CostOtherPaymentsServiceImpl.java 6.0 KB

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