Bladeren bron

合同段树搜索接口颜色问题

liuyc 1 jaar geleden
bovenliggende
commit
cafca93615

+ 71 - 125
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/ContractInfoServiceImpl.java

@@ -22,6 +22,7 @@ import org.springblade.core.tool.api.R;
 import org.springblade.core.tool.node.ForestNodeMerger;
 import org.springblade.core.tool.utils.BeanUtil;
 import org.springblade.core.tool.utils.ObjectUtil;
+import org.springblade.manager.bean.NodeVO;
 import org.springblade.manager.dto.FindAllUserByConditionDTO;
 import org.springblade.manager.dto.SaveUserInfoByProjectDTO;
 import org.springblade.manager.entity.*;
@@ -394,7 +395,8 @@ public class ContractInfoServiceImpl extends BaseServiceImpl<ContractInfoMapper,
                         Map<Long, Integer> informationQueryMaps = informationQueryList.stream().collect(Collectors.toMap(InformationQuery::getWbsId, InformationQuery::getStatus, (v1, v2) -> v1));
                         List<Long> pKeyIdList = new ArrayList<>(informationQueryMaps.keySet());
 
-                        //填报过的所有最底层节点(并且是查询有效节点的最下级节点)处理数量
+                        //TODO 处理数量
+                        //填报过的所有最底层节点
                         List<WbsTreeContractLazyVO> lowestNodesTB = distinctLowestNodesAll.stream().filter(f -> pKeyIdList.contains(f.getPKeyId()) && resultNodesPKeyIds.contains(f.getPKeyId())).collect(Collectors.toList());
                         List<Long> lowestNodeParentIdsTB = lowestNodesTB.stream().map(WbsTreeContractLazyVO::getParentId).collect(Collectors.toList());
                         List<WbsTreeContractLazyVO> resultParentNodesTB = new ArrayList<>();
@@ -413,6 +415,20 @@ public class ContractInfoServiceImpl extends BaseServiceImpl<ContractInfoMapper,
                                     }
                                 }).collect(Collectors.toMap(WbsTreeContractLazyVO::getPKeyId, Function.identity()));
 
+                        //TODO 处理颜色
+                        //先将WbsTreeContractLazyVO转为NodeVO
+                        List<NodeVO> nodeVOList = distinctNodesAll.stream().map(wbsTreeContractServiceImpl::convertToNodeVO).collect(Collectors.toList());
+                        //转为Map<Long, NodeVO>
+                        Map<Long, NodeVO> nodeVOMap = nodeVOList.stream().collect(Collectors.toMap(NodeVO::getId, vo -> vo, (existing, replacement) -> existing));
+                        //把distinctNodesAll把所有节点转为树形结构,再转为List<NodeVO>对象
+                        List<NodeVO> treeNodeVOList = wbsTreeContractServiceImpl.buildNodeTreeByStream(distinctNodesAll, lowestNodesMap);
+                        //处理节点颜色
+                        NodeVO.calculateStatusToDFS(treeNodeVOList, nodeVOMap);
+                        //把树形结构转为普通List集合
+                        List<NodeVO> nodeVOS = wbsTreeContractServiceImpl.flattenTree(treeNodeVOList);
+                        //获取所有节点颜色Map
+                        Map<Long, Integer> nodeColorStatusMap = nodeVOS.stream().collect(Collectors.toMap(NodeVO::getPKeyId, NodeVO::getStatus, (existing, replacement) -> existing));
+
                         //构造vo
                         if (wbsTreeContractList.size() > 0) {
                             //处理填报数量
@@ -425,24 +441,31 @@ public class ContractInfoServiceImpl extends BaseServiceImpl<ContractInfoMapper,
                                     countMap.put(key, 1L);
                                 }
                             }
