lyh
2025-01-16 1d84a3c62eeee429f7d7d6339bcf9b504a9d7277
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
package org.jeecg.modules.dnc.response;
 
import lombok.Data;
import lombok.NoArgsConstructor;
 
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
 
/**
 * Created by Administrator on 2019/9/6.
 */
@Data
@NoArgsConstructor
public class CommonJsonTree {
    private String id; // 要显示的节点的ID
    private String label; // 要显示的子节点的名称
    private String iconClass; // 节点的图标
    private String parentId; // 父节点的ID
    private List<CommonJsonTree> children; // 孩子节点的List
    private String rField; //绑定扩展鼠性
    private boolean checked = false; //是否选中
    private boolean disabled = false; //是否被禁用
    /**
     * 节点分类
     * 产品树型 1 产品 2 部件 3 零件
     * 设备树形 1 设备分组 2 设备
     */
    private Integer type;
 
    // 添加子节点的方法
    public CommonJsonTree addChildren(CommonJsonTree node) {
        if (this.children == null) {
            this.children = new ArrayList<CommonJsonTree>();
        }
        this.children.add(node);
        return node;
    }
 
    public boolean hasChildren() {
        boolean bu = true;
        if(getChildren() == null || getChildren().isEmpty()) {
            bu = false;
            return bu;
        }
        return bu;
    }
 
    /**
     * 获取树的所有叶子节点
     * @param tree
     * @return
     */
    public static Map<String, CommonJsonTree> getLeafNode(Map<String, CommonJsonTree> map, CommonJsonTree tree) {
        if(tree == null)
            return map;
        if(tree.hasChildren()) {
            List<CommonJsonTree> childrenNodes = tree.getChildren();
            for(CommonJsonTree child : childrenNodes) {
                map = getLeafNode(map, child);
            }
            map.put(tree.getId(), tree);
        }else {
            map.put(tree.getId(), tree);
        }
        return map;
    }
}