Browse Source

app影像资料bug

liuyc 2 years ago
parent
commit
7cba8121c5

+ 6 - 2
blade-service/blade-business/src/main/java/org/springblade/business/mapper/ImageClassificationFileMapper.xml

@@ -44,11 +44,15 @@
     </select>
 
     <select id="queryCurrentClassifyAllFileCount" resultType="java.lang.Integer">
-        select count(id) from u_image_classification_file where is_deleted = 0 and classify_id = #{classifyId} and
-        contract_id = #{contractId}
+        select count(id) from u_image_classification_file a
+        where is_deleted = 0
+          and status = 1
+          and classify_id = #{classifyId}
+          and contract_id = #{contractId}
         <if test="projectId != null and projectId != ''">
             and project_id = #{projectId}
         </if>
+            and a.wbs_id in (select p_key_id from m_wbs_tree_contract where is_deleted = 0 and status = 1 and contract_id = #{contractId})
     </select>
 
     <select id="selectShootingTimeByClassifyAndProjectId" resultType="java.util.Date">

+ 92 - 102
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/WbsTreeContractServiceImpl.java

@@ -1,6 +1,5 @@
 package org.springblade.manager.service.impl;
 
-import cn.hutool.core.swing.ScreenUtil;
 import cn.hutool.core.util.ObjectUtil;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
@@ -57,7 +56,6 @@ import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.math.BigInteger;
-import java.time.Year;
 import java.util.*;
 import java.util.function.Function;
 import java.util.regex.Matcher;
@@ -936,21 +934,13 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
                                         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));
+                        List<WbsTreeContractLazyFileVO> queryFileList = jdbcTemplate.query("select wbs_id,id from u_image_classification_file where status = 1 and is_deleted = 0 and contract_id = " + contractId + " and classify_id = " + classId, new BeanPropertyRowMapper<>(WbsTreeContractLazyFileVO.class));
                         //最底层节点与存储文件数量map
                         Map<Long, Integer> queryFileMaps = queryFileList.stream()
                                 .collect(Collectors.groupingBy(
@@ -959,27 +949,34 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
                                 ));
                         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);
+                        //填报过的所有最底层节点,处理数量
+                        List<WbsTreeContractLazyVO> lowestNodesTB = distinctLowestNodesAll.stream().filter(f -> pKeyIdList.contains(f.getPKeyId())).collect(Collectors.toList());
+                        List<WbsTreeContractLazyVO> lowestNodesTBNew = BeanUtil.copyProperties(lowestNodesTB, WbsTreeContractLazyVO.class);
+                        for (WbsTreeContractLazyVO vo : lowestNodesTB) {
+                            Integer fileCounts = queryFileMaps.get(vo.getPKeyId());
+                            if (fileCounts > 1) {
+                                /*当前节点下存在多个影像资料文件信息,那么就要添加进入集合中统一处理,
+                                在入参根据parentId分组时,就存在出现多个父级节点信息;
+                                此处要从1开始循环,因为不包含本身,如果从0,会多一条父级节点信息*/
+                                for (int i = 1; i < fileCounts; i++) {
+                                    lowestNodesTBNew.add(vo);
+                                }
+                            }
+                        }
+                        List<Long> lowestNodeParentIdsTB = lowestNodesTBNew.stream().map(WbsTreeContractLazyVO::getParentId).collect(Collectors.toList());
+                        List<WbsTreeContractLazyVO> resultParentNodesTB = new ArrayList<>();
+                        this.recursiveGetParentNodes(resultParentNodesTB, lowestNodeParentIdsTB, nodesAll);
 
                         //处理最终结果集
                         if (lazyNodes.size() > 0) {
                             Map<Long, Integer> countMap = new HashMap<>();
-                            for (WbsTreeContractLazyVO node : resultParentNodes) {
+                            for (WbsTreeContractLazyVO node : resultParentNodesTB) {
                                 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);
+                                if (countMap.containsKey(key)) {
+                                    countMap.put(key, countMap.get(key) + 1);
+                                } else {
+                                    countMap.put(key, 1);
                                 }
-                                countMap.put(key, totalCount);
                             }
 
                             //返回最终结果集
@@ -1041,14 +1038,6 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
                                                 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))),
@@ -1066,27 +1055,31 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
 
                                 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);
+                                //填报过的所有最底层节点,处理数量
+                                List<WbsTreeContractLazyVO> lowestNodesTB = distinctLowestNodesAll.stream().filter(f -> pKeyIdList.contains(f.getPKeyId())).collect(Collectors.toList());
+                                List<WbsTreeContractLazyVO> lowestNodesTBNew = BeanUtil.copyProperties(lowestNodesTB, WbsTreeContractLazyVO.class);
+                                for (WbsTreeContractLazyVO vo : lowestNodesTB) {
+                                    Integer fileCounts = queryFileMaps.get(vo.getPKeyId());
+                                    if (fileCounts > 1) {
+                                        for (int i = 1; i < fileCounts; i++) {
+                                            lowestNodesTBNew.add(vo);
+                                        }
+                                    }
+                                }
+                                List<Long> lowestNodeParentIdsTB = lowestNodesTBNew.stream().map(WbsTreeContractLazyVO::getParentId).collect(Collectors.toList());
+                                List<WbsTreeContractLazyVO> resultParentNodesTB = new ArrayList<>();
+                                this.recursiveGetParentNodes(resultParentNodesTB, lowestNodeParentIdsTB, nodesAll);
 
                                 //处理最终结果集
                                 if (lazyNodes.size() > 0) {
                                     Map<Long, Integer> countMap = new HashMap<>();
-                                    for (WbsTreeContractLazyVO node : resultParentNodes) {
+                                    for (WbsTreeContractLazyVO node : resultParentNodesTB) {
                                         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);
+                                        if (countMap.containsKey(key)) {
+                                            countMap.put(key, countMap.get(key) + 1);
+                                        } else {
+                                            countMap.put(key, 1);
                                         }
-                                        countMap.put(key, totalCount);
                                     }
 
                                     //返回最终结果集
@@ -1117,59 +1110,6 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
         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)) {
@@ -1382,6 +1322,56 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
         }
     }
 
+    public void recursiveGetParentNodes2(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());
+            }
+        }
+
+        //批量查询单次节点
+        List<WbsTreeContractLazyVO> parentNodes = new ArrayList<>();
+        if (keysWithValueOne.size() > 0) {
+            parentNodes = nodesAll.stream().filter(f -> keysWithValueOne.contains(f.getId().toString())).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<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);
+        }
+    }
+
     /**
      * 反向递归处理父节点颜色
      */