-                            List<WbsTreeContractTreeAllVO> wbsTreeContractTreeAllVOS = wbsTreeContractList.stream().map(node -> {
-                                WbsTreeContractTreeAllVO vo = BeanUtil.copyProperties(node, WbsTreeContractTreeAllVO.class);
-                                if (vo != null) {
-                                    vo.setContractIdRelation(node.getContractId());
-                                    vo.setType(ObjectUtils.isNotEmpty(node.getNodeType()) ? node.getNodeType() : 0);
-                                    vo.setTitle(ObjectUtil.isNotEmpty(node.getFullName()) ? node.getFullName() : node.getNodeName());
-                                    vo.setPrimaryKeyId(node.getPKeyId());
-                                    vo.setSubmitCounts(ObjectUtil.isNotEmpty(countMap.get(vo.getPrimaryKeyId())) ? countMap.get(vo.getPrimaryKeyId()) : (ObjectUtil.isNotEmpty(informationQueryMaps.get(vo.getPrimaryKeyId())) ? 1L : 0L));
-                                    if (vo.getSubmitCounts() >= 1L) {
-                                        vo.setColorStatus(2);
-                                    }
-                                    WbsTreeContractLazyVO lowestNode = lowestNodesMap.get(vo.getPrimaryKeyId());
-                                    if (lowestNode != null) {
-                                        vo.setColorStatus(lowestNode.getColorStatus());
-                                    }
-                                }
-                                return vo;
-                            }).collect(Collectors.toList());
+                            List<WbsTreeContractTreeAllVO> wbsTreeContractTreeAllVOS = wbsTreeContractList.stream()
+                                    .map(node -> {
+                                        WbsTreeContractTreeAllVO vo = BeanUtil.copyProperties(node, WbsTreeContractTreeAllVO.class);
+                                        if (vo != null) {
+                                            vo.setContractIdRelation(node.getContractId());
+                                            vo.setType(ObjectUtils.isNotEmpty(node.getNodeType()) ? node.getNodeType() : 0);
+                                            vo.setTitle(ObjectUtil.isNotEmpty(node.getFullName()) ? node.getFullName() : node.getNodeName());
+                                            vo.setPrimaryKeyId(node.getPKeyId());
+
+                                            //设置数量
+                                            vo.setSubmitCounts(ObjectUtil.isNotEmpty(countMap.get(vo.getPrimaryKeyId())) ? countMap.get(vo.getPrimaryKeyId()) : (ObjectUtil.isNotEmpty(informationQueryMaps.get(vo.getPrimaryKeyId())) ? 1L : 0L));
+
+                                            //设置颜色
+                                            Integer parentColorStatus = nodeColorStatusMap.get(vo.getPrimaryKeyId());
+                                            if (parentColorStatus != null) {
+                                                vo.setColorStatus(parentColorStatus);
+                                            } else {
+                                                WbsTreeContractLazyVO lowestNode = lowestNodesMap.get(vo.getPrimaryKeyId());
+                                                if (lowestNode != null) {
+                                                    vo.setColorStatus(lowestNode.getColorStatus());
+                                                }
+                                            }
+                                        }
+                                        return vo;
+                                    }).collect(Collectors.toList());
                             return R.data(this.buildWbsTreeByStreamByTreeAll(wbsTreeContractTreeAllVOS));
                         }
                     }
@@ -514,6 +537,13 @@ public class ContractInfoServiceImpl extends BaseServiceImpl<ContractInfoMapper,
                                         }
                                     }).collect(Collectors.toMap(WbsTreeContractLazyVO::getPKeyId, Function.identity()));
 
+                            List<NodeVO> nodeVOList = distinctNodesAll.stream().map(wbsTreeContractServiceImpl::convertToNodeVO).collect(Collectors.toList());
+                            Map<Long, NodeVO> nodeVOMap = nodeVOList.stream().collect(Collectors.toMap(NodeVO::getId, vo -> vo, (existing, replacement) -> existing));
+                            List<NodeVO> treeNodeVOList = wbsTreeContractServiceImpl.buildNodeTreeByStream(distinctNodesAll, lowestNodesMap);
+                            NodeVO.calculateStatusToDFS(treeNodeVOList, nodeVOMap);
+                            List<NodeVO> nodeVOS = wbsTreeContractServiceImpl.flattenTree(treeNodeVOList);
+                            Map<Long, Integer> nodeColorStatusMap = nodeVOS.stream().collect(Collectors.toMap(NodeVO::getPKeyId, NodeVO::getStatus, (existing, replacement) -> existing));
+
                             if (wbsTreeContractList.size() > 0) {
                                 Map<Long, Long> countMap = new HashMap<>();
                                 for (WbsTreeContractLazyVO node : resultParentNodesTB) {
@@ -524,24 +554,28 @@ public class ContractInfoServiceImpl extends BaseServiceImpl<ContractInfoMapper,
                                         countMap.put(key, 1L);
                                     }
                                 }
