|
@@ -3,10 +3,7 @@ package org.springblade.system.user.bean;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import lombok.Data;
|
|
|
|
|
|
-import java.util.LinkedList;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Queue;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -154,6 +151,62 @@ public class NodeVO {
|
|
|
node.setStatus(2);
|
|
|
}
|
|
|
|
|
|
+ public static void calculateStatusToDFS1(List<NodeVO> nodeList, Map<Long, Integer> nodeColorStatusMap) {
|
|
|
+ NodeVO rootNode = findRootNode(nodeList);
|
|
|
+ if (rootNode != null) {
|
|
|
+ calculateNodeStatusToDFS1(rootNode, nodeColorStatusMap);
|
|
|
+ nodeColorStatusMap.put(rootNode.getPKeyId(), rootNode.getStatus());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ public static void calculateNodeStatusToDFS1(NodeVO node, Map<Long, Integer> nodeColorStatusMap) {
|
|
|
+ //最底层节点直接返回
|
|
|
+ if (ObjectUtil.isEmpty(node.getChildren())) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //递归处理子节点
|
|
|
+ for (NodeVO child : node.getChildren()) {
|
|
|
+ calculateNodeStatusToDFS1(child, nodeColorStatusMap);
|
|
|
+ nodeColorStatusMap.put(child.getPKeyId(), child.getStatus());
|
|
|
+ }
|
|
|
+ //判断子级
|
|
|
+ Set<Integer> childStatusList = node.getChildren().stream().map(NodeVO::getStatus).collect(Collectors.toSet());
|
|
|
+ //如果子节点都是相同的状态,则父节点状态也为该状态
|
|
|
+ if (childStatusList.size() == 1) {
|
|
|
+ node.setStatus(childStatusList.iterator().next());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //判断是否存在同时只存在1、3的情况
|
|
|
+ if (childStatusList.contains(1) && childStatusList.contains(3) && !childStatusList.contains(2)) {
|
|
|
+ node.setStatus(2);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //判断是否存在同时只存在3、4的情况
|
|
|
+ if (childStatusList.contains(3) && childStatusList.contains(4) && !childStatusList.contains(1) && !childStatusList.contains(2)) {
|
|
|
+ node.setStatus(3);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //判断是否存在只有1但不全是1的情况
|
|
|
+ if (childStatusList.contains(1) && !childStatusList.contains(2) && !childStatusList.contains(3) && !childStatusList.contains(4)) {
|
|
|
+ node.setStatus(2);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ //判断是否存在只有2但不全是2的情况
|
|
|
+ if (childStatusList.contains(2) && !childStatusList.contains(1) && !childStatusList.contains(3) && !childStatusList.contains(4)) {
|
|
|
+ node.setStatus(2);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ //判断是否存在只有3但不全是3的情况
|
|
|
+ if (childStatusList.contains(3) && !childStatusList.contains(1) && !childStatusList.contains(2) && !childStatusList.contains(4)) {
|
|
|
+ node.setStatus(3);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ //其他情况,父节点状态默认为2
|
|
|
+ node.setStatus(2);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* BFS
|
|
|
*
|