Browse Source

影像资料懒加载树数量统计等

liuyc 2 years ago
parent
commit
9d947d5c1b

+ 11 - 0
blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/vo/WbsTreeContractLazyFileVO.java

@@ -0,0 +1,11 @@
+package org.springblade.manager.vo;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+@Data
+public class WbsTreeContractLazyFileVO implements Serializable {
+    private Long wbsId;
+    private Long id;
+}

+ 1 - 0
blade-service/blade-business/src/main/java/org/springblade/business/mapper/ImageClassificationFileMapper.xml

@@ -76,6 +76,7 @@
         from
         (
         select
+        create_time,
         id,
         title,
         text_content,

+ 25 - 1
blade-service/blade-manager/src/main/java/org/springblade/manager/controller/WbsTreeContractController.java

@@ -171,7 +171,7 @@ public class WbsTreeContractController extends BladeController {
      */
     @GetMapping("/lazyQueryContractWbsTree")
     @ApiOperationSupport(order = 9)
-    @ApiOperation(value = "客户端懒加载获取合同段树(统计颜色、填报数量)", notes = "传入父级parentId、合同段contractId、关联contractIdRelation")
+    @ApiOperation(value = "客户端懒加载获取合同段树(统计颜色、填报数量)")
     @ApiImplicitParams(value = {
             @ApiImplicitParam(name = "primaryKeyId"),
             @ApiImplicitParam(name = "parentId", value = "父节点id,为空则查询第一级节点"),
@@ -204,6 +204,30 @@ public class WbsTreeContractController extends BladeController {
         return R.data(vos);
     }
 
+    /**
+     * 影像资料-懒加载获取影像资料合同段树(统计颜色、存储部位文件数量)
+     *
+     * @author liuyc
+     * @date 2023年8月24日14:21:03
+     */
+    @GetMapping("/image/lazyQueryContractWbsTree")
+    @ApiOperationSupport(order = 9)
+    @ApiOperation(value = "影像资料-懒加载获取影像资料合同段树(统计颜色、存储部位文件数量)")
+    @ApiImplicitParams(value = {
+            @ApiImplicitParam(name = "primaryKeyId"),
+            @ApiImplicitParam(name = "parentId", value = "父节点id,为空则查询第一级节点"),
+            @ApiImplicitParam(name = "contractId", value = "合同段id"),
+            @ApiImplicitParam(name = "contractIdRelation", value = "合同段关联id(监理、业主合同关联施工合同id)"),
+            @ApiImplicitParam(name = "classId", value = "分类id")
+    })
+    public R<List<WbsTreeContractLazyVO>> imageLazyQueryContractWbsTree(@RequestParam String primaryKeyId, @RequestParam String parentId, @RequestParam String contractId, @RequestParam String contractIdRelation, @RequestParam String classId) {
+        if (StringUtils.isNotEmpty(primaryKeyId)) {
+            parentId = primaryKeyId;
+        }
+        List<WbsTreeContractLazyVO> vos = iWbsTreeContractService.imageLazyQueryContractWbsTree(parentId, contractId, contractIdRelation,classId);
+        return R.data(vos);
+    }
+
     /**
      * 同步项目到合同段所有表单排序
      */

+ 3 - 0
blade-service/blade-manager/src/main/java/org/springblade/manager/service/IWbsTreeContractService.java

@@ -63,10 +63,13 @@ public interface IWbsTreeContractService extends BaseService<WbsTreeContract> {
 
     List<WbsTreeContractLazyVO> lazyQueryContractWbsTree(String id, String contractId, String contractIdRelation, String tableOwner);
 
+    List<WbsTreeContractLazyVO> imageLazyQueryContractWbsTree(String parentId, String contractId, String contractIdRelation, String classId);
+
     boolean syncContractTabSort(String projectId);
 
     List<AppWbsTreeContractVO> searchNodeAllTableAndFile(String primaryKeyId, String type, String contractId, String projectId);
 
     List<WbsTreeContractVO> getConcealedWorksNodeTree(String contractId);
 
+
 }

+ 263 - 0
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/WbsTreeContractServiceImpl.java

@@ -907,6 +907,269 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
         return null;
     }
 
+    @Override
+    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) {
+                //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 {
+                        nodesAll = jdbcTemplate.query("select a.p_key_id,a.id,a.parent_id,(SELECT CASE WHEN count(1) > 0 THEN 1 ELSE 0 END FROM m_wbs_tree_contract b WHERE b.parent_id = a.id AND type = 1 AND b.contract_id = " + contractId + " AND b.is_deleted = 0 ) AS hasChildren from m_wbs_tree_contract a where type = 1 and status = 1 and is_deleted = 0 and contract_id = " + contractId, new BeanPropertyRowMapper<>(WbsTreeContractLazyVO.class));
+                        if (nodesAll.size() > 0) {
+                            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,(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));
+                    if (lazyNodes.size() > 0 && nodesAll.size() > 0) {
+                        //所有节点
+                        List<WbsTreeContractLazyVO> distinctNodesAll = nodesAll.stream()
+                                .collect(Collectors.collectingAndThen(
+                                        Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(WbsTreeContractLazyVO::getPKeyId))),
+                                        ArrayList::new
+                                ));
+
+                        //所有节点parentId分组Map
+                        Map<Long, List<WbsTreeContractLazyVO>> parentIdToNodesMap = distinctNodesAll.stream()
+                                .collect(Collectors.groupingBy(WbsTreeContractLazyVO::getParentId));
+
+                        //所有节点id分组Map
+                        Map<Long, List<WbsTreeContractLazyVO>> idToNodesMap = distinctNodesAll.stream()
+                                .collect(Collectors.groupingBy(WbsTreeContractLazyVO::getId));
+
+                        //所有最底层节点
+                        List<WbsTreeContractLazyVO> distinctLowestNodesAll = distinctNodesAll.stream().filter(f -> f.getHasChildren().equals(0)).collect(Collectors.collectingAndThen(
+                                Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(WbsTreeContractLazyVO::getPKeyId))),
+                                ArrayList::new
+                        ));
+                        //获取当前合同段所有影像文件信息
+                        List<WbsTreeContractLazyFileVO> queryFileList = jdbcTemplate.query("select wbs_id,id from u_image_classification_file where status = 1 and contract_id = " + contractId + " and classify_id = " + classId, new BeanPropertyRowMapper<>(WbsTreeContractLazyFileVO.class));
+                        //最底层节点与存储文件数量map
+                        Map<Long, Integer> queryFileMaps = queryFileList.stream()
+                                .collect(Collectors.groupingBy(
+                                        WbsTreeContractLazyFileVO::getWbsId,
+                                        Collectors.collectingAndThen(Collectors.toList(), List::size)
+                                ));
+                        List<Long> pKeyIdList = new ArrayList<>(queryFileMaps.keySet());
+
+                        //所有最底层节点,处理文件数量
+                        List<WbsTreeContractLazyVO> lowestNodesFile = distinctLowestNodesAll.stream().filter(f -> pKeyIdList.contains(f.getPKeyId())).collect(Collectors.toList());
+                        Set<Long> lowestNodeParentIds = lowestNodesFile.stream().map(WbsTreeContractLazyVO::getParentId).collect(Collectors.toSet());
+
+                        //获取所有父级节点
+                        Set<WbsTreeContractLazyVO> resultParentNodes = new HashSet<>();
+                        this.getParentNodes(resultParentNodes, lowestNodeParentIds, idToNodesMap);
+
+                        //处理最终结果集
+                        if (lazyNodes.size() > 0) {
+                            Map<Long, Integer> countMap = new HashMap<>();
+                            for (WbsTreeContractLazyVO node : resultParentNodes) {
+                                Long key = node.getPKeyId();
+                                Set<WbsTreeContractLazyVO> resultNodes = new HashSet<>();
+                                //获取最底层节点的文件数量信息
+                                this.getDcNodes(resultNodes, Collections.singletonList(node), parentIdToNodesMap);
+                                int totalCount = 0;
+                                for (Long pKeyId : resultNodes.stream().map(WbsTreeContractLazyVO::getPKeyId).collect(Collectors.toSet())) {
+                                    totalCount += queryFileMaps.getOrDefault(pKeyId, 0);
+                                }
+                                countMap.put(key, totalCount);
+                            }
+
+                            //返回最终结果集
+                            for (WbsTreeContractLazyVO lazyNodeVO : lazyNodes) {
+                                lazyNodeVO.setType(lazyNodeVO.getNodeType());
+                                lazyNodeVO.setNotExsitChild(!lazyNodeVO.getHasChildren().equals(1));
+                                lazyNodeVO.setPrimaryKeyId(lazyNodeVO.getPKeyId());
+                                if (lazyNodeVO.getParentId() == 0L) {
+                                    if (ObjectUtil.isNotEmpty(contractInfo.getContractName())) {
+                                        lazyNodeVO.setTitle(contractInfo.getContractName());
+                                    }
+                                }
+                                lazyNodeVO.setSubmitCounts(ObjectUtil.isNotEmpty(countMap.get(lazyNodeVO.getPKeyId())) ? countMap.get(lazyNodeVO.getPKeyId()) : (ObjectUtil.isNotEmpty(queryFileMaps.get(lazyNodeVO.getPKeyId())) ? queryFileMaps.get(lazyNodeVO.getPKeyId()) : 0));
+                                if (lazyNodeVO.getSubmitCounts() >= 1) {
+                                    lazyNodeVO.setColorStatus(2);
+                                }
+                            }
+                        }
+                        return lazyNodes;
+                    }
+
+                    //TODO 监理、业主合同段
+                } else if (new Integer("2").equals(contractInfo.getContractType()) || new Integer("3").equals(contractInfo.getContractType())) {
+                    List<WbsTreeContractLazyVO> lazyNodesAll = new ArrayList<>();
+                    List<String> contractIds = new ArrayList<>();
+                    if (ObjectUtil.isNotEmpty(contractIdRelation) && ObjectUtil.isNotEmpty(id)) {
+                        //非根节点时选择加载施工合同段的树
+                        contractIds.add(contractIdRelation);
+                    } else {
+                        //根节点时默认加载所有施工合同段的树
+                        contractIds = this.contractClient.getProcessContractByJLContractId(contractId);
+                    }
+                    if (ObjectUtil.isEmpty(contractIds) || contractIds.size() <= 0) {
+                        return null;
+                    }
+                    for (String sgContractId : contractIds) {
+                        ContractInfo sgContractInfo = jdbcTemplate.query("select contract_name from m_contract_info where id = " + sgContractId, new BeanPropertyRowMapper<>(ContractInfo.class)).stream().findAny().orElse(null);
+                        if (sgContractInfo != null) {
+                            //获取当前合同段所有缓存节点信息
+                            List<WbsTreeContractLazyVO> nodesAll;
+                            Object data = redisTemplate.opsForValue().get("blade-manager::contract:wbstree:" + sgContractId);
+                            if (data != null) {
+                                nodesAll = JSON.parseArray(data.toString(), WbsTreeContractLazyVO.class);
+                            } else {
+                                nodesAll = jdbcTemplate.query("select a.p_key_id,a.id,a.parent_id,(SELECT CASE WHEN count(1) > 0 THEN 1 ELSE 0 END FROM m_wbs_tree_contract b WHERE b.parent_id = a.id AND type = 1 AND b.contract_id = " + sgContractId + " AND b.is_deleted = 0 ) AS hasChildren from m_wbs_tree_contract a where type = 1 and status = 1 and is_deleted = 0 and contract_id = " + sgContractId, new BeanPropertyRowMapper<>(WbsTreeContractLazyVO.class));
+                                if (nodesAll.size() > 0) {
+                                    JSONArray array = JSONArray.parseArray(JSON.toJSONString(nodesAll));
+                                    redisTemplate.opsForValue().set("blade-manager::contract:wbstree:" + sgContractId, JSON.toJSON(array).toString());
+                                }
+                            }
+
+                            //获取当前层懒加载节点
+                            List<WbsTreeContractLazyVO> lazyNodes = jdbcTemplate.query("select p_key_id,(SELECT id FROM u_contract_tree_drawings where process_id = p_key_id) AS drawingsId,id,parent_id,node_type,type,wbs_type,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 = " + sgContractId + " 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 = " + sgContractId + " ORDER BY a.sort,title,a.create_time", new BeanPropertyRowMapper<>(WbsTreeContractLazyVO.class));
+                            if (lazyNodes.size() > 0 && nodesAll.size() > 0) {
+                                //所有节点
+                                List<WbsTreeContractLazyVO> distinctNodesAll = nodesAll.stream()
+                                        .collect(Collectors.collectingAndThen(
+                                                Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(WbsTreeContractLazyVO::getPKeyId))),
+                                                ArrayList::new
+                                        ));
+
+                                //所有节点parentId分组Map
+                                Map<Long, List<WbsTreeContractLazyVO>> parentIdToNodesMap = distinctNodesAll.stream()
+                                        .collect(Collectors.groupingBy(WbsTreeContractLazyVO::getParentId));
+
+                                //所有节点id分组Map
+                                Map<Long, List<WbsTreeContractLazyVO>> idToNodesMap = distinctNodesAll.stream()
+                                        .collect(Collectors.groupingBy(WbsTreeContractLazyVO::getId));
+
+                                //所有最底层节点
+                                List<WbsTreeContractLazyVO> distinctLowestNodesAll = distinctNodesAll.stream().filter(f -> f.getHasChildren().equals(0)).collect(Collectors.collectingAndThen(
+                                        Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(WbsTreeContractLazyVO::getPKeyId))),
+                                        ArrayList::new
+                                ));
+
+                                //获取当前合同段所有影像文件信息(只查看监理自己的,资料填报是查看的施工合同段的,这里有区别)
+                                List<WbsTreeContractLazyFileVO> queryFileList = jdbcTemplate.query("select wbs_id,id from u_image_classification_file where status = 1 and contract_id = " + contractId + " and classify_id = " + classId, new BeanPropertyRowMapper<>(WbsTreeContractLazyFileVO.class));
+                                //最底层节点与存储文件数量map
+                                Map<Long, Integer> queryFileMaps = queryFileList.stream()
+                                        .collect(Collectors.groupingBy(
+                                                WbsTreeContractLazyFileVO::getWbsId,
+                                                Collectors.collectingAndThen(Collectors.toList(), List::size)
+                                        ));
+
+                                List<Long> pKeyIdList = new ArrayList<>(queryFileMaps.keySet());
+
+                                //所有最底层节点,处理文件数量
+                                List<WbsTreeContractLazyVO> lowestNodesFile = distinctLowestNodesAll.stream().filter(f -> pKeyIdList.contains(f.getPKeyId())).collect(Collectors.toList());
+                                Set<Long> lowestNodeParentIds = lowestNodesFile.stream().map(WbsTreeContractLazyVO::getParentId).collect(Collectors.toSet());
+
+                                //获取所有父级节点
+                                Set<WbsTreeContractLazyVO> resultParentNodes = new HashSet<>();
+                                this.getParentNodes(resultParentNodes, lowestNodeParentIds, idToNodesMap);
+
+                                //处理最终结果集
+                                if (lazyNodes.size() > 0) {
+                                    Map<Long, Integer> countMap = new HashMap<>();
+                                    for (WbsTreeContractLazyVO node : resultParentNodes) {
+                                        Long key = node.getPKeyId();
+                                        Set<WbsTreeContractLazyVO> resultNodes = new HashSet<>();
+                                        //获取最底层节点的文件数量信息
+                                        this.getDcNodes(resultNodes, Collections.singletonList(node), parentIdToNodesMap);
+                                        int totalCount = 0;
+                                        for (Long pKeyId : resultNodes.stream().map(WbsTreeContractLazyVO::getPKeyId).collect(Collectors.toSet())) {
+                                            totalCount += queryFileMaps.getOrDefault(pKeyId, 0);
+                                        }
+                                        countMap.put(key, totalCount);
+                                    }
+
+                                    //返回最终结果集
+                                    for (WbsTreeContractLazyVO lazyNodeVO : lazyNodes) {
+                                        lazyNodeVO.setType(lazyNodeVO.getNodeType()); //前端显示需要一样的,所以修改成一样的
+                                        lazyNodeVO.setNotExsitChild(!lazyNodeVO.getHasChildren().equals(1));
+                                        lazyNodeVO.setPrimaryKeyId(lazyNodeVO.getPKeyId());
+                                        lazyNodeVO.setContractIdRelation(sgContractId);
+                                        if (lazyNodeVO.getParentId() == 0L) {
+                                            if (ObjectUtil.isNotEmpty(sgContractInfo.getContractName())) {
+                                                lazyNodeVO.setTitle(sgContractInfo.getContractName());
+                                            }
+                                        }
+                                        lazyNodeVO.setSubmitCounts(ObjectUtil.isNotEmpty(countMap.get(lazyNodeVO.getPKeyId())) ? countMap.get(lazyNodeVO.getPKeyId()) : (ObjectUtil.isNotEmpty(queryFileMaps.get(lazyNodeVO.getPKeyId())) ? queryFileMaps.get(lazyNodeVO.getPKeyId()) : 0));
+                                        if (lazyNodeVO.getSubmitCounts() >= 1) {
+                                            lazyNodeVO.setColorStatus(2);
+                                        }
+                                    }
+                                }
+                                lazyNodesAll.addAll(lazyNodes);
+                            }
+                        }
+                    }
+                    return lazyNodesAll;
+                }
+            }
+        }
+        return null;
+    }
+
+    /**
+     * 获取所有父级节点
+     *
+     * @param resultParentNodes
+     * @param parentIds
+     * @param idToNodesMap
+     */
+    private void getParentNodes(Set<WbsTreeContractLazyVO> resultParentNodes, Set<Long> parentIds, Map<Long, List<WbsTreeContractLazyVO>> idToNodesMap) {
+        if (parentIds.size() > 0 && !parentIds.contains(0L)) {
+            Set<Long> parentIdsAll = new HashSet<>();
+            for (Long parentId : parentIds) {
+                List<WbsTreeContractLazyVO> parentNodes = idToNodesMap.get(parentId);
+                if (parentNodes.size() > 0) {
+                    resultParentNodes.addAll(parentNodes);
+                    Set<Long> parentIdsFu = parentNodes.stream().map(WbsTreeContractLazyVO::getParentId).collect(Collectors.toSet());
+                    if (parentIdsFu.size() > 0) {
+                        parentIdsAll.addAll(parentIdsFu);
+                    }
+                }
+            }
+            if (parentIdsAll.size() > 0) {
+                this.getParentNodes(resultParentNodes, parentIdsAll, idToNodesMap);
+            }
+        }
+    }
+
+    /**
+     * 递归获取所有最底层节点
+     */
+    private void getDcNodes(Set<WbsTreeContractLazyVO> resultNodes, List<WbsTreeContractLazyVO> initNode, Map<Long, List<WbsTreeContractLazyVO>> parentIdToNodeAllMap) {
+        Set<Long> childIds = initNode.stream().map(WbsTreeContractLazyVO::getId).collect(Collectors.toSet());
+        if (childIds.size() > 0) {
+            List<WbsTreeContractLazyVO> dcNodeAll = new ArrayList<>();
+            for (Long childId : childIds) {
+                //所有子级
+                List<WbsTreeContractLazyVO> childNodes = parentIdToNodeAllMap.get(childId);
+                //最底层节点,返回结果
+                List<WbsTreeContractLazyVO> dcNode = childNodes.stream().filter(f -> f.getHasChildren() == 0).collect(Collectors.toList());
+                if (dcNode.size() > 0) {
+                    resultNodes.addAll(dcNode);
+                }
+                //非最底层节点,进入下次递归循环
+                List<WbsTreeContractLazyVO> noDcNode = childNodes.stream().filter(f -> f.getHasChildren() == 1).collect(Collectors.toList());
+                if (noDcNode.size() > 0) {
+                    dcNodeAll.addAll(noDcNode);
+                }
+            }
+            if (dcNodeAll.size() > 0) {
+                this.getDcNodes(resultNodes, dcNodeAll, parentIdToNodeAllMap);
+            }
+        }
+    }
+
     @Override
     public boolean syncContractTabSort(String projectId) {
         if (ObjectUtil.isNotEmpty(projectId)) {