CostShareParamServiceImpl.java 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. package com.imed.costaccount.service.impl;
  2. import cn.hutool.core.collection.CollectionUtil;
  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.PageUtils;
  10. import com.imed.costaccount.constants.NumberConstant;
  11. import com.imed.costaccount.mapper.CostShareParamMapper;
  12. import com.imed.costaccount.model.CostShareParam;
  13. import com.imed.costaccount.model.dto.CostShareParamAccountDto;
  14. import com.imed.costaccount.model.dto.CostShareParamEditDto;
  15. import com.imed.costaccount.model.dto.CostShareParamSaveDto;
  16. import com.imed.costaccount.model.vo.CostShareParamVO;
  17. import com.imed.costaccount.service.CostShareParamService;
  18. import io.swagger.annotations.ApiOperation;
  19. import org.springframework.stereotype.Service;
  20. import org.springframework.transaction.annotation.Propagation;
  21. import org.springframework.transaction.annotation.Transactional;
  22. import org.springframework.util.CollectionUtils;
  23. import org.springframework.util.StringUtils;
  24. import java.util.*;
  25. import java.util.stream.Collectors;
  26. @Service("costShareParamService")
  27. public class CostShareParamServiceImpl extends ServiceImpl<CostShareParamMapper, CostShareParam> implements CostShareParamService {
  28. /**
  29. * 分页查询相关的分摊参数数据
  30. *
  31. * @param current
  32. * @param pageSize
  33. * @param name
  34. * @return
  35. */
  36. @Override
  37. public PageUtils queryList(Integer current, Integer pageSize, String name,Long hospId) {
  38. Page<CostShareParam> costShareParamPage = new Page<>(current, pageSize);
  39. Page<CostShareParam> pages = this.page(costShareParamPage, new QueryWrapper<CostShareParam>().lambda()
  40. .eq(!StringUtils.isEmpty(hospId), CostShareParam::getHospId, hospId)
  41. .like(!StringUtils.isEmpty(name), CostShareParam::getShareParamName, name).orderByDesc(CostShareParam::getCreateTime))
  42. ;
  43. List<CostShareParam> records = pages.getRecords();
  44. List<CostShareParamVO> costShareParamVOList = BeanUtil.convertList(records, CostShareParamVO.class);
  45. PageUtils pageUtils = new PageUtils(pages);
  46. pageUtils.setList(costShareParamVOList);
  47. return pageUtils;
  48. }
  49. /**
  50. * 保存分摊参数
  51. * 保存的时候需要校验分摊参数
  52. * @param costShareParamSaveDto
  53. */
  54. @Override
  55. @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
  56. public void addCostShareParam(CostShareParamSaveDto costShareParamSaveDto) {
  57. //检验分摊参数是存在
  58. getCostShareParamByCode(costShareParamSaveDto);
  59. CostShareParam costShareParam = BeanUtil.convertObj(costShareParamSaveDto, CostShareParam.class);
  60. costShareParam.setCreateTime(System.currentTimeMillis());
  61. baseMapper.insert(costShareParam);
  62. }
  63. /**
  64. * 检验分摊参数是存在
  65. */
  66. private void getCostShareParamByCode(CostShareParamSaveDto costShareParamSaveDto) {
  67. List<CostShareParam> costShareParamList = baseMapper.selectList(new QueryWrapper<CostShareParam>().lambda()
  68. .eq(CostShareParam::getHospId, costShareParamSaveDto.getHospId()));
  69. // 检验添加的分摊参数是否存在
  70. if (!CollectionUtils.isEmpty(costShareParamList)){
  71. Map<String, List<CostShareParam>> costShareMap = costShareParamList.stream().collect(Collectors.groupingBy(CostShareParam::getShareParamCode));
  72. if (!CollectionUtils.isEmpty(costShareMap.get(costShareParamSaveDto.getShareParamCode()))){
  73. throw new CostException(500,"分摊参数已存在");
  74. }
  75. }
  76. }
  77. /**
  78. * 修改分摊参数
  79. *
  80. * @param costShareParamEditDto
  81. */
  82. @Override
  83. @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
  84. public void updateCostShareParam(CostShareParamEditDto costShareParamEditDto) {
  85. Long id = costShareParamEditDto.getId();
  86. CostShareParam costShareParam = baseMapper.selectById(id);
  87. if (Objects.isNull(costShareParam)){
  88. throw new CostException(500,"对不起分摊参数不存在");
  89. }
  90. baseMapper.deleteById(id);
  91. // 判断当前输入的Code以最初的Code是否一样
  92. List<CostShareParam> costShareParamList = baseMapper.selectList(new QueryWrapper<CostShareParam>().lambda().select(CostShareParam::getShareParamCode).eq(CostShareParam::getHospId, costShareParamEditDto.getHospId()));
  93. Map<String, List<CostShareParam>> map = costShareParamList.stream().collect(Collectors.groupingBy(CostShareParam::getShareParamCode));
  94. if (!CollectionUtils.isEmpty(map.get(costShareParamEditDto.getShareParamCode()))){
  95. throw new CostException(500,"对不起分摊参数代码已存在");
  96. }
  97. CostShareParam costShareParamRequest = BeanUtil.convertObj(costShareParamEditDto, CostShareParam.class);
  98. costShareParamRequest.setId(null);
  99. costShareParamRequest.setCreateTime(System.currentTimeMillis());
  100. if (NumberConstant.ONE.equals( costShareParamEditDto.getShareParamCode()) && NumberConstant.ONE.equals(costShareParamEditDto.getShareParamCode())){
  101. costShareParamRequest.setAccountingId(costShareParam.getAccountingId());
  102. }
  103. baseMapper.insert(costShareParamRequest);
  104. }
  105. /**
  106. * 为按照科目的计算方式添加成本科目
  107. *
  108. * @param costShareParamAccountDto
  109. * @return
  110. */
  111. @Override
  112. @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
  113. public CostShareParam updateCostShareParamByAccountId(CostShareParamAccountDto costShareParamAccountDto) {
  114. Long costShareParamId = costShareParamAccountDto.getCostShareParamId();
  115. CostShareParam costShareParam = baseMapper.selectById(costShareParamId);
  116. // 判断当前操作的分层参数的计算方式是不是按科目计算
  117. if (NumberConstant.TWO.equals(costShareParam.getCalcType())){
  118. String[] accountIds = costShareParamAccountDto.getAccountIds();
  119. List<String> accountList = Arrays.asList(accountIds);
  120. if (!CollectionUtil.isEmpty(accountList)){
  121. String accounds = accountList.stream().map(String::valueOf).collect(Collectors.joining(","));
  122. costShareParam.setAccountingId(accounds);
  123. }else {
  124. costShareParam.setAccountingId(null);
  125. }
  126. baseMapper.updateById(costShareParam);
  127. }else {
  128. throw new CostException(500,"计算方式不是按会计科目计算");
  129. }
  130. return null;
  131. }
  132. /**
  133. * 获取所有分摊参数的集合信息
  134. *
  135. * @param hospId
  136. * @return
  137. */
  138. @Override
  139. @ApiOperation("获取所有的分摊参数的集合数据")
  140. public List<CostShareParamVO> getAll(Long hospId) {
  141. List<CostShareParam> costShareParamList = baseMapper.selectList(new QueryWrapper<CostShareParam>().lambda()
  142. .eq(CostShareParam::getHospId, hospId));
  143. List<CostShareParamVO> costShareParamVOList = BeanUtil.convertList(costShareParamList, CostShareParamVO.class);
  144. return costShareParamVOList;
  145. }
  146. /**
  147. * 根据医院的Id分摊参数的ID获取对应的分摊参数的数据
  148. *
  149. * @param id
  150. * @param hospId
  151. * @return
  152. */
  153. @Override
  154. public CostShareParamVO getByHospIdAndAPramId(Integer id, Long hospId) {
  155. CostShareParam costShareParam = baseMapper.selectOne(new QueryWrapper<CostShareParam>().lambda()
  156. .eq(CostShareParam::getHospId, hospId)
  157. .eq(CostShareParam::getId, id));
  158. CostShareParamVO costShareParamVO = BeanUtil.convertObj(costShareParam, CostShareParamVO.class);
  159. return costShareParamVO;
  160. }
  161. @Override
  162. public List<Integer> selectIsSelect(Integer shareParamId) {
  163. CostShareParam byId = this.getById(shareParamId);
  164. if (Objects.isNull(byId)) {
  165. return Collections.emptyList();
  166. }
  167. String accountingId = byId.getAccountingId();
  168. if (!StringUtils.isEmpty(accountingId)){
  169. String[] split = accountingId.split(StrUtil.COMMA);
  170. List<Integer> collect = Arrays.stream(split).map(Integer::valueOf).collect(Collectors.toList());
  171. return collect;
  172. }else {
  173. return Collections.emptyList();
  174. }
  175. }
  176. }