lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/utils/TreeBuilder.java
@@ -1,10 +1,14 @@
package org.jeecg.modules.dnc.utils;
import it.unimi.dsi.fastutil.longs.*;
import it.unimi.dsi.fastutil.longs.Long2IntMap;
import it.unimi.dsi.fastutil.longs.Long2IntOpenHashMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
import org.jeecg.modules.dnc.entity.ProductMix;
import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.stream.Collectors;
public class TreeBuilder {
@@ -46,19 +50,19 @@
        // 1. 构建邻接表(父节点 -> 子节点列表)
        Long2ObjectMap<List<Long>> adjacencyList = new Long2ObjectOpenHashMap<>(nodes.size());
        nodes.forEach(node -> {
            long parentId = node.getParentId();
            Long parentId = node.getParentId();
            adjacencyList.computeIfAbsent(parentId, k -> new ArrayList<>())
                    .add(node.getId());
        });
        // 2. 初始化入度计数器
        Long2IntMap inDegree = new Long2IntOpenHashMap();
        nodes.forEach(node -> inDegree.put(node.getId(), 0));
        nodes.forEach(node -> inDegree.put(node.getId().longValue(), 0));
        // 3. 计算入度
        nodes.forEach(node -> {
            if (node.getParentId() != 0 && nodeMap.containsKey(node.getParentId())) {
                inDegree.put(node.getId(), inDegree.get(node.getId()) + 1);
                inDegree.put(node.getId().longValue(), inDegree.get(node.getId()) + 1);
            }
        });
@@ -178,4 +182,4 @@
        public Long2ObjectMap<ProductMix> getNodeMap() { return nodeMap; }
        public List<ProductMix> getValidNodes() { return validNodes; }
    }
}
}