lyh
2025-01-13 137d008bd9b7d932160436a3a560b24512f6d1db
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package org.jeecg.modules.dnc.service.support;
 
 
import org.jeecg.modules.dnc.dto.DepartmentExt;
import org.jeecg.modules.dnc.response.CommonJsonTree;
 
import java.util.ArrayList;
import java.util.List;
 
public class DepartmentTreeWrapper {
    public static List<CommonJsonTree> loadTree(List<DepartmentExt> componentInfoList) {
        List<CommonJsonTree> tree = new ArrayList<CommonJsonTree>();// TreeNode集合,存放所有树对象。
        CommonJsonTree node;
        for(DepartmentExt ext : componentInfoList) {
            node = new CommonJsonTree();
            node.setId(ext.getDepartId());
            node.setLabel(ext.getDepartName());
            node.setParentId(null);
            //设置菜单节点图标 Start
            String iconStr = "";
            /*判断是否设置了菜单导航图标样式*/
            if (!ext.hasChild()) {//导航页面的菜单节点
                iconStr = "";//默认图标
            }
            node.setIconClass(iconStr);
            node = loadChildrenNodes(ext, node);
            tree.add(node);
        }
        return tree;
    }
 
    private static CommonJsonTree loadChildrenNodes(DepartmentExt info, CommonJsonTree node) {
        if(info.hasChild()) {
            List<DepartmentExt> children = info.getChildList();
            CommonJsonTree childNode;
            for (DepartmentExt ext : children) {
                childNode = new CommonJsonTree();
                childNode.setId(ext.getDepartId());
                childNode.setLabel(ext.getDepartName());
                childNode.setParentId(ext.getParentId());
                //设置菜单节点图标 Start
                String iconStr = "";
                /*判断是否设置了菜单导航图标样式*/
                if (!ext.hasChild()) {//导航页面的菜单节点
                    iconStr = "";//默认图标
                }
                childNode.setIconClass(iconStr);
                childNode = loadChildrenNodes(ext, childNode);
                node.addChildren(childNode);
            }
        }
        return node;
    }
}