zhangherong
2 天以前 57df7097f99ffe16a4b81876f23aebf38b637ec5
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
package org.jeecg.modules.eam.tree;
 
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.eam.vo.EamEquipmentTree;
import org.jeecg.modules.system.entity.BaseFactory;
import org.jeecg.modules.system.model.EamBaseFactoryTreeModel;
 
import java.util.ArrayList;
import java.util.List;
 
public class FindsEquipmentEamCenterUtil {
    /**
     * 获取 MdcEquipmentTree
     */
    public static List<EamEquipmentTree> wrapEquipmentBaseFactoryTreeList(List<BaseFactory> recordList) {
        List<EamEquipmentTree> idList = new ArrayList<>();
        List<EamBaseFactoryTreeModel> records = new ArrayList<>();
        for (BaseFactory BaseFactory : recordList) {
            records.add(new EamBaseFactoryTreeModel(BaseFactory));
        }
        getChildren(records, idList);
        setEmptyChildrenAsNull(idList);
        return idList;
    }
 
    /**
     * 该方法是找到并封装顶级父类的节点到TreeList集合
     */
    private static void getChildren(List<EamBaseFactoryTreeModel> recordList, List<EamEquipmentTree> idList) {
        List<EamBaseFactoryTreeModel> treeList = new ArrayList<>();
        for (EamBaseFactoryTreeModel EamBaseFactoryTreeModel : recordList) {
            if (oConvertUtils.isEmpty(EamBaseFactoryTreeModel.getParentId())) {
//                EamBaseFactoryTreeModel.setType(1);
                treeList.add(EamBaseFactoryTreeModel);
                idList.add(new EamEquipmentTree().convertByBaseFactory(EamBaseFactoryTreeModel));
            }
        }
        getGrandChildren(treeList, recordList, idList);
    }
 
    /**
     *该方法是找到顶级父类下的所有子节点集合并封装到TreeList集合
     */
    private static void getGrandChildren(List<EamBaseFactoryTreeModel> treeList, List<EamBaseFactoryTreeModel> recordList, List<EamEquipmentTree> idList) {
        for (int i = 0; i < treeList.size(); i++) {
            EamBaseFactoryTreeModel model = treeList.get(i);
            EamEquipmentTree mdcEquipmentTree = idList.get(i);
            for (int i1 = 0; i1 < recordList.size(); i1++) {
                EamBaseFactoryTreeModel m = recordList.get(i1);
                if (m.getParentId() != null && m.getParentId().equals(model.getId())) {
                    model.getChildren().add(m);
//                    m.setType(1);
                    mdcEquipmentTree.getChildren().add(new EamEquipmentTree().convertByBaseFactory(m));
                }
            }
            getGrandChildren(treeList.get(i).getChildren(), recordList, idList.get(i).getChildren());
        }
    }
 
    /**
     * 该方法是将子节点为空的List集合设置为Null值
     */
    private static void setEmptyChildrenAsNull(List<EamEquipmentTree> idList) {
        for (EamEquipmentTree mdcEquipmentTree : idList) {
            if (mdcEquipmentTree.getChildren().isEmpty()) {
                mdcEquipmentTree.setLeaf(true);
            } else {
                setEmptyChildrenAsNull(mdcEquipmentTree.getChildren());
                mdcEquipmentTree.setLeaf(false);
            }
        }
    }
}