CostShareParamServiceImpl.java 8.6 KB

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