package com.ycl.utils; import com.ycl.domain.vo.ProjectEngineeringVO; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** * 构建树工具 * * @author:xp * @date:2025/3/3 2:37 */ public class TreeUtil { /** * 为工程构造树 * * @param nodes * @return */ public static List treeForProjectEng(List nodes) { Map nodeMap = new HashMap<>(); for (ProjectEngineeringVO node : nodes) { nodeMap.put(node.getId(), node); } List roots = new ArrayList<>(); for (ProjectEngineeringVO node : nodes) { if ("0".equals(node.getParent())) { roots.add(node); } else { ProjectEngineeringVO parentNode = nodeMap.get(node.getParent()); if (parentNode != null) { parentNode.getChildren().add(node); } } } return roots; } }