CostOtherPaymentsServiceImpl.java 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. package com.imed.costaccount.service.impl;
  2. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  3. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  4. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  5. import com.imed.costaccount.common.exception.CostException;
  6. import com.imed.costaccount.common.util.BeanUtil;
  7. import com.imed.costaccount.common.util.PageUtils;
  8. import com.imed.costaccount.common.util.UserContext;
  9. import com.imed.costaccount.mapper.CostOtherPaymentsMapper;
  10. import com.imed.costaccount.model.CostOtherPayments;
  11. import com.imed.costaccount.model.dto.CostOtherPaymentsEditDto;
  12. import com.imed.costaccount.model.vo.CostOtherPaymentsSaveDto;
  13. import com.imed.costaccount.model.vo.CostOtherPaymentsVO;
  14. import com.imed.costaccount.service.CostOtherPaymentsService;
  15. import org.springframework.stereotype.Service;
  16. import org.springframework.transaction.annotation.Propagation;
  17. import org.springframework.transaction.annotation.Transactional;
  18. import java.util.List;
  19. import java.util.Objects;
  20. @Service("costOtherPaymentsService")
  21. public class CostOtherPaymentsServiceImpl extends ServiceImpl<CostOtherPaymentsMapper, CostOtherPayments> implements CostOtherPaymentsService {
  22. /**
  23. * 分压查询全院其他收支设置
  24. *
  25. * @param current
  26. * @param pageSize
  27. * @param name
  28. * @param hospId
  29. * @return
  30. */
  31. @Override
  32. public PageUtils queryList(Integer current, Integer pageSize, String name, Long hospId) {
  33. Page<CostOtherPayments> costOtherPaymentsPage = new Page<>(current, pageSize);
  34. Page<CostOtherPayments> pages = this.page(costOtherPaymentsPage, new QueryWrapper<CostOtherPayments>().lambda().eq(CostOtherPayments::getHospId, hospId));
  35. List<CostOtherPayments> records = pages.getRecords();
  36. List<CostOtherPaymentsVO> costOtherPaymentsVOList = BeanUtil.convertList(records, CostOtherPaymentsVO.class);
  37. PageUtils pageUtils = new PageUtils(pages);
  38. pageUtils.setList(costOtherPaymentsVOList);
  39. return pageUtils;
  40. }
  41. /**
  42. * 根据Id获取对应的数据
  43. *
  44. * @param id
  45. * @return
  46. */
  47. @Override
  48. public CostOtherPaymentsVO getByParamsId(Long id) {
  49. CostOtherPayments costOtherPayments = this.getById(id);
  50. if (Objects.isNull(costOtherPayments)){
  51. return null;
  52. }
  53. CostOtherPaymentsVO costOtherPaymentsVO = BeanUtil.convertObj(costOtherPayments, CostOtherPaymentsVO.class);
  54. return costOtherPaymentsVO;
  55. }
  56. /**
  57. * @param costOtherPaymentsSaveDto
  58. */
  59. @Override
  60. @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
  61. public void addOtherPayment(CostOtherPaymentsSaveDto costOtherPaymentsSaveDto) {
  62. Long hospId = UserContext.getHospId();
  63. CostOtherPayments otherPayments = this.getOne(new QueryWrapper<CostOtherPayments>().lambda().eq(CostOtherPayments::getHospId, hospId)
  64. .eq(CostOtherPayments::getPaymentsName,costOtherPaymentsSaveDto.getPaymentsName())
  65. .eq(CostOtherPayments::getPaymentsType,costOtherPaymentsSaveDto.getPaymentsType()));
  66. if (Objects.nonNull(otherPayments)){
  67. throw new CostException(500,"数据已存在");
  68. }
  69. CostOtherPayments costOtherPayments = BeanUtil.convertObj(costOtherPaymentsSaveDto, CostOtherPayments.class);
  70. costOtherPayments.setHospId(hospId);
  71. costOtherPayments.setCreateTime(System.currentTimeMillis());
  72. this.save(costOtherPayments);
  73. }
  74. /**
  75. * 修改全院其他收支设置
  76. *
  77. * @param costOtherPaymentsEditDto
  78. */
  79. @Override
  80. @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
  81. public void updateOtherPaymentById(CostOtherPaymentsEditDto costOtherPaymentsEditDto) {
  82. Long hospId = UserContext.getHospId();
  83. Long id = costOtherPaymentsEditDto.getId();
  84. CostOtherPayments otherPayments = this.getOne(new QueryWrapper<CostOtherPayments>().lambda().eq(CostOtherPayments::getHospId, hospId)
  85. .eq(CostOtherPayments::getId,id));
  86. if (Objects.isNull(otherPayments)){
  87. throw new CostException(500,"原始数据不存在");
  88. }
  89. this.removeById(id);
  90. CostOtherPayments otherPaymentResponse = this.getOne(new QueryWrapper<CostOtherPayments>().lambda().eq(CostOtherPayments::getHospId, hospId)
  91. .eq(CostOtherPayments::getPaymentsName,costOtherPaymentsEditDto.getPaymentsName())
  92. .eq(CostOtherPayments::getPaymentsType,costOtherPaymentsEditDto.getPaymentsType()));
  93. if (Objects.nonNull(otherPaymentResponse)){
  94. throw new CostException(500,"修改后的数据已存在");
  95. }
  96. CostOtherPayments costOtherPayments = BeanUtil.convertObj(costOtherPaymentsEditDto, CostOtherPayments.class);
  97. costOtherPayments.setCreateTime(System.currentTimeMillis());
  98. costOtherPayments.setId(null);
  99. costOtherPayments.setHospId(hospId);
  100. this.save(costOtherPayments);
  101. }
  102. /**
  103. * 查询全院收支设置数据
  104. *
  105. * @param hospId
  106. * @return
  107. */
  108. @Override
  109. public List<CostOtherPaymentsVO> getAll(Long hospId) {
  110. List<CostOtherPayments> costOtherPaymentsList = this.list(new QueryWrapper<CostOtherPayments>().lambda().eq(CostOtherPayments::getHospId, hospId));
  111. return BeanUtil.convertList(costOtherPaymentsList, CostOtherPaymentsVO.class);
  112. }
  113. }