|
@@ -83,6 +83,8 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
private final Map<String, List<WbsTreeContractLazyVO>> localCacheNodes = new ConcurrentHashMap<>();
|
|
|
//存储当前合同段contractId_tableOwner对应的资料查询信息
|
|
|
private final Map<String, List<WbsTreeContractLazyQueryInfoVO>> localCacheQueryInfos = new ConcurrentHashMap<>();
|
|
|
+ //存储当前合同段contractId_tableOwner对应的节点数量统计缓存信息
|
|
|
+ private final Map<String, List<WbsTreeContractLazyVO>> localCacheParentCountNodes = new ConcurrentHashMap<>();
|
|
|
|
|
|
@Override
|
|
|
public List<WbsTreeContract> selectQueryCurrentNodeByAncestors(List<String> ids, String contractId) {
|
|
@@ -760,15 +762,8 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
//填报过的所有最底层节点
|
|
|
List<WbsTreeContractLazyVO> lowestNodesTB = distinctLowestNodesAll.parallelStream().filter(f -> pKeyIdList.contains(f.getPKeyId())).collect(Collectors.toList());
|
|
|
List<Long> lowestNodeParentIdsTB = lowestNodesTB.parallelStream().map(WbsTreeContractLazyVO::getParentId).collect(Collectors.toList());
|
|
|
- List<WbsTreeContractLazyVO> resultParentNodesTB = new ArrayList<>();
|
|
|
-
|
|
|
- long startTime2 = System.currentTimeMillis();
|
|
|
-
|
|
|
- this.recursiveGetParentNodes(resultParentNodesTB, lowestNodeParentIdsTB, nodesAll);
|
|
|
-
|
|
|
- long endTime2 = System.currentTimeMillis();
|
|
|
- long executionTime2 = endTime2 - startTime2;
|
|
|
- logger.info("recursiveGetParentNodes 处理数量 执行时间:" + executionTime2 + " ms");
|
|
|
+ //获取本地缓存节点数量统计
|
|
|
+ List<WbsTreeContractLazyVO> resultParentNodesTB = this.getCachedParentCountNodes(contractId, lowestNodeParentIdsTB, nodesAll, tableOwner);
|
|
|
|
|
|
//最底层节点颜色构造后Map
|
|
|
Map<Long, WbsTreeContractLazyVO> lowestNodesMap = lowestNodesTB.stream()
|
|
@@ -784,9 +779,8 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
}
|
|
|
}).collect(Collectors.toMap(WbsTreeContractLazyVO::getPKeyId, Function.identity()));
|
|
|
|
|
|
- long startTime3 = System.currentTimeMillis();
|
|
|
-
|
|
|
/*处理颜色*/
|
|
|
+ long startTime = System.currentTimeMillis();
|
|
|
//先将WbsTreeContractLazyVO转为NodeVO
|
|
|
List<NodeVO> nodeVOList = distinctNodesAll.stream().map(this::convertToNodeVO).collect(Collectors.toList());
|
|
|
//转为Map<Long, NodeVO>
|
|
@@ -799,10 +793,9 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
List<NodeVO> nodeVOS = this.flattenTree(treeNodeVOList);
|
|
|
//获取所有节点颜色Map
|
|
|
Map<Long, Integer> nodeColorStatusMap = nodeVOS.stream().collect(Collectors.toMap(NodeVO::getPKeyId, NodeVO::getStatus, (existing, replacement) -> existing));
|
|
|
-
|
|
|
- long endTime3 = System.currentTimeMillis();
|
|
|
- long executionTime3 = endTime3 - startTime3;
|
|
|
- logger.info("处理颜色执行时间:" + executionTime3 + " ms");
|
|
|
+ long endTime = System.currentTimeMillis();
|
|
|
+ long executionTime = endTime - startTime;
|
|
|
+ logger.info("处理颜色执行时间:" + executionTime + " ms");
|
|
|
|
|
|
/*处理最终结果集*/
|
|
|
if (lazyNodes.size() > 0) {
|
|
@@ -890,8 +883,8 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
|
|
|
List<WbsTreeContractLazyVO> lowestNodesTB = distinctLowestNodesAll.parallelStream().filter(f -> pKeyIdList.contains(f.getPKeyId())).collect(Collectors.toList());
|
|
|
List<Long> lowestNodeParentIdsTB = lowestNodesTB.parallelStream().map(WbsTreeContractLazyVO::getParentId).collect(Collectors.toList());
|
|
|
- List<WbsTreeContractLazyVO> resultParentNodesTB = new ArrayList<>();
|
|
|
- this.recursiveGetParentNodes(resultParentNodesTB, lowestNodeParentIdsTB, nodesAll);
|
|
|
+
|
|
|
+ List<WbsTreeContractLazyVO> resultParentNodesTB = this.getCachedParentCountNodes(sgContractId, lowestNodeParentIdsTB, nodesAll, tableOwner);
|
|
|
|
|
|
Map<Long, WbsTreeContractLazyVO> lowestNodesMap = lowestNodesTB.stream()
|
|
|
.peek(vo -> {
|
|
@@ -960,30 +953,32 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- //获取当前合同段所有节点缓存
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取当前合同段所有节点缓存
|
|
|
+ *
|
|
|
+ * @param contractId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
public List<WbsTreeContractLazyVO> getNodeAll(String contractId) {
|
|
|
- /*获取本地缓存*/
|
|
|
+ //获取本地缓存
|
|
|
List<WbsTreeContractLazyVO> nodesAll = localCacheNodes.get(contractId);
|
|
|
|
|
|
if (nodesAll == null || nodesAll.size() == 0) {
|
|
|
-
|
|
|
- //获取当前合同段所有缓存节点信息
|
|
|
+ //从Redis获取数据
|
|
|
Object data = redisTemplate.opsForValue().get("blade-manager::contract:wbstree:" + contractId);
|
|
|
if (data != null) {
|
|
|
- //从Redis获取数据
|
|
|
nodesAll = JSON.parseArray(data.toString(), WbsTreeContractLazyVO.class);
|
|
|
- /*更新本地缓存*/
|
|
|
+ //更新本地缓存
|
|
|
localCacheNodes.put(contractId, nodesAll);
|
|
|
|
|
|
} else {
|
|
|
-
|
|
|
- long startTime1 = System.currentTimeMillis();
|
|
|
-
|
|
|
+ //返回数据库数据
|
|
|
+ long startTime = System.currentTimeMillis();
|
|
|
nodesAll = jdbcTemplate.query("select a.p_key_id,a.id,a.parent_id from m_wbs_tree_contract a where a.type = 1 and a.status = 1 and a.is_deleted = 0 and a.contract_id = " + contractId, new BeanPropertyRowMapper<>(WbsTreeContractLazyVO.class));
|
|
|
-
|
|
|
- long endTime1 = System.currentTimeMillis();
|
|
|
- long executionTime1 = endTime1 - startTime1;
|
|
|
- logger.info("查询合同段" + contractId + "所有树执行时间:" + executionTime1 + " ms");
|
|
|
+ long endTime = System.currentTimeMillis();
|
|
|
+ long executionTime = endTime - startTime;
|
|
|
+ logger.info("查询合同段 " + contractId + " 所有树执行时间:" + executionTime + " ms");
|
|
|
|
|
|
if (nodesAll.size() > 0) {
|
|
|
//判断是否有子级,赋值
|
|
@@ -999,18 +994,72 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
vo.setHasChildren(0);
|
|
|
}
|
|
|
}
|
|
|
- /*更新本地缓存*/
|
|
|
- localCacheNodes.put(contractId, nodesAll);
|
|
|
-
|
|
|
+ //存储到Redis中
|
|
|
JSONArray array = JSONArray.parseArray(JSON.toJSONString(nodesAll));
|
|
|
redisTemplate.opsForValue().set("blade-manager::contract:wbstree:" + contractId, JSON.toJSON(array).toString());
|
|
|
+
|
|
|
+ //更新本地缓存
|
|
|
+ localCacheNodes.put(contractId, nodesAll);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return nodesAll;
|
|
|
}
|
|
|
|
|
|
- //获取当前合同段所有填报资料缓存信息
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取节点数量统计缓存
|
|
|
+ *
|
|
|
+ * @param contractId
|
|
|
+ * @param lowestNodeParentIdsTB
|
|
|
+ * @param nodesAll
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<WbsTreeContractLazyVO> getCachedParentCountNodes(String contractId, List<Long> lowestNodeParentIdsTB, List<WbsTreeContractLazyVO> nodesAll, String tableOwner) {
|
|
|
+ //从本地缓存获取数据
|
|
|
+ String cacheKey = contractId + "_" + tableOwner;
|
|
|
+ List<WbsTreeContractLazyVO> resultParentNodesTB = localCacheParentCountNodes.get(cacheKey);
|
|
|
+
|
|
|
+ if (resultParentNodesTB == null || resultParentNodesTB.isEmpty()) {
|
|
|
+
|
|
|
+ //从Redis获取数据
|
|
|
+ Object data = redisTemplate.opsForValue().get("blade-manager::contract:wbstree:byParentCountNodes:" + cacheKey);
|
|
|
+ if (data != null) {
|
|
|
+ resultParentNodesTB = JSON.parseArray(data.toString(), WbsTreeContractLazyVO.class);
|
|
|
+ //更新本地缓存
|
|
|
+ localCacheParentCountNodes.put(cacheKey, resultParentNodesTB);
|
|
|
+
|
|
|
+ } else {
|
|
|
+ /*重新计算,进行递归获取父节点计数统计*/
|
|
|
+ resultParentNodesTB = new ArrayList<>();
|
|
|
+ long startTime = System.currentTimeMillis();
|
|
|
+ this.recursiveGetParentNodes(resultParentNodesTB, lowestNodeParentIdsTB, nodesAll);
|
|
|
+ long endTime = System.currentTimeMillis();
|
|
|
+ long executionTime = endTime - startTime;
|
|
|
+ logger.info("节点树数量统计计算耗时:" + executionTime + " ms");
|
|
|
+
|
|
|
+ if (resultParentNodesTB.size() > 0) {
|
|
|
+ //存储到Redis中
|
|
|
+ JSONArray array = JSONArray.parseArray(JSON.toJSONString(resultParentNodesTB));
|
|
|
+ redisTemplate.opsForValue().set("blade-manager::contract:wbstree:byParentCountNodes:" + cacheKey, JSON.toJSON(array).toString());
|
|
|
+
|
|
|
+ //更新本地缓存
|
|
|
+ localCacheParentCountNodes.put(cacheKey, resultParentNodesTB);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return resultParentNodesTB;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取当前合同段所有填报资料缓存信息
|
|
|
+ *
|
|
|
+ * @param contractId
|
|
|
+ * @param tableOwner
|
|
|
+ * @return
|
|
|
+ */
|
|
|
public List<WbsTreeContractLazyQueryInfoVO> getQueryInfoList(String contractId, String tableOwner) {
|
|
|
//从本地缓存获取
|
|
|
String cacheKey = contractId + "_" + tableOwner;
|
|
@@ -1020,27 +1069,28 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
return cachedQueryInfoList;
|
|
|
}
|
|
|
|
|
|
- //获取redis缓存
|
|
|
+ //从Redis获取数据
|
|
|
Object dataInformationQuery = redisTemplate.opsForValue().get("blade-manager::contract:wbstree:byInformationQuery:" + cacheKey);
|
|
|
|
|
|
List<WbsTreeContractLazyQueryInfoVO> queryInfoList;
|
|
|
if (dataInformationQuery != null) {
|
|
|
- //返回redis数据
|
|
|
queryInfoList = JSON.parseArray(dataInformationQuery.toString(), WbsTreeContractLazyQueryInfoVO.class);
|
|
|
-
|
|
|
//更新本地缓存
|
|
|
localCacheQueryInfos.put(cacheKey, queryInfoList);
|
|
|
|
|
|
} else {
|
|
|
//返回数据库数据
|
|
|
+ long startTime = System.currentTimeMillis();
|
|
|
String querySql = "select wbs_id,status from u_information_query where type = 1 and contract_id = " + contractId + " and classify = " + tableOwner;
|
|
|
-
|
|
|
queryInfoList = jdbcTemplate.query(querySql, new BeanPropertyRowMapper<>(WbsTreeContractLazyQueryInfoVO.class));
|
|
|
+ long endTime = System.currentTimeMillis();
|
|
|
+ long executionTime = endTime - startTime;
|
|
|
+ logger.info("合同段资料信息查询耗时:" + executionTime + " ms");
|
|
|
|
|
|
if (!queryInfoList.isEmpty()) {
|
|
|
JSONArray array = JSONArray.parseArray(JSON.toJSONString(queryInfoList));
|
|
|
|
|
|
- //存储redis
|
|
|
+ //存储到Redis中
|
|
|
redisTemplate.opsForValue().set("blade-manager::contract:wbstree:byInformationQuery:" + cacheKey, JSON.toJSON(array).toString());
|
|
|
|
|
|
//更新本地缓存
|
|
@@ -1429,8 +1479,7 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
* @param lowestNodeParentIds 最底层节点ParentIds
|
|
|
* @param nodesAll 所有节点
|
|
|
*/
|
|
|
- public void recursiveGetParentNodes
|
|
|
- (List<WbsTreeContractLazyVO> result, List<Long> lowestNodeParentIds, List<WbsTreeContractLazyVO> nodesAll) {
|
|
|
+ public void recursiveGetParentNodes(List<WbsTreeContractLazyVO> result, List<Long> lowestNodeParentIds, List<WbsTreeContractLazyVO> nodesAll) {
|
|
|
if (lowestNodeParentIds.isEmpty()) {
|
|
|
return;
|
|
|
}
|
|
@@ -1467,58 +1516,6 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /*public void recursiveGetParentNodes(List<WbsTreeContractLazyVO> result, List<Long> lowestNodeParentIds, List<WbsTreeContractLazyVO> nodesAll) {
|
|
|
- if (lowestNodeParentIds.isEmpty()) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- //父级Id与出现的次数Map
|
|
|
- Map<Long, Long> parentIdGroup = lowestNodeParentIds.parallelStream()
|
|
|
- .collect(Collectors.groupingByConcurrent(Function.identity(), Collectors.counting()));
|
|
|
-
|
|
|
- Set<Long> keysWithValueOne = new HashSet<>(); //单次
|
|
|
- Map<Long, Long> keysWithValueSome = new ConcurrentHashMap<>(); //多次
|
|
|
-
|
|
|
- parentIdGroup.forEach((key, value) -> {
|
|
|
- if (value == 1L) {
|
|
|
- keysWithValueOne.add(key);
|
|
|
- } else {
|
|
|
- keysWithValueSome.put(key, value);
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- //批量查询单次节点
|
|
|
- List<WbsTreeContractLazyVO> parentNodes = new ArrayList<>();
|
|
|
- if (!keysWithValueOne.isEmpty()) {
|
|
|
- parentNodes = nodesAll.parallelStream()
|
|
|
- .filter(f -> keysWithValueOne.contains(f.getId()))
|
|
|
- .collect(Collectors.toList());
|
|
|
- }
|
|
|
-
|
|
|
- //批量查询多次节点
|
|
|
- List<WbsTreeContractLazyVO> multipleParentNodes = new ArrayList<>();
|
|
|
- keysWithValueSome.forEach((key, count) -> {
|
|
|
- List<WbsTreeContractLazyVO> nodes = nodesAll.parallelStream()
|
|
|
- .filter(f -> key.equals(f.getId()))
|
|
|
- .limit(1) //限制只取一个
|
|
|
- .collect(Collectors.toList());
|
|
|
- if (!nodes.isEmpty()) {
|
|
|
- multipleParentNodes.addAll(Collections.nCopies(count.intValue(), nodes.get(0)));
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- //结果集
|
|
|
- List<Long> collect = Stream.concat(parentNodes.stream(), multipleParentNodes.stream())
|
|
|
- .map(WbsTreeContractLazyVO::getParentId)
|
|
|
- .collect(Collectors.toList());
|
|
|
-
|
|
|
- if (!collect.isEmpty()) {
|
|
|
- result.addAll(parentNodes);
|
|
|
- result.addAll(multipleParentNodes);
|
|
|
- this.recursiveGetParentNodes(result, collect, nodesAll);
|
|
|
- }
|
|
|
- }*/
|
|
|
-
|
|
|
@Override
|
|
|
public boolean syncTabData(String pKeyId) throws Exception {
|
|
|
WbsTreeContract node = baseMapper.selectOne(Wrappers.<WbsTreeContract>lambdaQuery().eq(WbsTreeContract::getPKeyId, pKeyId));
|
|
@@ -2662,12 +2659,22 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
localCacheNodes.remove(contractId);
|
|
|
|
|
|
/*删除资料缓存*/
|
|
|
- Iterator<Map.Entry<String, List<WbsTreeContractLazyQueryInfoVO>>> iterator = localCacheQueryInfos.entrySet().iterator();
|
|
|
- while (iterator.hasNext()) {
|
|
|
- Map.Entry<String, List<WbsTreeContractLazyQueryInfoVO>> entry = iterator.next();
|
|
|
+ Iterator<Map.Entry<String, List<WbsTreeContractLazyQueryInfoVO>>> iterator_1 = localCacheQueryInfos.entrySet().iterator();
|
|
|
+ while (iterator_1.hasNext()) {
|
|
|
+ Map.Entry<String, List<WbsTreeContractLazyQueryInfoVO>> entry = iterator_1.next();
|
|
|
+ String cacheKey = entry.getKey();
|
|
|
+ if (cacheKey.startsWith(contractId + "_")) {
|
|
|
+ iterator_1.remove();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /*删除节点计算统计缓存*/
|
|
|
+ Iterator<Map.Entry<String, List<WbsTreeContractLazyVO>>> iterator_2 = localCacheParentCountNodes.entrySet().iterator();
|
|
|
+ while (iterator_2.hasNext()) {
|
|
|
+ Map.Entry<String, List<WbsTreeContractLazyVO>> entry = iterator_2.next();
|
|
|
String cacheKey = entry.getKey();
|
|
|
if (cacheKey.startsWith(contractId + "_")) {
|
|
|
- iterator.remove();
|
|
|
+ iterator_2.remove();
|
|
|
}
|
|
|
}
|
|
|
}
|