hr 4 роки тому
батько
коміт
cf0b71bf0a

+ 14 - 14
src/main/java/com/imed/costaccount/service/impl/AccountingProductServiceImpl.java

@@ -80,20 +80,6 @@ public class AccountingProductServiceImpl extends ServiceImpl<AccountingProductM
         for (AccountProductVO account : list) {
             // 如果是父子关系
             if (accountVO.getId().equals(account.getParentId())) {
-                List<AccountingProduct> accountingProducts = baseMapper.selectList(
-                        new LambdaQueryWrapper<AccountingProduct>().select(AccountingProduct::getId, AccountingProduct::getProductId)
-                                .eq(AccountingProduct::getAccountingId, account.getId())
-                );
-                if (CollUtil.isNotEmpty(accountingProducts)) {
-                    List<Integer> productIds = accountingProducts.stream().map(AccountingProduct::getProductId).collect(Collectors.toList());
-                    List<Product> products = productMapper.selectList(
-                            new LambdaQueryWrapper<Product>().in(Product::getId, productIds)
-                    );
-                    if (CollUtil.isNotEmpty(products)) {
-                        List<ProductVO> productVOS = BeanUtil.convertList(products, ProductVO.class);
-                         account.setProductVOs(productVOS);
-                    }
-                }
 
                 List<AccountProductVO> child = accountVO.getChild();
                 if (CollUtil.isEmpty(child)) {
@@ -105,6 +91,20 @@ public class AccountingProductServiceImpl extends ServiceImpl<AccountingProductM
                 this.getAccountTree(account, list);
                 accountVO.setIsParent(true);
             }
+            List<AccountingProduct> accountingProducts = baseMapper.selectList(
+                    new LambdaQueryWrapper<AccountingProduct>().select(AccountingProduct::getId, AccountingProduct::getProductId)
+                            .eq(AccountingProduct::getAccountingId, account.getId())
+            );
+            if (CollUtil.isNotEmpty(accountingProducts)) {
+                List<Integer> productIds = accountingProducts.stream().map(AccountingProduct::getProductId).collect(Collectors.toList());
+                List<Product> products = productMapper.selectList(
+                        new LambdaQueryWrapper<Product>().in(Product::getId, productIds)
+                );
+                if (CollUtil.isNotEmpty(products)) {
+                    List<ProductVO> productVOS = BeanUtil.convertList(products, ProductVO.class);
+                    account.setProductVOs(productVOS);
+                }
+            }
         }
         return accountVOS;
     }

+ 30 - 15
src/main/java/com/imed/costaccount/service/impl/ResponsibilityServiceImpl.java

@@ -66,8 +66,8 @@ public class ResponsibilityServiceImpl extends ServiceImpl<ResponsibilityMapper,
                 i.setChild(child);
             }
         }));
