CostOtherPaymentsDataServiceImpl.java 7.8 KB

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