2
0

CostOtherPaymentsDataServiceImpl.java 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. package com.imed.costaccount.service.impl;
  2. import cn.hutool.core.date.DateUtil;
  3. import cn.hutool.core.util.StrUtil;
  4. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  5. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  6. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  7. import com.imed.costaccount.common.exception.CostException;
  8. import com.imed.costaccount.common.util.BeanUtil;
  9. import com.imed.costaccount.common.util.DateUtils;
  10. import com.imed.costaccount.common.util.PageUtils;
  11. import com.imed.costaccount.enums.DateStyleEnum;
  12. import com.imed.costaccount.mapper.CostOtherPaymentsDataMapper;
  13. import com.imed.costaccount.model.CostOtherPaymentsData;
  14. import com.imed.costaccount.model.dto.CostOtherPaymentsDataEditDto;
  15. import com.imed.costaccount.model.dto.CostOtherPaymentsDataSaveDto;
  16. import com.imed.costaccount.model.vo.CostOtherPaymentsDataVO;
  17. import com.imed.costaccount.service.CostOtherPaymentsDataService;
  18. import org.springframework.stereotype.Service;
  19. import org.springframework.transaction.annotation.Propagation;
  20. import org.springframework.transaction.annotation.Transactional;
  21. import java.util.Date;
  22. import java.util.List;
  23. import java.util.Objects;
  24. @Service("costOtherPaymentsDataService")
  25. public class CostOtherPaymentsDataServiceImpl extends ServiceImpl<CostOtherPaymentsDataMapper, CostOtherPaymentsData> implements CostOtherPaymentsDataService {
  26. /**
  27. * 分页查询
  28. *
  29. * @param current 第几页
  30. * @param pageSize 每页大小
  31. * @param dateTime 时间
  32. * @param hospId 医院Id
  33. * @return
  34. */
  35. @Override
  36. public PageUtils queryList(Integer current, Integer pageSize, String dateTime, Long hospId) {
  37. // 先检验当前年月是否存在数据
  38. int year = 0;
  39. int month = 0;
  40. Date date = DateUtils.StringToDate(dateTime, DateStyleEnum.YYYY_MM);
  41. if (StrUtil.isNotBlank(dateTime)) {
  42. year = DateUtil.year(date);
  43. month = DateUtil.month(date) + 1;
  44. }
  45. Page<CostOtherPaymentsData> paymentsDataPage = new Page<>(current, pageSize);
  46. Page<CostOtherPaymentsData> pages = this.page(paymentsDataPage, new QueryWrapper<CostOtherPaymentsData>().lambda()
  47. .eq(CostOtherPaymentsData::getHospId, hospId)
  48. .eq(StrUtil.isNotBlank(dateTime),CostOtherPaymentsData::getDateYear,year)
  49. .eq(StrUtil.isNotBlank(dateTime),CostOtherPaymentsData::getDateMonth,month)
  50. .orderByDesc(CostOtherPaymentsData::getCreateTime));
  51. List<CostOtherPaymentsData> records = pages.getRecords();
  52. List<CostOtherPaymentsDataVO> costOtherPaymentsDataVOList = BeanUtil.convertList(records, CostOtherPaymentsDataVO.class);
  53. PageUtils pageUtils = new PageUtils(pages);
  54. pageUtils.setList(costOtherPaymentsDataVOList);
  55. return pageUtils;
  56. }
  57. /**
  58. * 保存全院其他收支数据
  59. *
  60. * @param costOtherPaymentsDataSaveDto 全院其他收支
  61. * @param hospId 医院的Id
  62. */
  63. @Override
  64. @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
  65. public void addOtherPaymentData(CostOtherPaymentsDataSaveDto costOtherPaymentsDataSaveDto, Long hospId) {
  66. String dateTime = costOtherPaymentsDataSaveDto.getDateTime();
  67. // 先检验当前年月是否存在数据
  68. checkOtherPaymentData(costOtherPaymentsDataSaveDto, hospId, dateTime);
  69. CostOtherPaymentsData costOtherPaymentsData = BeanUtil.convertObj(costOtherPaymentsDataSaveDto, CostOtherPaymentsData.class);
  70. int year = 0;
  71. int month = 0;
  72. Date date = DateUtils.StringToDate(dateTime, DateStyleEnum.YYYY_MM);
  73. if (StrUtil.isNotBlank(dateTime)) {
  74. year = DateUtil.year(date);
  75. month = DateUtil.month(date) + 1;
  76. }
  77. costOtherPaymentsData.setHospId(hospId);
  78. costOtherPaymentsData.setCreateTime(System.currentTimeMillis());
  79. costOtherPaymentsData.setDateYear(year);
  80. costOtherPaymentsData.setDateMonth(month);
  81. this.save(costOtherPaymentsData);
  82. }
  83. // 先检验当前年月是否存在数据
  84. private void checkOtherPaymentData(CostOtherPaymentsDataSaveDto costOtherPaymentsDataSaveDto, Long hospId, String dateTime) {
  85. int year = 0;
  86. int month = 0;
  87. Date date = DateUtils.StringToDate(dateTime, DateStyleEnum.YYYY_MM);
  88. if (StrUtil.isNotBlank(dateTime)) {
  89. year = DateUtil.year(date);
  90. month = DateUtil.month(date) + 1;
  91. }
  92. Integer paymentsType = costOtherPaymentsDataSaveDto.getPaymentsType();
  93. String paymentsName = costOtherPaymentsDataSaveDto.getPaymentsName();
  94. CostOtherPaymentsData paymentsData = this.getOne(new QueryWrapper<CostOtherPaymentsData>().lambda()
  95. .eq(CostOtherPaymentsData::getHospId, hospId)
  96. .eq(CostOtherPaymentsData::getDateYear, year).eq(CostOtherPaymentsData::getDateMonth, month)
  97. .eq(CostOtherPaymentsData::getPaymentsType, paymentsType).eq(CostOtherPaymentsData::getPaymentsName, paymentsName));
  98. if (Objects.nonNull(paymentsData)){
  99. throw new CostException(500,"当前年月添加的数据已存在");
  100. }
  101. }
  102. /**
  103. * 修改全院其他收支数据
  104. *
  105. * @param costOtherPaymentsDataEditDto
  106. * @param hospId
  107. */
  108. @Override
  109. @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
  110. public void updateOtherPaymentData(CostOtherPaymentsDataEditDto costOtherPaymentsDataEditDto, Long hospId) {
  111. String dateTime = costOtherPaymentsDataEditDto.getDateTime();
  112. int year = 0;
  113. int month = 0;
  114. if (StrUtil.isNotBlank(dateTime)) {
  115. Date date = DateUtils.StringToDate(dateTime, DateStyleEnum.YYYY_MM);
  116. year = DateUtil.year(date);
  117. month = DateUtil.month(date) + 1;
  118. }
  119. Long id = costOtherPaymentsDataEditDto.getId();
  120. CostOtherPaymentsData otherPaymentsData = this.getById(id);
  121. if (Objects.isNull(otherPaymentsData)){
  122. throw new CostException(500,"全院其他收支数据不存在");
  123. }
  124. this.removeById(id);
  125. CostOtherPaymentsDataSaveDto costOtherPaymentsDataSaveDto = BeanUtil.convertObj(costOtherPaymentsDataEditDto, CostOtherPaymentsDataSaveDto.class);
  126. // 检验数据
  127. checkOtherPaymentData(costOtherPaymentsDataSaveDto,hospId,dateTime);
  128. // 实现数据添加
  129. CostOtherPaymentsData costOtherPaymentsData = BeanUtil.convertObj(costOtherPaymentsDataSaveDto, CostOtherPaymentsData.class);
  130. costOtherPaymentsData.setCreateTime(System.currentTimeMillis());
  131. costOtherPaymentsData.setHospId(hospId);
  132. costOtherPaymentsData.setDateYear(year);
  133. costOtherPaymentsData.setDateMonth(month);
  134. this.save(costOtherPaymentsData);
  135. }
  136. }