package com.dcit.danger.dto.node;

import java.util.ArrayList;
import java.util.List;


public class BuildCodeTreeNode {
	
	public static List<SysCodeTreeNode> buildTree(List<SysCodeTreeNode> treeNodeList){
		if(treeNodeList == null || treeNodeList.size() == 0){
            return null;
        }
        List<SysCodeTreeNode> topNodes = new ArrayList<SysCodeTreeNode>();
 
        for (SysCodeTreeNode children : treeNodeList) {
 
            String pid = children.getParentId();
            if (pid == null || "".equals(pid) || pid.equals("0")) {
                topNodes.add(children);
 
                continue;
            }
 
            for (SysCodeTreeNode parent : treeNodeList) {
                String id = parent.getId();
                if (id != null && id.equals(pid)) {
                    parent.getChildList().add(children);
                    continue;
                }
            }
 
        }
 
        /*DeptTreeNode root = new DeptTreeNode();
        if (topNodes.size() == 1) {
            root = topNodes.get(0);
        } else {
        	root.setId("-1");
            root.setParentId("");
            root.setParentIds("");
            root.setChildList(topNodes);
            root.setFullName("顶级节点");
            root.setShortName("顶级节点");
        }*/
 
        return topNodes;
	}

}
