[测评系统]--测评系统核心代码库
wzp
2024-01-31 ad58ba3d20b080ef113cbd196000028f83308bb3
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
package com.ots.common.utils;
import com.ots.project.system.menu.domain.Menu;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
 
public class TreeUtils {
    
    public static List<Menu> getChildPerms(List<Menu> list, int parentId) {
        List<Menu> returnList = new ArrayList<Menu>();
        for (Iterator<Menu> iterator = list.iterator(); iterator.hasNext(); ) {
            Menu t = (Menu) iterator.next();
            
            if (t.getParentId() == parentId) {
                recursionFn(list, t);
                returnList.add(t);
            }
        }
        return returnList;
    }
    
    private static void recursionFn(List<Menu> list, Menu t) {
        
        List<Menu> childList = getChildList(list, t);
        t.setChildren(childList);
        for (Menu tChild : childList) {
            if (hasChild(list, tChild)) {
                
                Iterator<Menu> it = childList.iterator();
                while (it.hasNext()) {
                    Menu n = (Menu) it.next();
                    recursionFn(list, n);
                }
            }
        }
    }
    
    private static List<Menu> getChildList(List<Menu> list, Menu t) {
        List<Menu> tlist = new ArrayList<Menu>();
        Iterator<Menu> it = list.iterator();
        while (it.hasNext()) {
            Menu n = (Menu) it.next();
            if (n.getParentId().longValue() == t.getMenuId().longValue()) {
                tlist.add(n);
            }
        }
        return tlist;
    }
    List<Menu> returnList = new ArrayList<Menu>();
    
    public List<Menu> getChildPerms(List<Menu> list, int typeId, String prefix) {
        if (list == null) {
            return null;
        }
        for (Iterator<Menu> iterator = list.iterator(); iterator.hasNext(); ) {
            Menu node = (Menu) iterator.next();
            
            if (node.getParentId() == typeId) {
                recursionFn(list, node, prefix);
            }
            
            
        }
        return returnList;
    }
    private void recursionFn(List<Menu> list, Menu node, String p) {
        
        List<Menu> childList = getChildList(list, node);
        if (hasChild(list, node)) {
            
            returnList.add(node);
            Iterator<Menu> it = childList.iterator();
            while (it.hasNext()) {
                Menu n = (Menu) it.next();
                n.setMenuName(p + n.getMenuName());
                recursionFn(list, n, p + p);
            }
        } else {
            returnList.add(node);
        }
    }
    
    private static boolean hasChild(List<Menu> list, Menu t) {
        return getChildList(list, t).size() > 0 ? true : false;
    }
}