Sfoglia il codice sorgente

合同段wbs树相关

liuyc 1 anno fa
parent
commit
d015f29232

+ 6 - 1
blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/feign/WbsTreeContractClient.java

@@ -181,5 +181,10 @@ public interface WbsTreeContractClient {
 
     //获取 节点下表单
     @GetMapping(API_PREFIX + "/searchNodeAllTableInfo")
-    List<AppWbsTreeContractVO> searchNodeAllTableInfo(@RequestParam String primaryKeyId, @RequestParam String type, @RequestParam String contractId, @RequestParam String projectId,@RequestParam Long userId);
+    List<AppWbsTreeContractVO> searchNodeAllTableInfo(@RequestParam String primaryKeyId, @RequestParam String type, @RequestParam String contractId, @RequestParam String projectId, @RequestParam Long userId);
+
+    /*删除合同段本地缓存*/
+    @GetMapping(API_PREFIX + "/deleteContractLocalCache")
+    void deleteContractLocalCache(@RequestParam String contractId);
+
 }

+ 3 - 0
blade-service/blade-business/src/main/java/org/springblade/business/service/impl/InformationQueryServiceImpl.java

@@ -919,6 +919,9 @@ public class InformationQueryServiceImpl extends BaseServiceImpl<InformationQuer
         if (keysByInformationQuery != null) {
             RedisTemplate.delete(keysByInformationQuery);
         }
+
+        //删除合同段本地缓存
+        wbsTreeContractClient.deleteContractLocalCache(contractId);
     }
 
     @Override

+ 6 - 0
blade-service/blade-manager/src/main/java/org/springblade/manager/feign/WbsTreeContractClientImpl.java

@@ -425,4 +425,10 @@ public class WbsTreeContractClientImpl implements WbsTreeContractClient {
         return list;
     }
 
+    /*删除合同段本地缓存*/
+    @Override
+    public void deleteContractLocalCache(String contractId) {
+        wbsTreeContractServiceImpl.deleteContractLocalCache(contractId);
+    }
+
 }

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

@@ -9,7 +9,7 @@ import org.springblade.manager.vo.*;
 
 import java.util.List;
 
