Browse Source

分摊复制

ljx 4 năm trước cách đây
mục cha
commit
8634871d86

+ 6 - 5
src/main/java/com/imed/costaccount/service/impl/CostAccountShareServiceImpl.java

@@ -172,7 +172,7 @@ public class CostAccountShareServiceImpl extends ServiceImpl<CostAccountShareMap
                         throw new CostException(500, "存在重复的数据");
                     }
                     if (NumberConstant.ONE.equals(isShareCost) && NumberConstant.ONE.equals(costAccountShareSaveDto.getIsShareCost())) {
-                        throw new CostException(500, "责任中心已包含分摊成本");
+                        throw new CostException(500, "同个责任中心只允许一条设置包含分摊成本");
                     }
                 });
             }
@@ -393,16 +393,17 @@ public class CostAccountShareServiceImpl extends ServiceImpl<CostAccountShareMap
         CostShareLevel costShareLevel = costShareLevelService.getById(shareId);
         Integer calcType = costShareLevel.getCalcType();
         // 分摊参数设置对饮的责任中心的id集合
-        List<Long> responsibilityIds = this.list(new QueryWrapper<CostAccountShare>().lambda().eq(CostAccountShare::getHospId, hospId)).stream().map(CostAccountShare::getResponsibilityId).collect(Collectors.toList());
+//        List<Long> responsibilityIds = this.list(new QueryWrapper<CostAccountShare>().lambda().eq(CostAccountShare::getHospId, hospId)).stream().map(CostAccountShare::getResponsibilityId).distinct().collect(Collectors.toList());
         // 执行类型的分摊级别的Id的集合
         List<Long> costShareIds = costShareLevelService.list(new QueryWrapper<CostShareLevel>().lambda()
                 .eq(CostShareLevel::getHospId, hospId).eq(CostShareLevel::getCalcType, calcType))
-                .stream().map(CostShareLevel::getId).collect(Collectors.toList());
+                .stream().map(CostShareLevel::getId).distinct().collect(Collectors.toList());
         // 筛选责任中心里面符合指定类型的责任中心
         // 筛选指定类型的责任中心 并且当前没有设置的责任中心
         List<Responsibility> responsibilityList = responsibilityService.list(new QueryWrapper<Responsibility>().lambda()
-                .eq(Responsibility::getHospId, hospId)).stream()
-                .filter(i -> costShareIds.contains(i.getShareId()) && !responsibilityIds.contains(i.getId())).collect(Collectors.toList());
+                .eq(Responsibility::getHospId, hospId).ne(Responsibility::getShareId,NumberConstant.ZERO));
+        responsibilityList=responsibilityList.stream()
+                .filter(i -> costShareIds.contains(i.getShareId()) && !responsibilityId.equals(i.getId())).collect(Collectors.toList());
         return responsibilityList;
     }
 

+ 28 - 2
src/main/java/com/imed/costaccount/service/impl/CostShareLevelServiceImpl.java

@@ -1,9 +1,11 @@
 package com.imed.costaccount.service.impl;
 
+import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.imed.costaccount.common.exception.CostException;
+import com.imed.costaccount.common.util.BeanUtil;
 import com.imed.costaccount.common.util.PageUtils;
 import com.imed.costaccount.mapper.CostShareLevelMapper;
 import com.imed.costaccount.model.CostShareLevel;
@@ -12,15 +14,16 @@ import com.imed.costaccount.model.dto.CostShareLevelEditDto;
 import com.imed.costaccount.model.dto.CostShareLevelSaveDto;
 import com.imed.costaccount.model.vo.CostShareLevelVO;
 import com.imed.costaccount.service.CostShareLevelService;
-import com.imed.costaccount.common.util.BeanUtil;
 import org.apache.shiro.SecurityUtils;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Propagation;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.StringUtils;
 
+import java.util.Arrays;
 import java.util.List;
 import java.util.Objects;
+import java.util.stream.Collectors;
 
 
 @Service("costShareLevelService")
@@ -64,12 +67,18 @@ public class CostShareLevelServiceImpl extends ServiceImpl<CostShareLevelMapper,
     public void addCostShareLevel(CostShareLevelSaveDto costShareLevelSaveDto) {
         User user = (User) SecurityUtils.getSubject().getPrincipal();
         Long hospId = user.getHospId();
+        // 检验目标层级必须大于等于当前层级
+        String targetLevel = costShareLevelSaveDto.getTargetLevel();
+        Integer leverSort = costShareLevelSaveDto.getLeverSort();
+        checkTargetLevel(targetLevel, leverSort);
         CostShareLevel costShareLevel = BeanUtil.convertObj(costShareLevelSaveDto, CostShareLevel.class);
         costShareLevel.setCreateTime(System.currentTimeMillis());
         costShareLevel.setHospId(hospId);
         baseMapper.insert(costShareLevel);
     }
-
+    /**
+     * 查询层级级别大于等于当前
+     */
     /**
      * 修改分摊层级数据
      *
@@ -85,6 +94,9 @@ public class CostShareLevelServiceImpl extends ServiceImpl<CostShareLevelMapper,
         if (Objects.isNull(costShareLevel)){
             throw new CostException("分摊层级数据不存在");
         }
+        String targetLevel = costShareLevelEditDto.getTargetLevel();
+        Integer leverSort = costShareLevelEditDto.getLeverSort();
+        checkTargetLevel(targetLevel, leverSort);
         baseMapper.deleteById(id);
         CostShareLevel costShareLevelRequest = BeanUtil.convertObj(costShareLevelEditDto, CostShareLevel.class);
         costShareLevelRequest.setId(null);
@@ -93,6 +105,20 @@ public class CostShareLevelServiceImpl extends ServiceImpl<CostShareLevelMapper,
         baseMapper.insert(costShareLevelRequest);
     }
 
+    /**
+     *  目标层级不能小于当前层级
+     * @param targetLevel 目标层级
+     * @param leverSort 当前层级
+     */
+    private void checkTargetLevel(String targetLevel, Integer leverSort) {
+        List<Integer> targetLevelList = Arrays.stream(targetLevel.split(StrUtil.COMMA)).map(Integer::valueOf).collect(Collectors.toList());
+        targetLevelList.forEach(i -> {
+            if (i < leverSort) {
+                throw new CostException(500, "目标层级不能小于当前层级");
+            }
+        });
+    }
+
     /**
      * 获取所有的分摊层级数据
      *