wzy
2022-08-14 b141df9bf9764db8567efebed48006e12ab1f657
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package com.xzx.gc.role.rbac.tree;
 
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.xzx.gc.entity.CoreFunction;
 
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
 
public class FunctionItem  implements TreeItem{
    CoreFunction sysFunction = null;
    List<FunctionItem> children = new ArrayList<>();
    @JsonIgnore
    FunctionItem parent = null;
    String name ;
    public FunctionItem(CoreFunction sysFunction){
        this.sysFunction = sysFunction;
        this.name = sysFunction!=null?sysFunction.getName():null;
    }
    
    
    public void setParent(FunctionItem parent){
        this.parent = parent;
        parent.children.add(this);
    }
    @Override
    public List<FunctionItem> getChildren(){
        return this.children;
    }
    @Override
    public Long getId(){
        return sysFunction.getId();
    }
    
    public CoreFunction getData(){
        return this.sysFunction;
    }
    
    /**
     * 查找某个指定的子功能
     * @param functionId
     * @return
     */
    public FunctionItem findChild(long functionId){
        if(sysFunction.getId()==functionId){
            return this;
        }
        for(FunctionItem item:children){
            FunctionItem find = item.findChild(functionId);
            if(find!=null){
                return find;
            }
        }
        return null;
        
    }
    
    /**
     * 查找所有的子功能
     * @return
     */
    public List<FunctionItem> findAllItem(){
        List<FunctionItem> all = new LinkedList<>();
        findAllChildItem(all,this);
        return all;
    }
    
    public List<Long> findAllChildrenId(){
        List<FunctionItem> items =findAllItem();
        List<Long> children = new ArrayList<Long>();
        for(FunctionItem item:items){
            children.add(item.getId());
        }
        return children;
    }
    
    
    private void findAllChildItem(List<FunctionItem> all,FunctionItem parent){
        for(FunctionItem item:parent.children){
            all.add(item);
            findAllChildItem(all,item);
        }
        
    }
    
    
    
 
    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((sysFunction == null) ? 0 : sysFunction.hashCode());
        return result;
    }
 
 
    @Override
    public boolean equals(Object obj) {
        if (this == obj){
            return true;}
        if (obj == null){
            return false;}
        if (getClass() != obj.getClass()){
            return false;}
        FunctionItem other = (FunctionItem) obj;
        if (sysFunction == null) {
            if (other.sysFunction != null)
                return false;
        } else if (!sysFunction.equals(other.sysFunction))
            return false;
        return true;
    }
 
 
    @Override
    public String toString() {
        return "MenuItem [sysFunction=" + sysFunction.getName() + ","+this.children.size()+"]";
    }
 
 
    @Override
    public String getName() {
        return sysFunction==null?"":sysFunction.getName();
    }
 
 
 
    
    
    
    
 
}