-                                List<WbsTreeContractTreeAllVO> wbsTreeContractTreeAllVOS = wbsTreeContractList.stream().map(node -> {
-                                    WbsTreeContractTreeAllVO vo = BeanUtil.copyProperties(node, WbsTreeContractTreeAllVO.class);
-                                    if (vo != null) {
-                                        vo.setContractIdRelation(node.getContractId());
-                                        vo.setType(ObjectUtils.isNotEmpty(node.getNodeType()) ? node.getNodeType() : 0);
-                                        vo.setTitle(ObjectUtil.isNotEmpty(node.getFullName()) ? node.getFullName() : node.getNodeName());
-                                        vo.setPrimaryKeyId(node.getPKeyId());
-                                        vo.setSubmitCounts(ObjectUtil.isNotEmpty(countMap.get(vo.getPrimaryKeyId())) ? countMap.get(vo.getPrimaryKeyId()) : (ObjectUtil.isNotEmpty(informationQueryMaps.get(vo.getPrimaryKeyId())) ? 1L : 0L));
-                                        if (vo.getSubmitCounts() >= 1L) {
-                                            vo.setColorStatus(2);
-                                        }
-                                        WbsTreeContractLazyVO lowestNode = lowestNodesMap.get(vo.getPrimaryKeyId());
-                                        if (lowestNode != null) {
-                                            vo.setColorStatus(lowestNode.getColorStatus());
-                                        }
-                                    }
-                                    return vo;
-                                }).collect(Collectors.toList());
+                                List<WbsTreeContractTreeAllVO> wbsTreeContractTreeAllVOS = wbsTreeContractList.stream()
+                                        .map(node -> {
+                                            WbsTreeContractTreeAllVO vo = BeanUtil.copyProperties(node, WbsTreeContractTreeAllVO.class);
+                                            if (vo != null) {
+                                                vo.setContractIdRelation(node.getContractId());
+                                                vo.setType(ObjectUtils.isNotEmpty(node.getNodeType()) ? node.getNodeType() : 0);
+                                                vo.setTitle(ObjectUtil.isNotEmpty(node.getFullName()) ? node.getFullName() : node.getNodeName());
+                                                vo.setPrimaryKeyId(node.getPKeyId());
+                                                vo.setSubmitCounts(ObjectUtil.isNotEmpty(countMap.get(vo.getPrimaryKeyId())) ? countMap.get(vo.getPrimaryKeyId()) : (ObjectUtil.isNotEmpty(informationQueryMaps.get(vo.getPrimaryKeyId())) ? 1L : 0L));
+
+                                                Integer parentColorStatus = nodeColorStatusMap.get(vo.getPrimaryKeyId());
+                                                if (parentColorStatus != null) {
+                                                    vo.setColorStatus(parentColorStatus);
+                                                } else {
+                                                    WbsTreeContractLazyVO lowestNode = lowestNodesMap.get(vo.getPrimaryKeyId());
+                                                    if (lowestNode != null) {
+                                                        vo.setColorStatus(lowestNode.getColorStatus());
+                                                    }
+                                                }
+                                            }
+                                            return vo;
+                                        }).collect(Collectors.toList());
                                 resultMaps.put(contractRelationJlyz.getContractIdSg(), this.buildWbsTreeByStreamByTreeAll(wbsTreeContractTreeAllVOS));
                             }
                         }
@@ -553,94 +587,6 @@ public class ContractInfoServiceImpl extends BaseServiceImpl<ContractInfoMapper,
         return null;
     }
 