-        parentCostResponsibility.forEach(i->{
-            if (NumberConstant.ZERO.equals(i.getParentId())){
+        parentCostResponsibility.forEach(i -> {
+            if (NumberConstant.ZERO.equals(i.getParentId())) {
                 i.setShareLevel(null);
             }
         });
@@ -98,15 +98,21 @@ public class ResponsibilityServiceImpl extends ServiceImpl<ResponsibilityMapper,
         }
 
         // 如果是汇总中心,那么不存在分摊级别
-        if (responsibilitySaveDTO.getIsGatherCenter() == 1) {
+        Integer isGatherCenter = responsibilitySaveDTO.getIsGatherCenter();
+        if (isGatherCenter == 1) {
             center.setShareLevel(0);
             center.setShareName("");
         }
+        // 父节点不允许为非汇总中心
+        Responsibility byId = this.getById(id);
+        if (Objects.nonNull(byId) && (byId.getIsGatherCenter() == 2)) {
+            throw new CostException(500, "非汇总中心不允许添加");
+        }
 
         this.save(center);
     }
 
-    private void checkCode(String code,Integer hospId) {
+    private void checkCode(String code, Integer hospId) {
         // 校验责任代码唯一性
         Responsibility one = this.getOne(
                 new LambdaQueryWrapper<Responsibility>().select(Responsibility::getId)
@@ -139,29 +145,38 @@ public class ResponsibilityServiceImpl extends ServiceImpl<ResponsibilityMapper,
             return;
         }
 
-        this.updateCurrent(responsibilityEditDTO, center,user.getHospId());
+        this.updateCurrent(responsibilityEditDTO, center, user.getHospId());
     }
 
     /**
      * 修的是父节点
-     *  @param dto
+     *
+     * @param dto
      * @param responsibility
      * @param hospId
      */
     @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
     public void updateParent(ResponsibilityEditDTO dto, Responsibility responsibility, Integer hospId) {
+
         // 删除原有的父节点数据
         Integer id = dto.getId();
         this.removeById(id);
-        this.checkCode(dto.getResponsibilityCode(),hospId);
+        List<Responsibility> child = this.list(new QueryWrapper<Responsibility>().lambda().eq(Responsibility::getParentId, id));
+        // 如果修改是否汇总中心 从是 -》 否那么子节点直接删除
+        if (responsibility.getIsGatherCenter() == 1 && dto.getIsGatherCenter() == 2) {
+            this.removeByIds(child.stream().map(Responsibility::getId).collect(Collectors.toList()));
+            return;
+        }
+
+        this.checkCode(dto.getResponsibilityCode(), hospId);
         // 新增父节点数据
         Responsibility newResponsibility = BeanUtil.convertObj(dto, Responsibility.class);
         newResponsibility.setId(null).setHospId(responsibility.getHospId()).setCreateTime(new Date().getTime()).setResponsibilityLevel(1);
         this.save(newResponsibility);
+
         // 将原来所有父节点下数据关联到新的父节点下
-        List<Responsibility> list = this.list(new QueryWrapper<Responsibility>().lambda().eq(Responsibility::getParentId, id));
-        list.forEach(i -> i.setParentId(newResponsibility.getId()));
-        this.updateBatchById(list);
+        child.forEach(i -> i.setParentId(newResponsibility.getId()));
+        this.updateBatchById(child);
 
     }
 
@@ -178,7 +193,7 @@ public class ResponsibilityServiceImpl extends ServiceImpl<ResponsibilityMapper,
         Integer id = dto.getId();
         this.removeById(id);
 
-        this.checkCode(dto.getResponsibilityCode(),hospId);
+        this.checkCode(dto.getResponsibilityCode(), hospId);
         // 新增父节点数据
         Responsibility newResponsibility = BeanUtil.convertObj(dto, Responsibility.class);
         newResponsibility.setId(null).setHospId(responsibility.getHospId()).setCreateTime(new Date().getTime()).setResponsibilityLevel(1);
@@ -270,7 +285,7 @@ public class ResponsibilityServiceImpl extends ServiceImpl<ResponsibilityMapper,
     public List<CommonVO> getParentList(User user) {
         List<Responsibility> list = this.list(
                 new LambdaQueryWrapper<Responsibility>().select(Responsibility::getId, Responsibility::getResponsibilityName)
-                        .eq(Responsibility::getResponsibilityLevel,1)
+                        .eq(Responsibility::getResponsibilityLevel, 1)
                         .eq(Responsibility::getHospId, user.getHospId())
         );
         return list.stream().map(i -> {
@@ -291,16 +306,16 @@ public class ResponsibilityServiceImpl extends ServiceImpl<ResponsibilityMapper,
     public List<CostResponsibilityLevelVO> getLevelTwo(Integer hospId) {
         List<Responsibility> responsibilities = baseMapper.selectList(new QueryWrapper<Responsibility>().lambda()
                 .eq(Responsibility::getHospId, hospId)
-                .eq(Responsibility::getIsGatherCenter,NumberConstant.TWO));
+                .eq(Responsibility::getIsGatherCenter, NumberConstant.TWO));
         List<CostResponsibilityLevelVO> costResponsibilityLevelVOS = BeanUtil.convertList(responsibilities, CostResponsibilityLevelVO.class);
         List<CostShareLevelVO> costShareLevelServiceAll = costShareLevelService.getAll(hospId);
         Map<Integer, List<CostShareLevelVO>> listMap = costShareLevelServiceAll.stream().collect(Collectors.groupingBy(CostShareLevelVO::getId));
         // 设置责任中心的计算方式
-        costResponsibilityLevelVOS.forEach(i->{
+        costResponsibilityLevelVOS.forEach(i -> {
             i.setResponsibilityId(i.getId());
             Integer shareLevel = i.getShareLevel();
             List<CostShareLevelVO> costShareLevelVOList = listMap.get(shareLevel);
-            if (!CollectionUtils.isEmpty(costShareLevelVOList)){
+            if (!CollectionUtils.isEmpty(costShareLevelVOList)) {
                 i.setCalcType(costShareLevelVOList.get(0).getCalcType());
             }
         });