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
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 java.util.*;
 
public class SiteAreaProductLineWrapper {
 
    public static List<CommonCascade> loadCascadePlus(List<Site> siteList, List<Area> areaList,
                                                      List<ProductionLine> productionLineList) {
        if (siteList == null || siteList.isEmpty() || areaList == null || areaList.isEmpty()
                || productionLineList == null || productionLineList.isEmpty())
            return Collections.emptyList();
        List<CommonCascade> list = new ArrayList<>();
        Map<String, CommonCascade> siteMap = new HashMap<>();
        Map<String, CommonCascade> areaMap = new HashMap<>();
        if (siteList == null || siteList.isEmpty())
            return list;
        CommonCascade siteNode;
        CommonCascade areaNode;
        CommonCascade productionLineNode;
        for (Site site : siteList) {
            siteNode = new CommonCascade();
            siteNode = siteNode.setValue(site.getId()).setLabel(site.getName());
            list.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);
            }
        }
        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);
 
            }
        }
        List<CommonCascade> secondList = new ArrayList<>();
        for (CommonCascade c : list) {
            if (c.hasChildren()) {
                secondList.add(c);
            }
        }
        List<CommonCascade> middleList = new ArrayList<>();
        for (CommonCascade c : secondList) {
            if (c.hasChildren()) {
                middleList.add(c);
            }
        }
        List<CommonCascade> result = new ArrayList<>();
        for (CommonCascade c : middleList) {
            if (c.hasChildren()) {
                result.add(c);
            }
        }
        return middleList;
    }
 
}