hyingbo
7 天以前 cc0e9036de6e922e8fe254fef01d8de9996024b7
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package org.jeecg.modules.dnc.service.support;
 
import org.jeecg.modules.dnc.dto.DeviceGroupExt;
import org.jeecg.modules.dnc.entity.DeviceGroup;
import org.jeecg.modules.dnc.response.CommonGenericTree;
import org.springframework.beans.BeanUtils;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
public class DeviceGroupTreeWrapper {
    public static List<CommonGenericTree> loadTree(List<DeviceGroupExt> deviceGroupExtList) {
        Map<String, CommonGenericTree> treeMap = new HashMap<>();
        for(DeviceGroupExt ext : deviceGroupExtList) {
            treeMap = getBaseNodeMap(ext, treeMap);
        }
        return CommonGenericTree.convertMapToList(treeMap);
    }
 
    public static List<CommonGenericTree> loadDepartTree(List<DeviceGroupExt> deviceGroupExtList) {
        List<CommonGenericTree> tree = new ArrayList<CommonGenericTree>();// TreeNode集合,存放所有树对象。
        CommonGenericTree<DeviceGroup> node;
        DeviceGroup deviceGroup;
        for(DeviceGroupExt ext : deviceGroupExtList) {
            node = new CommonGenericTree<DeviceGroup>();
            node.setId(ext.getGroupId());
            node.setLabel(ext.getGroupName());
            node.setParentId(null);
            //设置菜单节点图标 Start
            String iconStr = "";
            /*判断是否设置了菜单导航图标样式*/
            if (!ext.hasChild()) {//导航页面的菜单节点
                iconStr = "";//默认图标
            }
            node.setIconClass(iconStr);
            node.setType(1);
            deviceGroup = new DeviceGroup();
            BeanUtils.copyProperties(ext, deviceGroup);
            node.setEntity(deviceGroup);
            node = loadChildrenNodes(ext, node);
            tree.add(node);
        }
        return tree;
    }
 
    private static CommonGenericTree loadChildrenNodes(DeviceGroupExt info, CommonGenericTree node) {
        if(info.hasChild()) {
            List<DeviceGroupExt> children = info.getChildren();
            CommonGenericTree<DeviceGroup> childNode;
            DeviceGroup deviceGroup;
            for (DeviceGroupExt ext : children) {
                childNode = new CommonGenericTree();
                childNode.setId(ext.getGroupId());
                childNode.setLabel(ext.getGroupName());
                childNode.setParentId(ext.getParentId());
                //设置菜单节点图标 Start
                String iconStr = "";
                /*判断是否设置了菜单导航图标样式*/
                if (!ext.hasChild()) {//导航页面的菜单节点
                    iconStr = "";//默认图标
                }
                childNode.setIconClass(iconStr);
                childNode.setType(1);
                deviceGroup = new DeviceGroup();
                BeanUtils.copyProperties(ext, deviceGroup);
                childNode.setEntity(deviceGroup);
                childNode = loadChildrenNodes(ext, childNode);
                node.addChildren(childNode);
            }
        }
        return node;
    }
 
    private static Map<String,CommonGenericTree> getBaseNodeMap(DeviceGroupExt ext, Map<String,CommonGenericTree> map) {
        CommonGenericTree<DeviceGroup> node;
        DeviceGroup deviceGroup;
        if(ext.getRankLevel() == 1) {
            node = new CommonGenericTree<DeviceGroup>();
            node.setId(ext.getGroupId());
            node.setLabel(ext.getGroupName());
            node.setParentId(null);
            //设置菜单节点图标 Start
            String iconStr = "";
            /*判断是否设置了菜单导航图标样式*/
            if (!ext.hasChild()) {//导航页面的菜单节点
                iconStr = "";//默认图标
            }
            node.setIconClass(iconStr);
            node.setType(1);
            deviceGroup = new DeviceGroup();
            BeanUtils.copyProperties(ext, deviceGroup);
            node.setEntity(deviceGroup);
            map.put(node.getId(), node);
            return map;
        }else {
            node = new CommonGenericTree<DeviceGroup>();
            node.setId(ext.getGroupId());
            node.setLabel(ext.getGroupName());
            node.setParentId(ext.getParentId());
            //设置菜单节点图标 Start
            String iconStr = "";
            /*判断是否设置了菜单导航图标样式*/
            if (!ext.hasChild()) {//导航页面的菜单节点
                iconStr = "";//默认图标
            }
            node.setIconClass(iconStr);
            node.setType(1);
            deviceGroup = new DeviceGroup();
            BeanUtils.copyProperties(ext, deviceGroup);
            node.setEntity(deviceGroup);
            map.put(node.getId(), node);
            return getBaseNodeMap(ext.getParent(), map);
        }
    }
}