liuyc 1 年之前
父节点
当前提交
3ec3a3b5c2

+ 54 - 6
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/WbsTreeContractServiceImpl.java

@@ -57,7 +57,7 @@ import javax.servlet.http.HttpServletRequest;
 import java.io.*;
 import java.math.BigInteger;
 import java.util.*;
-import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.*;
 import java.util.function.Function;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
@@ -764,6 +764,8 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
                         List<Long> lowestNodeParentIdsTB = lowestNodesTB.parallelStream().map(WbsTreeContractLazyVO::getParentId).collect(Collectors.toList());
                         //获取本地缓存节点数量统计
                         List<WbsTreeContractLazyVO> resultParentNodesTB = this.getCachedParentCountNodes(contractId, lowestNodeParentIdsTB, nodesAll, tableOwner);
+                        //List<WbsTreeContractLazyVO> resultParentNodesTB = new ArrayList<>();
+                        //this.recursiveGetParentNodes(resultParentNodesTB, lowestNodeParentIdsTB, nodesAll);
 
                         //最底层节点颜色构造后Map
                         Map<Long, WbsTreeContractLazyVO> lowestNodesMap = lowestNodesTB.stream()
@@ -1485,20 +1487,20 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
         }
 
         //父级Id与出现的次数Map
-        Map<Long, Long> parentIdGroup = lowestNodeParentIds.parallelStream()
+        Map<Long, Long> parentIdGroup = lowestNodeParentIds.stream()
                 .collect(Collectors.groupingByConcurrent(Function.identity(), Collectors.counting()));
 
         //批量查询单次节点
-        List<WbsTreeContractLazyVO> parentNodes = parentIdGroup.entrySet().parallelStream()
+        List<WbsTreeContractLazyVO> parentNodes = parentIdGroup.entrySet().stream()
                 .filter(entry -> entry.getValue() == 1L)
-                .flatMap(entry -> nodesAll.parallelStream()
+                .flatMap(entry -> nodesAll.stream()
                         .filter(f -> entry.getKey().equals(f.getId())))
                 .collect(Collectors.toList());
 
         //批量查询多次节点
-        List<WbsTreeContractLazyVO> multipleParentNodes = parentIdGroup.entrySet().parallelStream()
+        List<WbsTreeContractLazyVO> multipleParentNodes = parentIdGroup.entrySet().stream()
                 .filter(entry -> entry.getValue() > 1L)
-                .flatMap(entry -> nodesAll.parallelStream()
+                .flatMap(entry -> nodesAll.stream()
                         .filter(f -> entry.getKey().equals(f.getId()))
                         .limit(1)
                         .flatMap(node -> Collections.nCopies(entry.getValue().intValue(), node).stream()))
@@ -1516,6 +1518,52 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
         }
     }
 
+    /*
+    public void recursiveGetParentNodes(List<WbsTreeContractLazyVO> result, List<Long> lowestNodeParentIds, List<WbsTreeContractLazyVO> nodesAll) {
+        if (lowestNodeParentIds.isEmpty()) {
+            return;
+        }
+
+        //设置并行度为3(解决并发时重复创建线程)
+        ForkJoinPool customThreadPool = new ForkJoinPool(3);
+
+        //父级Id与出现的次数Map
+        Map<Long, Long> parentIdGroup = lowestNodeParentIds.parallelStream()
+                .collect(Collectors.groupingByConcurrent(Function.identity(), Collectors.counting()));
+
+        //批量查询单次节点
+        CompletableFuture<List<WbsTreeContractLazyVO>> parentNodesFuture = CompletableFuture.supplyAsync(() ->
+                parentIdGroup.entrySet().stream()
+                        .filter(entry -> entry.getValue() == 1L)
+                        .flatMap(entry -> nodesAll.parallelStream()
+                                .filter(f -> entry.getKey().equals(f.getId())))
+                        .collect(Collectors.toList()), customThreadPool);
+
+        //批量查询多次节点
+        CompletableFuture<List<WbsTreeContractLazyVO>> multipleParentNodesFuture = CompletableFuture.supplyAsync(() ->
+                parentIdGroup.entrySet().stream()
+                        .filter(entry -> entry.getValue() > 1L)
+                        .flatMap(entry -> nodesAll.parallelStream()
+                                .filter(f -> entry.getKey().equals(f.getId()))
+                                .limit(1)
+                                .flatMap(node -> Collections.nCopies(entry.getValue().intValue(), node).stream()))
+                        .collect(Collectors.toList()), customThreadPool);
+
+        //结果集
+        CompletableFuture<List<Long>> collectFuture = parentNodesFuture.thenCombine(multipleParentNodesFuture, (parentNodes, multipleParentNodes) ->
+                Stream.concat(parentNodes.stream(), multipleParentNodes.stream())
+                        .map(WbsTreeContractLazyVO::getParentId)
+                        .collect(Collectors.toList()));
+
+        List<Long> collect = collectFuture.join();
+
+        if (!collect.isEmpty()) {
+            result.addAll(parentNodesFuture.join());
+            result.addAll(multipleParentNodesFuture.join());
+            this.recursiveGetParentNodes(result, collect, nodesAll);
+        }
+    }*/
+
     @Override
     public boolean syncTabData(String pKeyId) throws Exception {
         WbsTreeContract node = baseMapper.selectOne(Wrappers.<WbsTreeContract>lambdaQuery().eq(WbsTreeContract::getPKeyId, pKeyId));