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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package org.jeecg.modules.eam.wrapper;
 
import org.jeecg.modules.eam.entity.Area;
import org.jeecg.modules.eam.entity.ProductionLine;
import org.jeecg.modules.eam.entity.Site;
import org.jeecg.modules.eam.vo.CommonCascade;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import java.util.*;
 
public class SiteAreaCascadeWrapper {
 
    /**
     * 获取工厂车间两级级联数据 必须选择到产线
     * 
     * @param siteList
     * @param areaList
     * @return
     */
    public static List<CommonCascade> loadCascade(List<Site> siteList, List<Area> areaList) {
        List<CommonCascade> list = loadCascadeBase(siteList, areaList, null);
        List<CommonCascade> result = new ArrayList<>();
        for (CommonCascade c : list) {
            if (c.hasChildren()) {
                result.add(c);
            }
        }
        return result;
    }
 
    /**
     * 必须要选择到产线三级级联结构
     * 
     * @param siteList
     * @param areaList
     * @return
     */
    public static List<CommonCascade> loadCascade(List<Site> siteList, List<Area> areaList,
            List<ProductionLine> lineList) {
        List<CommonCascade> list = loadCascadeBase(siteList, areaList, lineList);
        // 过滤工厂下没有车间 车间下没有产线的数据
        List<CommonCascade> result = new ArrayList<>();
        for (CommonCascade c : list) {
            if (c.hasChildren()) {
                List<CommonCascade> children = c.getChildren();
                List<CommonCascade> dList = new ArrayList<>();
                for (CommonCascade d : children) {
                    if (d.hasChildren()) {
                        dList.add(d);
                    }
                }
                if (!dList.isEmpty()) {
                    c.setChildren(dList);
                    result.add(c);
                }
 
            }
        }
        return result;
    }
 
    /**
     * 获取工厂车间产线三级级联数据 返回全数据 不做过滤
     * 
     * @param siteList
     * @param areaList
     * @param lineList
     * @return
     */
    public static List<CommonCascade> loadCascadeBase(List<Site> siteList, List<Area> areaList,
            List<ProductionLine> productionLineList) {
        List<CommonCascade> commonCascadeList = new ArrayList<CommonCascade>();
        if (CollectionUtils.isNotEmpty(siteList) || CollectionUtils.isNotEmpty(areaList)) {
            Map<String, CommonCascade> siteMap = new HashMap<>();
            Map<String, CommonCascade> areaMap = new HashMap<>();
            CommonCascade siteNode;
            CommonCascade areaNode;
            CommonCascade productionLineNode;
            for (Site site : siteList) {
                siteNode = new CommonCascade();
                siteNode = siteNode.setValue(site.getId()).setLabel(site.getName());
                commonCascadeList.add(siteNode);
                siteMap.put(site.getId(), siteNode);
            }
            for (Area area : areaList) {
                if (siteMap.containsKey(area.getSiteId())) {
                    siteNode = siteMap.get(area.getSiteId());
                    areaNode = new CommonCascade();
                    areaNode = areaNode.setValue(area.getId()).setLabel(area.getName());
                    siteNode.addChildren(areaNode);
                    areaMap.put(area.getId(), areaNode);
                }
            }
            // 返回两级数据
            if (CollectionUtils.isNotEmpty(productionLineList)) {
                for (ProductionLine productionLine : productionLineList) {
                    if (areaMap.containsKey(productionLine.getAreaId())) {
                        areaNode = areaMap.get(productionLine.getAreaId());
                        productionLineNode = new CommonCascade();
                        productionLineNode = productionLineNode.setValue(productionLine.getId())
                                .setLabel(productionLine.getName());
                        areaNode.addChildren(productionLineNode);
                    }
                }
            }
        }
        return commonCascadeList;
    }
 
}