소스 검색

删除节点bug

liuyc 1 년 전
부모
커밋
c989095236

+ 7 - 5
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/WbsTreeContractServiceImpl.java

@@ -277,12 +277,14 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
                         }
                     });
                 }
-                List<String> nodeNames = tableNames.stream().map(WbsTreeContract::getNodeName).collect(Collectors.toList());
-                if (nodeNames.size() > 0) {
-                    String names = StringUtils.join(nodeNames, " , ");
-                    throw new ServiceException(StringUtil.format("节点下的 {} 中存在填报数据,删除失败!", names));
+                if (tableNames.size() > 0) {
+                    List<String> nodeNames = tableNames.stream().map(WbsTreeContract::getNodeName).collect(Collectors.toList());
+                    if (nodeNames.size() > 0) {
+                        String names = StringUtils.join(nodeNames, " , ");
+                        throw new ServiceException(StringUtil.format("节点下的 {} 中存在填报数据,删除失败!", names));
+                    }
+                    baseMapper.deleteBatch(ids1, pawDTO.getWbsId(), pawDTO.getProjectId(), pawDTO.getContractId());
                 }
-                baseMapper.deleteBatch(ids1, pawDTO.getWbsId(), pawDTO.getProjectId(), pawDTO.getContractId());
             }
 
             //TODO ---------新增---------

+ 8 - 18
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/WbsTreeServiceImpl.java

@@ -860,15 +860,10 @@ public class WbsTreeServiceImpl extends BaseServiceImpl<WbsTreeMapper, WbsTree>
                         List<WbsTreeContract> wbsTreeContractList = wbsTreeContractMapper.selectContractList(pawDTO.getWbsId(), pawDTO.getProjectId(), ids1);
 
                         if (wbsTreeContractList.size() > 0) {
-                            List<ContractInfo> contractInfoArrayList = new ArrayList<>();
-                            wbsTreeContractList.forEach(list -> {
-                                ContractInfo contractInfos = contractInfoMapper.selectOne(Wrappers.<ContractInfo>query().lambda()
-                                        .select(ContractInfo::getContractName)
-                                        .eq(ContractInfo::getId, list.getContractId()));
-                                contractInfoArrayList.add(contractInfos);
-                            });
-                            List<String> names = contractInfoArrayList.stream().distinct().map(ContractInfo::getContractName).collect(Collectors.toList());
-                            if (wbsTreeContractList.size() > 0) {
+                            Set<String> contractIds = wbsTreeContractList.stream().map(WbsTreeContract::getContractId).collect(Collectors.toSet());
+                            List<ContractInfo> contractInfoArrayList = contractInfoMapper.selectList(Wrappers.<ContractInfo>query().lambda().select(ContractInfo::getContractName).in(ContractInfo::getId, contractIds));
+                            if (contractInfoArrayList.size() > 0) {
+                                List<String> names = contractInfoArrayList.stream().distinct().map(ContractInfo::getContractName).collect(Collectors.toList());
                                 String join = StringUtils.join(names, ",");
                                 return R.fail(400, StringUtil.format("当前项目wbs树的节点已被 {} 引用中,删除失败", join));
                             }
@@ -902,15 +897,10 @@ public class WbsTreeServiceImpl extends BaseServiceImpl<WbsTreeMapper, WbsTree>
                         List<WbsTreeContract> wbsTreeContractList = wbsTreeContractMapper.selectContractList(pawDTO.getPrimaryKeyId(), pawDTO.getProjectId(), ids2);
 
                         if (wbsTreeContractList.size() > 0) {
-                            List<ContractInfo> contractInfoArrayList = new ArrayList<>();
-                            wbsTreeContractList.forEach(list -> {
-                                ContractInfo contractInfos = contractInfoMapper.selectOne(Wrappers.<ContractInfo>query().lambda()
-                                        .select(ContractInfo::getContractName)
-                                        .eq(ContractInfo::getId, list.getContractId()));
-                                contractInfoArrayList.add(contractInfos);
-                            });
-                            List<String> names = contractInfoArrayList.stream().distinct().map(ContractInfo::getContractName).collect(Collectors.toList());
-                            if (wbsTreeContractList.size() > 0) {
+                            Set<String> contractIds = wbsTreeContractList.stream().map(WbsTreeContract::getContractId).collect(Collectors.toSet());
+                            List<ContractInfo> contractInfoArrayList = contractInfoMapper.selectList(Wrappers.<ContractInfo>query().lambda().select(ContractInfo::getContractName).in(ContractInfo::getId, contractIds));
+                            if (contractInfoArrayList.size() > 0) {
+                                List<String> names = contractInfoArrayList.stream().distinct().map(ContractInfo::getContractName).collect(Collectors.toList());
                                 String join = StringUtils.join(names, ",");
                                 return R.fail(400, StringUtil.format("当前项目wbs树的节点已被 {} 引用中,删除失败", join));
                             }