liuyc 1 år sedan
förälder
incheckning
d2440ed87b

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

@@ -80,6 +80,8 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
 
     //存储当前合同段contractId对应的合同段树
     private final Map<String, List<WbsTreeContractLazyVO>> localCacheNodes = new ConcurrentHashMap<>();
+    //存储当前合同段contractId_tableOwner对应的资料查询信息缓存
+    private final Map<String, List<WbsTreeContractLazyQueryInfoVO>> localCacheQueryInfos = new ConcurrentHashMap<>();
 
     @Override
     public List<WbsTreeContract> selectQueryCurrentNodeByAncestors(List<String> ids, String contractId) {
@@ -750,7 +752,8 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
                         ));
 
                         //获取当前合同段所有填报资料缓存信息
-                        List<WbsTreeContractLazyQueryInfoVO> queryInfoList;
+                        List<WbsTreeContractLazyQueryInfoVO> queryInfoList = this.getQueryInfoList(contractId, tableOwner);
+                        /*List<WbsTreeContractLazyQueryInfoVO> queryInfoList;
                         Object dataInformationQuery;
                         if (ObjectUtil.isEmpty(tableOwner)) {
                             dataInformationQuery = redisTemplate.opsForValue().get("blade-manager::contract:wbstree:byInformationQuery:" + contractId + "_1");
@@ -773,12 +776,11 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
                                     redisTemplate.opsForValue().set("blade-manager::contract:wbstree:byInformationQuery:" + contractId + "_" + tableOwner, JSON.toJSON(array).toString());
                                 }
                             }
-                        }
+                        }*/
                         Map<Long, Integer> queryInfoMaps = queryInfoList.stream().filter(f -> ObjectUtil.isNotEmpty(f.getWbsId()))
                                 .collect(Collectors.toMap(WbsTreeContractLazyQueryInfoVO::getWbsId, WbsTreeContractLazyQueryInfoVO::getStatus, (existingValue, newValue) -> existingValue));
                         List<Long> pKeyIdList = new ArrayList<>(queryInfoMaps.keySet());
 
-
                         //TODO 处理数量
                         //填报过的所有最底层节点
                         List<WbsTreeContractLazyVO> lowestNodesTB = distinctLowestNodesAll.parallelStream().filter(f -> pKeyIdList.contains(f.getPKeyId())).collect(Collectors.toList());
@@ -941,7 +943,8 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
                                 ));
 
                                 //获取当前合同段所有填报资料缓存信息
-                                List<WbsTreeContractLazyQueryInfoVO> queryInfoList;
+                                List<WbsTreeContractLazyQueryInfoVO> queryInfoList = this.getQueryInfoList(sgContractId, tableOwner);
+                                /*List<WbsTreeContractLazyQueryInfoVO> queryInfoList;
                                 Object dataInformationQuery;
                                 if (ObjectUtil.isEmpty(tableOwner)) {
                                     dataInformationQuery = redisTemplate.opsForValue().get("blade-manager::contract:wbstree:byInformationQuery:" + sgContractId + "_1");
@@ -952,7 +955,7 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
                                     queryInfoList = JSON.parseArray(dataInformationQuery.toString(), WbsTreeContractLazyQueryInfoVO.class);
                                 } else {
                                     if (ObjectUtil.isEmpty(tableOwner)) {
-                                        queryInfoList = jdbcTemplate.query("select wbs_id,status from u_information_query where type = 1 and contract_id = " + sgContractId, new BeanPropertyRowMapper<>(WbsTreeContractLazyQueryInfoVO.class));
+                                        queryInfoList = jdbcTemplate.query("select wbs_id,status from u_information_query where type = 1 and contract_id = " + sgContractId + " and classify = 1", new BeanPropertyRowMapper<>(WbsTreeContractLazyQueryInfoVO.class));
                                         if (queryInfoList.size() > 0) {
                                             JSONArray array = JSONArray.parseArray(JSON.toJSONString(queryInfoList));
                                             redisTemplate.opsForValue().set("blade-manager::contract:wbstree:byInformationQuery:" + sgContractId + "_1", JSON.toJSON(array).toString());
@@ -964,7 +967,7 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
                                             redisTemplate.opsForValue().set("blade-manager::contract:wbstree:byInformationQuery:" + sgContractId + "_" + tableOwner, JSON.toJSON(array).toString());
                                         }
                                     }
-                                }
+                                }*/
                                 Map<Long, Integer> queryInfoMaps = queryInfoList.stream().filter(f -> ObjectUtil.isNotEmpty(f.getWbsId()))
                                         .collect(Collectors.toMap(WbsTreeContractLazyQueryInfoVO::getWbsId, WbsTreeContractLazyQueryInfoVO::getStatus, (existingValue, newValue) -> existingValue));
                                 List<Long> pKeyIdList = new ArrayList<>(queryInfoMaps.keySet());
