CostShareLevelServiceImpl.java 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. package com.imed.costaccount.service.impl;
  2. import cn.hutool.core.util.StrUtil;
  3. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  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.mapper.CostShareLevelMapper;
  11. import com.imed.costaccount.model.CostShareLevel;
  12. import com.imed.costaccount.model.User;
  13. import com.imed.costaccount.model.dto.CostShareLevelEditDto;
  14. import com.imed.costaccount.model.dto.CostShareLevelSaveDto;
  15. import com.imed.costaccount.model.vo.CostShareLevelVO;
  16. import com.imed.costaccount.service.CostShareLevelService;
  17. import org.apache.shiro.SecurityUtils;
  18. import org.springframework.stereotype.Service;
  19. import org.springframework.transaction.annotation.Propagation;
  20. import org.springframework.transaction.annotation.Transactional;
  21. import org.springframework.util.StringUtils;
  22. import java.util.ArrayList;
  23. import java.util.Arrays;
  24. import java.util.List;
  25. import java.util.Objects;
  26. import java.util.stream.Collectors;
  27. @Service("costShareLevelService")
  28. public class CostShareLevelServiceImpl extends ServiceImpl<CostShareLevelMapper, CostShareLevel> implements CostShareLevelService {
  29. /**
  30. * 分页查询相关分摊层级信息
  31. *
  32. * @param current
  33. * @param pageSize
  34. * @param name
  35. * @param hospId
  36. * @return
  37. */
  38. @Override
  39. public PageUtils queryList(Integer current, Integer pageSize, String name, Long hospId) {
  40. Page<CostShareLevel> costShareLevelPage = new Page<>(current, pageSize);
  41. Page<CostShareLevel> pages = this.page(costShareLevelPage, new QueryWrapper<CostShareLevel>().lambda()
  42. .eq(!StringUtils.isEmpty(hospId), CostShareLevel::getHospId, hospId)
  43. .like(!StringUtils.isEmpty(name), CostShareLevel::getShareName, name)
  44. .orderByAsc(CostShareLevel::getLeverSort));
  45. List<CostShareLevel> costShareLevelList = pages.getRecords();
  46. List<CostShareLevelVO> costShareLevelVOList = BeanUtil.convertList(costShareLevelList, CostShareLevelVO.class);
  47. int max=costShareLevelVOList.size();
  48. costShareLevelVOList.forEach(i->{
  49. i.setMaxLevel(max);
  50. });
  51. PageUtils pageUtils = new PageUtils(pages);
  52. pageUtils.setList(costShareLevelVOList);
  53. return pageUtils;
  54. }
  55. /**
  56. * 保存
  57. *
  58. * @param costShareLevelSaveDto
  59. */
  60. @Override
  61. @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
  62. public void addCostShareLevel(CostShareLevelSaveDto costShareLevelSaveDto) {
  63. User user = (User) SecurityUtils.getSubject().getPrincipal();
  64. Long hospId = user.getHospId();
  65. // 检验目标层级必须大于等于当前层级
  66. String targetLevel = costShareLevelSaveDto.getTargetLevel();
  67. Integer leverSort = costShareLevelSaveDto.getLeverSort();
  68. checkTargetLevel(targetLevel, leverSort);
  69. CostShareLevel costShareLevel = BeanUtil.convertObj(costShareLevelSaveDto, CostShareLevel.class);
  70. costShareLevel.setCreateTime(System.currentTimeMillis());
  71. costShareLevel.setHospId(hospId);
  72. baseMapper.insert(costShareLevel);
  73. }
  74. /**
  75. * 查询层级级别大于等于当前
  76. */
  77. /**
  78. * 修改分摊层级数据
  79. *
  80. * @param costShareLevelEditDto
  81. */
  82. @Override
  83. @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
  84. public void updateByCostShareLevel(CostShareLevelEditDto costShareLevelEditDto) {
  85. User user = (User) SecurityUtils.getSubject().getPrincipal();
  86. Long hospId = user.getHospId();
  87. Long id = costShareLevelEditDto.getId();
  88. CostShareLevel costShareLevel = baseMapper.selectById(id);
  89. if (Objects.isNull(costShareLevel)){
  90. throw new CostException("分摊层级数据不存在");
  91. }
  92. String targetLevel = costShareLevelEditDto.getTargetLevel();
  93. Integer leverSort = costShareLevelEditDto.getLeverSort();
  94. checkTargetLevel(targetLevel, leverSort);
  95. baseMapper.deleteById(id);
  96. CostShareLevel costShareLevelRequest = BeanUtil.convertObj(costShareLevelEditDto, CostShareLevel.class);
  97. costShareLevelRequest.setId(null);
  98. costShareLevelRequest.setCreateTime(System.currentTimeMillis());
  99. costShareLevelRequest.setHospId(hospId);
  100. baseMapper.insert(costShareLevelRequest);
  101. }
  102. /**
  103. * 目标层级不能小于当前层级
  104. * @param targetLevel 目标层级
  105. * @param leverSort 当前层级
  106. */
  107. private void checkTargetLevel(String targetLevel, Integer leverSort) {
  108. List<Integer> targetLevelList = Arrays.stream(targetLevel.split(StrUtil.COMMA)).map(Integer::valueOf).collect(Collectors.toList());
  109. targetLevelList.forEach(i -> {
  110. if (i < leverSort) {
  111. throw new CostException(500, "目标层级不能小于当前层级");
  112. }
  113. });
  114. }
  115. /**
  116. * 获取所有的分摊层级数据
  117. *
  118. * @param hospId
  119. * @return
  120. */
  121. @Override
  122. public List<CostShareLevelVO> getAll(Long hospId) {
  123. QueryWrapper<CostShareLevel> wrapper = new QueryWrapper<>();
  124. wrapper.eq(!StringUtils.isEmpty(hospId), "hosp_id", hospId).orderByAsc("lever_sort");
  125. List<CostShareLevel> costShareLevels = baseMapper.selectList(wrapper);
  126. List<CostShareLevelVO> costShareLevelVOList = BeanUtil.convertList(costShareLevels, CostShareLevelVO.class);
  127. return costShareLevelVOList;
  128. }
  129. /**
  130. * 通过分摊层级序号得到分摊层级列表
  131. *
  132. * @param targetLevelList 分摊层级序号列表
  133. * @param hospId 医院id
  134. * @return CostShareLevel List
  135. */
  136. @Override
  137. public List<CostShareLevel> getListByLevelSort(ArrayList<String> targetLevelList, Long hospId) {
  138. return this.list(
  139. new LambdaQueryWrapper<CostShareLevel>()
  140. .in(CostShareLevel::getLeverSort, targetLevelList)
  141. .eq(CostShareLevel::getHospId, hospId)
  142. );
  143. }
  144. @Override
  145. public List<Long> getMaxId(Long hospId) {
  146. List<Long> ids = baseMapper.getMaxIds(hospId);
  147. return ids;
  148. }
  149. /**
  150. * 删除分摊等级的数据
  151. *
  152. * @param idList 分摊层级的id
  153. */
  154. @Override
  155. @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
  156. public void deleteByIds(List<Integer> idList) {
  157. this.removeByIds(idList);
  158. }
  159. }