|
@@ -68,6 +68,11 @@ import java.util.stream.Stream;
|
|
|
@AllArgsConstructor
|
|
|
public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractMapper, WbsTreeContract> implements IWbsTreeContractService {
|
|
|
|
|
|
+ static {
|
|
|
+ /*parallelStream并行流粒度*/
|
|
|
+ System.setProperty("java.util.concurrent.ForkJoinPool.common.parallelism", "4");
|
|
|
+ }
|
|
|
+
|
|
|
private static final Logger logger = LoggerFactory.getLogger(WbsTreeContractServiceImpl.class);
|
|
|
private final ConstructionLedgerFeignClient constructionLedgerFeign;
|
|
|
private final WbsTreePrivateMapper wbsTreePrivateMapper;
|
|
@@ -742,6 +747,10 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
for (WbsTreeContractLazyVO lazyNode : lazyNodes) {
|
|
|
lazyNode.setSubmitCounts(0);
|
|
|
lazyNode.setColorStatus(2);
|
|
|
+ lazyNode.setType(lazyNode.getNodeType());
|
|
|
+ lazyNode.setNotExsitChild(!lazyNode.getHasChildren().equals(1));
|
|
|
+ lazyNode.setPrimaryKeyId(lazyNode.getPKeyId());
|
|
|
+ lazyNode.setTitle(contractInfo.getContractName());
|
|
|
}
|
|
|
return lazyNodes;
|
|
|
}
|
|
@@ -773,8 +782,13 @@ 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);
|
|
|
+
|
|
|
+ /*List<WbsTreeContractLazyVO> resultParentNodesTB = new ArrayList<>();
|
|
|
+ long startTime1 = System.currentTimeMillis();
|
|
|
+ this.recursiveGetParentNodes(resultParentNodesTB, lowestNodeParentIdsTB, nodesAll);
|
|
|
+ long endTime1 = System.currentTimeMillis();
|
|
|
+ long executionTime1 = endTime1 - startTime1;
|
|
|
+ logger.info("合同段 " + contractId + " wbs节点树 数量计算 耗时:" + executionTime1 + " ms");*/
|
|
|
|
|
|
//最底层节点颜色构造后Map
|
|
|
Map<Long, WbsTreeContractLazyVO> lowestNodesMap = lowestNodesTB.stream()
|
|
@@ -879,6 +893,11 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
for (WbsTreeContractLazyVO lazyNode : lazyNodes) {
|
|
|
lazyNode.setSubmitCounts(0);
|
|
|
lazyNode.setColorStatus(2);
|
|
|
+ lazyNode.setType(lazyNode.getNodeType());
|
|
|
+ lazyNode.setNotExsitChild(!lazyNode.getHasChildren().equals(1));
|
|
|
+ lazyNode.setPrimaryKeyId(lazyNode.getPKeyId());
|
|
|
+ lazyNode.setContractIdRelation(sgContractId);
|
|
|
+ lazyNode.setTitle(sgContractInfo.getContractName());
|
|
|
}
|
|
|
return lazyNodes;
|
|
|
}
|
|
@@ -1048,7 +1067,6 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
return nodesAll;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 获取节点数量统计缓存
|
|
|
*
|
|
@@ -1549,18 +1567,18 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
}
|
|
|
|
|
|
//父级Id与出现的次数Map
|
|
|
- Map<Long, Long> parentIdGroup = lowestNodeParentIds.stream()
|
|
|
+ Map<Long, Long> parentIdGroup = lowestNodeParentIds.parallelStream()
|
|
|
.collect(Collectors.groupingByConcurrent(Function.identity(), Collectors.counting()));
|
|
|
|
|
|
//批量查询单次节点
|
|
|
- List<WbsTreeContractLazyVO> parentNodes = parentIdGroup.entrySet().stream()
|
|
|
+ List<WbsTreeContractLazyVO> parentNodes = parentIdGroup.entrySet().parallelStream()
|
|
|
.filter(entry -> entry.getValue() == 1L)
|
|
|
.flatMap(entry -> nodesAll.stream()
|
|
|
.filter(f -> entry.getKey().equals(f.getId())))
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
//批量查询多次节点
|
|
|
- List<WbsTreeContractLazyVO> multipleParentNodes = parentIdGroup.entrySet().stream()
|
|
|
+ List<WbsTreeContractLazyVO> multipleParentNodes = parentIdGroup.entrySet().parallelStream()
|
|
|
.filter(entry -> entry.getValue() > 1L)
|
|
|
.flatMap(entry -> nodesAll.stream()
|
|
|
.filter(f -> entry.getKey().equals(f.getId()))
|
|
@@ -1579,48 +1597,36 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
this.recursiveGetParentNodes(result, collect, nodesAll);
|
|
|
}
|
|
|
}*/
|
|
|
-
|
|
|
public void recursiveGetParentNodes(List<WbsTreeContractLazyVO> result, List<Long> lowestNodeParentIds, List<WbsTreeContractLazyVO> nodesAll) {
|
|
|
if (lowestNodeParentIds.isEmpty()) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- //并行粒度4
|
|
|
- ForkJoinPool customThreadPool = new ForkJoinPool(2);
|
|
|
-
|
|
|
- //父级Id与出现的次数Map
|
|
|
- Map<Long, Long> parentIdGroup = lowestNodeParentIds.parallelStream()
|
|
|
+ Map<Long, Long> parentIdGroup = lowestNodeParentIds.stream()
|
|
|
.collect(Collectors.groupingByConcurrent(Function.identity(), Collectors.counting()));
|
|
|
|
|
|
- //批量查询单次节点
|
|
|
- CompletableFuture<List<WbsTreeContractLazyVO>> parentNodesFuture = CompletableFuture.supplyAsync(() ->
|
|
|
- parentIdGroup.entrySet().parallelStream()
|
|
|
- .filter(entry -> entry.getValue() == 1L)
|
|
|
- .flatMap(entry -> nodesAll.parallelStream()
|
|
|
- .filter(f -> entry.getKey().equals(f.getId())))
|
|
|
- .collect(Collectors.toList()), customThreadPool);
|
|
|
+ List<WbsTreeContractLazyVO> collectedNodes = parentIdGroup.entrySet().parallelStream()
|
|
|
+ .flatMap(entry -> {
|
|
|
+ List<WbsTreeContractLazyVO> nodes = nodesAll.stream()
|
|
|
+ .filter(f -> entry.getKey().equals(f.getId()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
|
- //批量查询多次节点
|
|
|
- CompletableFuture<List<WbsTreeContractLazyVO>> multipleParentNodesFuture = CompletableFuture.supplyAsync(() ->
|
|
|
- parentIdGroup.entrySet().parallelStream()
|
|
|
- .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).parallelStream()))
|
|
|
- .collect(Collectors.toList()), customThreadPool);
|
|
|
+ if (entry.getValue() > 1L) {
|
|
|
+ nodes = nodes.stream().limit(1)
|
|
|
+ .flatMap(node -> Collections.nCopies(entry.getValue().intValue(), node).stream())
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ }
|
|
|
|
|
|
- //结果集
|
|
|
- CompletableFuture<List<Long>> collectFuture = parentNodesFuture.thenCombine(multipleParentNodesFuture, (parentNodes, multipleParentNodes) ->
|
|
|
- Stream.concat(parentNodes.parallelStream(), multipleParentNodes.parallelStream())
|
|
|
- .map(WbsTreeContractLazyVO::getParentId)
|
|
|
- .collect(Collectors.toList()));
|
|
|
+ return nodes.stream();
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
|
- List<Long> collect = collectFuture.join();
|
|
|
+ List<Long> collect = collectedNodes.stream()
|
|
|
+ .map(WbsTreeContractLazyVO::getParentId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
|
if (!collect.isEmpty()) {
|
|
|
- result.addAll(parentNodesFuture.join());
|
|
|
- result.addAll(multipleParentNodesFuture.join());
|
|
|
+ result.addAll(collectedNodes);
|
|
|
this.recursiveGetParentNodes(result, collect, nodesAll);
|
|
|
}
|
|
|
}
|