qushaowei
2023-10-07 3858c775f565df000a45afd9a0c38c7b6bb39069
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
package org.jeecg.modules.eam.wrapper;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import org.jeecg.common.api.vo.CommonGenericTree;
import org.jeecg.common.util.StrUtils;
import org.jeecg.modules.eam.entity.Area;
import org.jeecg.modules.eam.entity.ProductionLine;
import org.jeecg.modules.eam.entity.Site;
 
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 
@SuppressWarnings("rawtypes")
public class SiteAreaLineTreeWrapper {
 
    /**
     * 工厂/车间树
     */
    public static List<CommonGenericTree> loadTree(List<Site> siteList, List<Area> areaList) {
        //return loadTree(siteList, areaList, Collections.emptyList());
        return null;
    }
 
    /**
     * 工厂/车间/产线树
     */
    @SuppressWarnings("unchecked")
    public static List<CommonGenericTree> loadTree(String title,List<Site> siteList, List<Area> areaList,
            List<ProductionLine> productionLineList) {
        List<CommonGenericTree> list = new ArrayList<>();
        Map<String, CommonGenericTree> siteMap = new HashMap<>();
        Map<String, CommonGenericTree> areaMap = new HashMap<>();
        CommonGenericTree<Site> root = new CommonGenericTree<>();
        root.setKey("-1");
        root.setTitle("中国航发");
        root.setType(0);
        list.add(root);
        if (CollectionUtils.isNotEmpty(siteList)) {
            CommonGenericTree<Site> siteNode;
            CommonGenericTree<Area> areaNode;
            CommonGenericTree<ProductionLine> lineNode;
            for (Site site : siteList) {
                siteNode = new CommonGenericTree<>();
                siteNode.setKey(site.getId());
                siteNode.setTitle(site.getName());
                siteNode.setParentId(root.getKey());
                siteNode.setIcon("");
                siteNode.setType(1);
                siteNode.setEntity(site);
                root.addChildren(siteNode);
                siteMap.put(site.getId(), siteNode);
            }
            for (Area area : areaList) {
                if (siteMap.containsKey(area.getSiteId())) {
                    siteNode = siteMap.get(area.getSiteId());
                    areaNode = new CommonGenericTree<>();
                    areaNode.setKey(area.getId());
                    areaNode.setTitle(area.getName());
                    areaNode.setParentId(area.getSiteId());
                    areaNode.setIcon("");
                    areaNode.setType(2);
                    areaNode.setEntity(area);
                    siteNode.addChildren(areaNode);
                    areaMap.put(area.getId(), areaNode);
                }
            }
            for (ProductionLine line : productionLineList) {
                if (areaMap.containsKey(line.getAreaId())) {
                    areaNode = areaMap.get(line.getAreaId());
                    lineNode = new CommonGenericTree<>();
                    lineNode.setKey(line.getId());
                    lineNode.setTitle(line.getName());
                    lineNode.setParentId(line.getAreaId());
                    lineNode.setIcon("");
                    lineNode.setType(3);
                    lineNode.setEntity(line);
                    lineNode.setDisabled(true);
                    areaNode.addChildren(lineNode);
                }
            }
        }
        return list;
    }
 
}