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<ProjectEngineeringVO> treeForProjectEng(List<ProjectEngineeringVO> nodes) {
|
Map<String, ProjectEngineeringVO> nodeMap = new HashMap<>();
|
for (ProjectEngineeringVO node : nodes) {
|
nodeMap.put(node.getId(), node);
|
}
|
List<ProjectEngineeringVO> 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;
|
}
|
|
}
|