-    /**
-     * 处理submitCounts计数、colorStatus颜色问题
-     *
-     * @param reNodes 数据源
-     */
-    private void reSetSubmitCountsAndColorStatus(List<WbsTreeContractTreeAllVO> reNodes) {
-        //反向for循环解决顺序问题,最底层节点才是数据源
-        for (int i = reNodes.size() - 1; i >= 0; i--) {
-            WbsTreeContractTreeAllVO node = reNodes.get(i);
-            if (node.getChildren() != null && !node.getChildren().isEmpty()) {
-                //计数
-                long childSubmitCounts = 0L;
-                for (WbsTreeContractTreeAllVO child : node.getChildren()) {
-                    if (child.getSubmitCounts() == 1L) {
-                        childSubmitCounts++;
-                    } else if (child.getSubmitCounts() > 1L) {
-                        childSubmitCounts = child.getSubmitCounts();
-                    }
-                }
-                node.setSubmitCounts(childSubmitCounts);
-
-                //颜色
-                boolean allThree = true; //是否所有子节点的getColorStatus都等于3
-                boolean allFour = true; //是否所有子节点的getColorStatus都等于4
-                boolean hasTwo = false; //是否存在子节点的getColorStatus等于2
-                boolean hasOne = false; //是否存在子节点的getColorStatus等于1
-                boolean hasThreeOrFour = false; //是否存在子节点的getColorStatus等于3或4
-                for (WbsTreeContractTreeAllVO child : node.getChildren()) {
-                    if (child.getColorStatus() != 3) {
-                        allThree = false;
-                    }
-                    if (child.getColorStatus() != 4) {
-                        allFour = false;
-                    }
-                    if (child.getColorStatus() == 2) {
-                        hasTwo = true;
-                    }
-                    if (child.getColorStatus() == 1) {
-                        hasOne = true;
-                    }
-                    if (child.getColorStatus() == 3 || child.getColorStatus() == 4) {
-                        hasThreeOrFour = true;
-                    }
-                }
-                if (allThree) {
-                    node.setColorStatus(3);
-                } else if (allFour) {
-                    node.setColorStatus(4);
-                } else if (hasTwo || (hasOne && hasThreeOrFour)) {
-                    node.setColorStatus(2);
-                } else {
-                    node.setColorStatus(1);
-                }
-
-            } else if (node.getSubmitCounts() == 1L) {
-                node.setSubmitCounts(1L);
-                //最底层节点颜色
-                if (ObjectUtils.isNotEmpty(node.getColorStatus())) {
-                    if (node.getColorStatus().equals(0)) { //任务状态=0,未上报
-                        node.setColorStatus(2); //蓝色
-                    } else if (node.getColorStatus().equals(1)) { //任务状态=1,待审批
-                        node.setColorStatus(3); //橙色
-                    } else if (node.getColorStatus().equals(2)) { //任务状态=2,已审批
-                        node.setColorStatus(4); //绿色
-                    }
-                }
-            } else if (node.getSubmitCounts() == 0L && ObjectUtils.isEmpty(node.getColorStatus())) {
-                node.setColorStatus(1); //黑色 //任务状态=null,未填报
-            }
-        }
-    }
-
-
-    /**
-     * 获取构造完的List集合
-     *
-     * @param reNodes 数据源
-     * @param result  结果集
-     */
-    private void getNodesAll(List<WbsTreeContractTreeAllVO> reNodes, LinkedList<WbsTreeContractTreeAllVO> result) {
-        for (WbsTreeContractTreeAllVO node : reNodes) {
-            if (node.getChildren() != null && !node.getChildren().isEmpty()) {
-                result.addAll(node.getChildren());
-                this.getNodesAll(node.getChildren(), result);
-            }
-        }
-    }
-
     /**
      * 反向递归获取父级
      *

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

@@ -2326,13 +2326,13 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
      * @param distinctNodesAll 去重后所有节点数据
      * @return
      */
-    private 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);
     }
 
-    private 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)) {
@@ -2357,7 +2357,7 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
     }
 
     //转换VO
-    private NodeVO convertToNodeVO(WbsTreeContractLazyVO wbsTreeContractLazyVO) {
+    public NodeVO convertToNodeVO(WbsTreeContractLazyVO wbsTreeContractLazyVO) {
         NodeVO nodeVO = new NodeVO();
         nodeVO.setId(wbsTreeContractLazyVO.getId());
         nodeVO.setParentId(wbsTreeContractLazyVO.getParentId());
@@ -2367,7 +2367,7 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
     }
 
     //把树形结构转为普通List
-    private List<NodeVO> flattenTree(List<NodeVO> tree) {
+    public List<NodeVO> flattenTree(List<NodeVO> tree) {
         List<NodeVO> result = new ArrayList<>();
         for (NodeVO node : tree) {
             result.add(node);