@@ -1055,6 +1058,60 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
         return null;
     }
 
+    //构建资料查询缓存的key
+    private String buildCacheKey(String contractId, String tableOwner) {
+        if (StringUtils.isNotEmpty(tableOwner)) {
+            return contractId + "_" + tableOwner;
+        } else {
+            return contractId + "_1";
+        }
+    }
+
+    //获取当前合同段所有填报资料缓存信息
+    public List<WbsTreeContractLazyQueryInfoVO> getQueryInfoList(String contractId, String tableOwner) {
+        //从本地缓存获取
+        String cacheKey = buildCacheKey(contractId, tableOwner);
+        List<WbsTreeContractLazyQueryInfoVO> cachedQueryInfoList = localCacheQueryInfos.get(cacheKey);
+
+        if (cachedQueryInfoList != null && !cachedQueryInfoList.isEmpty()) {
+            return cachedQueryInfoList;
+        }
+
+        //根据需要更新localCacheQueryInfos
+        Object dataInformationQuery;
+        if (ObjectUtil.isEmpty(tableOwner)) {
+            dataInformationQuery = redisTemplate.opsForValue().get("blade-manager::contract:wbstree:byInformationQuery:" + contractId + "_1");
+        } else {
+            dataInformationQuery = redisTemplate.opsForValue().get("blade-manager::contract:wbstree:byInformationQuery:" + contractId + "_" + tableOwner);
+        }
+        List<WbsTreeContractLazyQueryInfoVO> queryInfoList;
+        if (dataInformationQuery != null) {
+            //返回redis数据
+            queryInfoList = JSON.parseArray(dataInformationQuery.toString(), WbsTreeContractLazyQueryInfoVO.class);
+            localCacheQueryInfos.put(cacheKey, queryInfoList); //更新本地缓存
+
+        } else {
+            //返回数据库数据
+            String querySql = ObjectUtil.isEmpty(tableOwner) ?
+                    "select wbs_id,status from u_information_query where type = 1 and contract_id = " + contractId + " and classify =1" :
+                    "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));
+
+            if (!queryInfoList.isEmpty()) {
+                JSONArray array = JSONArray.parseArray(JSON.toJSONString(queryInfoList));
+                if (ObjectUtil.isEmpty(tableOwner)) {
+                    redisTemplate.opsForValue().set("blade-manager::contract:wbstree:byInformationQuery:" + contractId + "_1", JSON.toJSON(array).toString());
+                } else {
+                    redisTemplate.opsForValue().set("blade-manager::contract:wbstree:byInformationQuery:" + contractId + "_" + tableOwner, JSON.toJSON(array).toString());
+                }
+                localCacheQueryInfos.put(cacheKey, queryInfoList); //更新本地缓存
+            }
+        }
+
+        return queryInfoList;
+    }
+
     @Override
     public List<WbsTreeContractLazyVO> imageLazyQueryContractWbsTree(String id, String contractId, String
             contractIdRelation, String classId) {
@@ -2679,6 +2736,18 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
 
     /*删除合同段本地缓存*/
     public void deleteContractLocalCache(String contractId) {
+        /*删除节点缓存*/
         localCacheNodes.remove(contractId);
+
+        /*删除资料缓存*/
+        Iterator<Map.Entry<String, List<WbsTreeContractLazyQueryInfoVO>>> iterator = localCacheQueryInfos.entrySet().iterator();
+        while (iterator.hasNext()) {
+            Map.Entry<String, List<WbsTreeContractLazyQueryInfoVO>> entry = iterator.next();
+            String cacheKey = entry.getKey();
+            if (cacheKey.startsWith(contractId + "_")) {
+                iterator.remove();
+            }
+        }
     }
+
 }