-@CacheNamespace
+//@CacheNamespace
 public interface WbsTreeContractMapper extends EasyBaseMapper<WbsTreeContract> {
 
     int deleteByIds(@Param("ids") List<Long> ids);

+ 98 - 90
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/WbsTreeContractServiceImpl.java

@@ -25,7 +25,6 @@ import org.springblade.common.utils.SnowFlakeUtil;
 import org.springblade.core.log.exception.ServiceException;
 import org.springblade.core.mp.base.BaseServiceImpl;
 import org.springblade.core.secure.utils.AuthUtil;
-import org.springblade.core.secure.utils.SecureUtil;
 import org.springblade.core.tool.node.ForestNodeMerger;
 import org.springblade.core.tool.utils.*;
 import org.springblade.manager.bean.NodeVO;
@@ -52,10 +51,7 @@ import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.LinkedCaseInsensitiveMap;
 import org.springframework.web.multipart.MultipartFile;
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
+import java.io.*;
 import java.math.BigInteger;
 import java.util.*;
 import java.util.concurrent.ConcurrentHashMap;
@@ -79,6 +75,8 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
     @Autowired
     StringRedisTemplate redisTemplate;
 
+    //存储当前合同段contractId对应的合同段树
+    private final Map<String, List<WbsTreeContractLazyVO>> localCacheNodes = new ConcurrentHashMap<>();
 
     @Override
     public List<WbsTreeContract> selectQueryCurrentNodeByAncestors(List<String> ids, String contractId) {
@@ -682,52 +680,64 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
     @Override
     public List<WbsTreeContractLazyVO> lazyQueryContractWbsTree(String id, String contractId, String contractIdRelation, String tableOwner) {
         if (ObjectUtil.isNotEmpty(contractId)) {
-            ContractInfo contractInfo = jdbcTemplate.query("select contract_name,contract_type from m_contract_info where id = " + contractId, new BeanPropertyRowMapper<>(ContractInfo.class)).stream().findAny().orElse(null);
+            ContractInfo contractInfo = contractInfoMapper.selectOne(Wrappers.<ContractInfo>lambdaQuery().select(ContractInfo::getContractName, ContractInfo::getContractType).eq(ContractInfo::getId, contractId));
             if (contractInfo != null) {
                 //TODO ************ 施工合同段 ************
                 if (new Integer(1).equals(contractInfo.getContractType())) {
-                    //获取当前合同段所有缓存节点信息
-                    List<WbsTreeContractLazyVO> nodesAll;
-                    /*Object data = redisTemplate.opsForValue().get("blade-manager::contract:wbstree:" + contractId);
-                    if (data != null) {
-                        nodesAll = JSON.parseArray(data.toString(), WbsTreeContractLazyVO.class);
-                    } else {*/
-
-                    //long startTime1 = System.currentTimeMillis();
-
-                    /*开启mybatis-plus二级缓存*/
-                    List<WbsTreeContract> wbsTreeContracts = baseMapper.selectList(Wrappers.<WbsTreeContract>lambdaQuery()
-                            .select(WbsTreeContract::getId, WbsTreeContract::getPKeyId, WbsTreeContract::getParentId)
-                            .eq(WbsTreeContract::getType, 1)
-                            .eq(WbsTreeContract::getStatus, 1)
-                            .eq(WbsTreeContract::getContractId, contractId)
-                    );
-
-                    /*long endTime1 = System.currentTimeMillis();
-                    long executionTime1 = endTime1 - startTime1;
-                    System.out.println("1111111111111:" + executionTime1);*/
-
-                    nodesAll = BeanUtil.copyProperties(wbsTreeContracts, WbsTreeContractLazyVO.class);
-
-                    //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));
-                    if (nodesAll.size() > 0) {
-                        //判断是否有子级,赋值
-                        Map<Long, List<WbsTreeContractLazyVO>> groupedByParentId = nodesAll.stream().collect(Collectors.groupingBy(WbsTreeContractLazyVO::getParentId));
-                        for (WbsTreeContractLazyVO vo : nodesAll) {
-                            if (vo.getParentId() == 0) {
-                                vo.setHasChildren(1);
-                            }
-                            List<WbsTreeContractLazyVO> childNodes = groupedByParentId.getOrDefault(vo.getId(), null);
-                            if (childNodes != null && childNodes.size() > 0) {
-                                vo.setHasChildren(1);
-                            } else {
-                                vo.setHasChildren(0);
+                    /*获取本地缓存*/
+                    List<WbsTreeContractLazyVO> nodesAll = localCacheNodes.get(contractId);
+
+                    if (nodesAll == null || nodesAll.size() == 0) {
+
+                        //获取当前合同段所有缓存节点信息
+                        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();
+
+                            /*开启mybatis-plus二级缓存*/
+                            /*List<WbsTreeContract> wbsTreeContracts = baseMapper.selectList(Wrappers.<WbsTreeContract>lambdaQuery()
+                                    .select(WbsTreeContract::getId, WbsTreeContract::getPKeyId, WbsTreeContract::getParentId)
+                                    .eq(WbsTreeContract::getType, 1)
+                                    .eq(WbsTreeContract::getStatus, 1)
+                                    .eq(WbsTreeContract::getContractId, contractId)
+                            );
+                            nodesAll = BeanUtil.copyProperties(wbsTreeContracts, WbsTreeContractLazyVO.class);*/
+
+                            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;
+                            System.out.println("baseMapper.selectList(contractId)执行时间:" + executionTime1 + " ms");
+
+                            if (nodesAll.size() > 0) {
+                                //判断是否有子级,赋值
+                                Map<Long, List<WbsTreeContractLazyVO>> groupedByParentId = nodesAll.stream().collect(Collectors.groupingBy(WbsTreeContractLazyVO::getParentId));
+                                for (WbsTreeContractLazyVO vo : nodesAll) {
+                                    if (vo.getParentId() == 0) {
+                                        vo.setHasChildren(1);
+                                    }
+                                    List<WbsTreeContractLazyVO> childNodes = groupedByParentId.getOrDefault(vo.getId(), null);
+                                    if (childNodes != null && childNodes.size() > 0) {
+                                        vo.setHasChildren(1);
+                                    } else {
+                                        vo.setHasChildren(0);
+                                    }
+                                }
+                                /*更新本地缓存*/
+                                localCacheNodes.put(contractId, nodesAll);
+
+                                JSONArray array = JSONArray.parseArray(JSON.toJSONString(nodesAll));
+                                redisTemplate.opsForValue().set("blade-manager::contract:wbstree:" + contractId, JSON.toJSON(array).toString());
                             }
                         }
-                        /*JSONArray array = JSONArray.parseArray(JSON.toJSONString(nodesAll));
-                        redisTemplate.opsForValue().set("blade-manager::contract:wbstree:" + contractId, JSON.toJSON(array).toString());*/
                     }
-                    //}
 
                     //获取当前层懒加载节点
                     List<WbsTreeContractLazyVO> lazyNodes = jdbcTemplate.query("select p_key_id,contract_id,(SELECT id FROM u_contract_tree_drawings where process_id = p_key_id) AS drawingsId,id,parent_id,node_type,type,wbs_type,is_concrete,major_data_type,partition_code,old_id,contract_id_relation,is_concealed_works_node,CASE (SELECT count(1) FROM u_tree_contract_first AS tcf WHERE tcf.is_deleted = 0 AND tcf.wbs_node_id = a.p_key_id) WHEN 0 THEN 'false' ELSE 'true' END AS isFirst,IFNULL(if(length(trim(full_name))>0,full_name,node_name),node_name) AS title,(SELECT CASE WHEN count(1) > 0 THEN 1 ELSE 0 END FROM m_wbs_tree_contract b WHERE b.parent_id = a.id AND b.type = 1 and b.status = 1 AND b.contract_id = " + contractId + " AND b.is_deleted = 0 ) AS hasChildren from m_wbs_tree_contract a where a.node_type != 111 and a.type = 1 and a.status = 1 and a.is_deleted = 0 and parent_id = " + (StringUtils.isNotEmpty(id) ? id : 0) + " and contract_id = " + contractId + " ORDER BY a.sort,title,a.create_time", new BeanPropertyRowMapper<>(WbsTreeContractLazyVO.class));
@@ -781,13 +791,13 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
                         List<Long> lowestNodeParentIdsTB = lowestNodesTB.parallelStream().map(WbsTreeContractLazyVO::getParentId).collect(Collectors.toList());
                         List<WbsTreeContractLazyVO> resultParentNodesTB = new ArrayList<>();
 
-                        //long startTime2 = System.currentTimeMillis();
+                        long startTime2 = System.currentTimeMillis();
 
                         this.recursiveGetParentNodes(resultParentNodesTB, lowestNodeParentIdsTB, nodesAll);
 
-                        /*long endTime2 = System.currentTimeMillis();
+                        long endTime2 = System.currentTimeMillis();
                         long executionTime2 = endTime2 - startTime2;
-                        System.out.println("2222222222222:" + executionTime2);*/
+                        System.out.println("recursiveGetParentNodes执行时间:" + executionTime2 + " ms");
 
                         //最底层节点颜色构造后Map
                         Map<Long, WbsTreeContractLazyVO> lowestNodesMap = lowestNodesTB.stream()
@@ -803,7 +813,7 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
                                     }
                                 }).collect(Collectors.toMap(WbsTreeContractLazyVO::getPKeyId, Function.identity()));
 
-                        //long startTime3 = System.currentTimeMillis();
+                        long startTime3 = System.currentTimeMillis();
                         //TODO 处理颜色
                         //先将WbsTreeContractLazyVO转为NodeVO
                         List<NodeVO> nodeVOList = distinctNodesAll.stream().map(this::convertToNodeVO).collect(Collectors.toList());
@@ -818,9 +828,9 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
                         //获取所有节点颜色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;
-                        System.out.println("3333333333333:" + executionTime3);*/
+                        long endTime3 = System.currentTimeMillis();
+                        long executionTime3 = endTime3 - startTime3;
+                        System.out.println("处理颜色执行时间:" + executionTime3 + " ms");
 
                         //TODO 处理最终结果集
                         if (lazyNodes.size() > 0) {
@@ -1049,7 +1059,8 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
     }
 
     @Override
-    public List<WbsTreeContractLazyVO> imageLazyQueryContractWbsTree(String id, String contractId, String contractIdRelation, String classId) {
+    public List<WbsTreeContractLazyVO> imageLazyQueryContractWbsTree(String id, String contractId, String
+            contractIdRelation, String classId) {
         if (ObjectUtil.isNotEmpty(contractId)) {
             ContractInfo contractInfo = jdbcTemplate.query("select contract_name,contract_type from m_contract_info where id = " + contractId, new BeanPropertyRowMapper<>(ContractInfo.class)).stream().findAny().orElse(null);
             if (contractInfo != null) {
@@ -1298,7 +1309,8 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
     }
 
     @Override
-    public List<AppWbsTreeContractVO> searchNodeAllTableAndFile(String primaryKeyId, String type, String contractId, String projectId) {
+    public List<AppWbsTreeContractVO> searchNodeAllTableAndFile(String primaryKeyId, String type, String
+            contractId, String projectId) {
         List<AppWbsTreeContractVO> vos = this.searchNodeAllTable(primaryKeyId, type, contractId, projectId);
         if (vos != null && vos.size() > 0) {
             List<Long> list = vos.stream().map(AppWbsTreeContractVO::getPKeyId).collect(Collectors.toList());
@@ -1383,7 +1395,8 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
      * @param initNode       初始化节点入参
      * @param contractId     合同段id
      */
-    private void getConcealedWorkParentNode(Set<WbsTreeContract> resultAllNodes, List<WbsTreeContract> initNode, String contractId) {
+    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));
@@ -1401,7 +1414,8 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
      * @param initNode       初始化节点入参
      * @param contractId     合同段id
      */
-    private void getConcealedWorkChildNode(Set<WbsTreeContract> resultAllNodes, List<WbsTreeContract> initNode, String contractId) {
+    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));
@@ -1439,43 +1453,31 @@ 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;
         }
 
         //父级Id与出现的次数Map
-        Map<Long, Long> parentIdGroup = lowestNodeParentIds.stream()
-                .collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
-
-        List<String> keysWithValueOne = new ArrayList<>();
-        Map<Long, Long> keysWithValueSome = new HashMap<>();
-
-        for (Map.Entry<Long, Long> entry : parentIdGroup.entrySet()) {
-            if (entry.getValue() == 1L) {
-                keysWithValueOne.add(entry.getKey().toString());
-            } else {
-                keysWithValueSome.put(entry.getKey(), entry.getValue());
-            }
-        }
+        Map<Long, Long> parentIdGroup = lowestNodeParentIds.parallelStream()
+                .collect(Collectors.groupingByConcurrent(Function.identity(), Collectors.counting()));
 
         //批量查询单次节点
-        List<WbsTreeContractLazyVO> parentNodes = new ArrayList<>();
-        if (keysWithValueOne.size() > 0) {
-            parentNodes = nodesAll.stream().filter(f -> keysWithValueOne.contains(f.getId().toString())).collect(Collectors.toList());
-        }
+        List<WbsTreeContractLazyVO> parentNodes = parentIdGroup.entrySet().parallelStream()
+                .filter(entry -> entry.getValue() == 1L)
+                .flatMap(entry -> nodesAll.parallelStream()
+                        .filter(f -> entry.getKey().equals(f.getId())))
+                .collect(Collectors.toList());
 
         //批量查询多次节点
-        List<WbsTreeContractLazyVO> multipleParentNodes = new ArrayList<>();
-        for (Map.Entry<Long, Long> entry : keysWithValueSome.entrySet()) {
-            Long key = entry.getKey();
-            Long count = entry.getValue();
-
-            List<WbsTreeContractLazyVO> nodes = nodesAll.stream().filter(f -> key.equals(f.getId())).collect(Collectors.toList());
-            if (!nodes.isEmpty()) {
-                multipleParentNodes.addAll(Collections.nCopies(count.intValue(), nodes.get(0)));
-            }
-        }
+        List<WbsTreeContractLazyVO> multipleParentNodes = 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).stream()))
+                .collect(Collectors.toList());
 
         //结果集
         List<Long> collect = Stream.concat(parentNodes.stream(), multipleParentNodes.stream())
@@ -1487,8 +1489,9 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
             result.addAll(multipleParentNodes);
             this.recursiveGetParentNodes(result, collect, 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;
         }
@@ -1538,7 +1541,7 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
             result.addAll(multipleParentNodes);
             this.recursiveGetParentNodes(result, collect, nodesAll);
         }
-    }
+    }*/
 
     @Override
     public boolean syncTabData(String pKeyId) throws Exception {
@@ -2525,13 +2528,15 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
      * @param distinctNodesAll 去重后所有节点数据
      * @return
      */
-    public List<NodeVO> buildNodeTreeByStream(List<WbsTreeContractLazyVO> distinctNodesAll, Map<Long, WbsTreeContractLazyVO> lowestNodesMap) {
+    public List<NodeVO> buildNodeTreeByStream
+    (List<WbsTreeContractLazyVO> distinctNodesAll, Map<Long, WbsTreeContractLazyVO> lowestNodesMap) {
         List<WbsTreeContractLazyVO> list = distinctNodesAll.stream().filter(f -> f.getParentId().equals(0L)).collect(Collectors.toList());
         Map<Long, List<WbsTreeContractLazyVO>> map = distinctNodesAll.stream().collect(Collectors.groupingBy(WbsTreeContractLazyVO::getParentId));
         return recursionFnNodeTree(list, map, lowestNodesMap);
     }
 
-    public List<NodeVO> recursionFnNodeTree(List<WbsTreeContractLazyVO> list, Map<Long, List<WbsTreeContractLazyVO>> map, Map<Long, WbsTreeContractLazyVO> lowestNodesMap) {
+    public List<NodeVO> recursionFnNodeTree
+            (List<WbsTreeContractLazyVO> list, Map<Long, List<WbsTreeContractLazyVO>> map, Map<Long, WbsTreeContractLazyVO> lowestNodesMap) {
         List<NodeVO> result = new ArrayList<>();
         for (WbsTreeContractLazyVO vo : list) {
             if (vo.getHasChildren().equals(0)) {
@@ -2675,5 +2680,8 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
         return list;
     }
 
-
+    /*删除合同段本地缓存*/
+    public void deleteContractLocalCache(String contractId) {
+        localCacheNodes.remove(contractId);
+    }
 }

+ 3 - 3
blade-service/blade-manager/src/main/resources/application-dev.yml

@@ -19,6 +19,6 @@ oss:
   bucket-name: bladex-test-info
 
 #Mybatis-plus配置
-mybatis-plus:
-  configuration:
-    cache-enabled: true #开启mybatis的二级缓存
+#mybatis-plus:
+#  configuration:
+#    cache-enabled: true