Bladeren bron

app隐蔽工程树

liuyc 2 jaren geleden
bovenliggende
commit
034ae6f660

+ 2 - 2
blade-service/blade-manager/src/main/java/org/springblade/manager/controller/WbsTreeContractController.java

@@ -394,8 +394,8 @@ public class WbsTreeContractController extends BladeController {
     @PostMapping("/getConcealedWorksNodeTree")
     @ApiOperationSupport(order = 15)
     @ApiOperation(value = "获取合同段隐蔽工程节点树", notes = "传入合同段id")
-    public R<List<WbsTreeContractLazyVO>> getConcealedWorksNodeTree(@RequestParam String contractId) {
-        List<WbsTreeContractLazyVO> result = iWbsTreeContractService.getConcealedWorksNodeTree(contractId);
+    public R<List<WbsTreeContractVO>> getConcealedWorksNodeTree(@RequestParam String contractId) {
+        List<WbsTreeContractVO> result = iWbsTreeContractService.getConcealedWorksNodeTree(contractId);
         return R.data(result);
     }
 

+ 1 - 1
blade-service/blade-manager/src/main/java/org/springblade/manager/service/IWbsTreeContractService.java

@@ -67,6 +67,6 @@ public interface IWbsTreeContractService extends BaseService<WbsTreeContract> {
 
     List<AppWbsTreeContractVO> searchNodeAllTableAndFile(String primaryKeyId, String type, String contractId, String projectId);
 
-    List<WbsTreeContractLazyVO> getConcealedWorksNodeTree(String contractId);
+    List<WbsTreeContractVO> getConcealedWorksNodeTree(String contractId);
 
 }

+ 53 - 8
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/WbsTreeContractServiceImpl.java

@@ -415,7 +415,7 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
     public List<AppWbsTreeContractVO> searchNodeAllTable(String primaryKeyId, String tableOwner, String contractId, String projectId) {
         //由于Feign调用时,获取不到UserId
         Long userId;
-        if (primaryKeyId.contains(":")) {
+        if (StringUtils.isNotEmpty(primaryKeyId) && primaryKeyId.contains(":")) {
             String[] ds = primaryKeyId.split(":");
             primaryKeyId = ds[0];
             userId = Long.parseLong(ds[1]);
@@ -951,20 +951,65 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
     }
 
     @Override
-    public List<WbsTreeContractLazyVO> getConcealedWorksNodeTree(String contractId) {
+    public List<WbsTreeContractVO> getConcealedWorksNodeTree(String contractId) {
         List<WbsTreeContract> wbsTreeContracts = this.getBaseMapper().selectList(Wrappers.<WbsTreeContract>lambdaQuery()
-                .select(WbsTreeContract::getId,WbsTreeContract::getPKeyId,WbsTreeContract::getParentId,WbsTreeContract::getNodeType,
-                        WbsTreeContract::getType,WbsTreeContract::getWbsType,WbsTreeContract::getMajorDataType,WbsTreeContract::getPartitionCode,
-                        WbsTreeContract::getOldId,WbsTreeContract::getContractIdRelation,WbsTreeContract::getIsConcealedWorksNode,WbsTreeContract::getIsConcrete
+                .select(WbsTreeContract::getId, WbsTreeContract::getPKeyId, WbsTreeContract::getParentId, WbsTreeContract::getNodeType,
+                        WbsTreeContract::getType, WbsTreeContract::getWbsType, WbsTreeContract::getMajorDataType, WbsTreeContract::getPartitionCode,
+                        WbsTreeContract::getOldId, WbsTreeContract::getContractIdRelation, WbsTreeContract::getIsConcealedWorksNode, WbsTreeContract::getIsConcrete
                 )
                 .eq(WbsTreeContract::getContractId, contractId).eq(WbsTreeContract::getIsConcealedWorksNode, 1));
-        List<WbsTreeContract> distinctWbsTreeContracts = wbsTreeContracts.stream()
+        List<WbsTreeContract> initNode = wbsTreeContracts.stream()
                 .distinct()
                 .collect(Collectors.toList());
+        //获取所有隐蔽节点的父级、子级
+        Set<WbsTreeContract> resultAllNodes = new HashSet<>();
+        this.getConcealedWorkParentNode(resultAllNodes, initNode, contractId);
+        this.getConcealedWorkChildNode(resultAllNodes, initNode, contractId);
+        resultAllNodes.addAll(initNode);
+
+        List<WbsTreeContractVO> result = new ArrayList<>();
+        for (WbsTreeContract resultAllNode : resultAllNodes) {
+            WbsTreeContractVO vo = new WbsTreeContractVO();
+            BeanUtil.copyProperties(resultAllNode, vo);
+            result.add(vo);
+        }
+        return this.buildWbsTreeByStream(result, 0L);
+    }
 
-        //TODO
+    /**
+     * 递归获取隐蔽工程节点的所有父级节点
+     *
+     * @param resultAllNodes 结果集
+     * @param initNode       初始化节点入参
+     * @param contractId     合同段id
+     */
+    private void getConcealedWorkParentNode(Set<WbsTreeContract> resultAllNodes, List<WbsTreeContract> initNode, String contractId) {
+        Set<Long> parentIds = initNode.stream().map(WbsTreeContract::getParentId).collect(Collectors.toSet());
+        if (parentIds.size() > 0) {
+            List<WbsTreeContract> parentNodes = baseMapper.selectList(Wrappers.<WbsTreeContract>lambdaQuery().in(WbsTreeContract::getId, parentIds).eq(WbsTreeContract::getContractId, contractId).eq(WbsTreeContract::getType, 1));
+            if (parentNodes.size() > 0) {
+                resultAllNodes.addAll(parentNodes);
+                this.getConcealedWorkParentNode(resultAllNodes, parentNodes, contractId);
+            }
+        }
+    }
 
-        return null;
+    /**
+     * 递归获取隐蔽工程节点的所有子级节点
+     *
+     * @param resultAllNodes 结果集
+     * @param initNode       初始化节点入参
+     * @param contractId     合同段id
+     */
+    private void getConcealedWorkChildNode(Set<WbsTreeContract> resultAllNodes, List<WbsTreeContract> initNode, String contractId) {
+        Set<Long> childIds = initNode.stream().map(WbsTreeContract::getId).collect(Collectors.toSet());
+        if (childIds.size() > 0) {
+            List<WbsTreeContract> childNodes = baseMapper.selectList(Wrappers.<WbsTreeContract>lambdaQuery().in(WbsTreeContract::getParentId, childIds).eq(WbsTreeContract::getContractId, contractId).eq(WbsTreeContract::getType, 1));
+            if (childNodes.size() > 0) {
+                resultAllNodes.addAll(childNodes);
+                this.getConcealedWorkChildNode(resultAllNodes, childNodes, contractId);
+            }
+        }
     }
 
     /**