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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package org.jeecg.modules.dnc.service.support;
 
import cn.hutool.core.util.StrUtil;
import org.jeecg.modules.dnc.entity.*;
import org.jeecg.modules.dnc.response.CommonGenericTree;
import org.jeecg.modules.dnc.entity.ComponentInfo;
import org.jeecg.modules.dnc.dto.ComponentExt;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
public class ProductTreeWrapper {
 
    public static List<CommonGenericTree> loadTree(List<ProductInfo> productInfoList, List<ComponentExt> componentInfoList,
                                                   List<PartsInfo> partsInfoList,List<ProcessStream> processStreams, List<WorkStep> workStepList) {
        List<CommonGenericTree> tree = new ArrayList<CommonGenericTree>();// TreeNode集合,存放所有树对象。
        Map<String, CommonGenericTree> productMap = new HashMap<>();
        Map<String, CommonGenericTree> componentMap = new HashMap<>();
        Map<String, CommonGenericTree> partsMap = new HashMap<>();
        Map<String, CommonGenericTree> processMap = new HashMap<>();
        CommonGenericTree<ProductInfo> node;
        CommonGenericTree<ComponentInfo> componentNode;
        CommonGenericTree<PartsInfo> partsNode;
        CommonGenericTree<ProcessStream> processNode;
        CommonGenericTree<WorkStep> workStepNode;
        for(ProductInfo productInfo : productInfoList) {
            node = new CommonGenericTree();
            node.setId(productInfo.getProductId());
            node.setLabel("[" + productInfo.getProductNo()+ "]" + productInfo.getProductName());
            node.setParentId(productInfo.getProductId());
            node.setIconClass("");
            node.setType(1);
            node.setEntity(productInfo);
            tree.add(node);
            productMap.put(productInfo.getProductId(), node);
        }
 
        List<CommonGenericTree> commonJsonTreeList = ComponentTreeWrapper.loadTree(componentInfoList);
        for(CommonGenericTree compNode : commonJsonTreeList) {
            componentMap = CommonGenericTree.getLeafNode(componentMap, compNode);
            if(productMap.containsKey(compNode.getRField())) {
                node = productMap.get(compNode.getRField());
                compNode.setParentId(node.getId());
                node.addChildren(compNode);
            }
        }
 
        for(PartsInfo parts : partsInfoList) {
            partsNode = new CommonGenericTree();
            partsNode.setId(parts.getPartsId());
            partsNode.setLabel("[" + parts.getPartsCode()+ "]" + parts.getPartsName());
            partsNode.setParentId(null);
            partsNode.setIconClass("");
            partsNode.setType(3);
            partsNode.setRField(parts.getComponentId());
            partsNode.setEntity(parts);
            if(componentMap.containsKey(partsNode.getRField())) {
                componentNode = componentMap.get(partsNode.getRField());
                partsNode.setParentId(componentNode.getId());
                componentNode.addChildren(partsNode);
            }
            partsMap.put(parts.getPartsId(), partsNode);
        }
 
        //工序存在部件或者零件下
        for(ProcessStream processStream : processStreams) {
            processNode = new CommonGenericTree();
            processNode.setId(processStream.getProcessId());
            processNode.setLabel("[" + processStream.getProcessCode()+ "]" + processStream.getProcessName());
            processNode.setParentId(null);
            processNode.setIconClass("");
            processNode.setType(4);
            if (StrUtil.isEmpty(processStream.getPartsId())) {
                //没有partsId,部件下的工序
                processNode.setRField(processStream.getComponentId());
                processNode.setEntity(processStream);
                if(componentMap.containsKey(processNode.getRField())) {
                    componentNode = componentMap.get(processNode.getRField());
                    processNode.setParentId(componentNode.getId());
                    componentNode.addChildren(processNode);
                }
            }else {
                //有partsId,零件下的工序
                processNode.setRField(processStream.getPartsId());
                processNode.setEntity(processStream);
                if(partsMap.containsKey(processNode.getRField())) {
                    partsNode = partsMap.get(processNode.getRField());
                    processNode.setParentId(partsNode.getId());
                    partsNode.addChildren(processNode);
                }
            }
            processMap.put(processStream.getProcessId(),processNode);
        }
 
        //工步存在工序下
        for (WorkStep workStep : workStepList) {
            workStepNode = new CommonGenericTree();
            workStepNode.setId(workStep.getStepId());
            workStepNode.setLabel("[" + workStep.getStepCode() + "]" + workStep.getStepName());
            workStepNode.setParentId(null);
            workStepNode.setIconClass("");
            workStepNode.setType(5);
            workStepNode.setRField(workStep.getProcessId());
            workStepNode.setEntity(workStep);
            if (processMap.containsKey(workStepNode.getRField())) {
                processNode = processMap.get(workStepNode.getRField());
                workStepNode.setParentId(processNode.getId());
                processNode.addChildren(workStepNode);
            }
        }
 
        return tree;
    }
 
    public static List<CommonGenericTree> loadTree(List<ProductInfo> productInfoList) {
        List<CommonGenericTree> tree = new ArrayList<CommonGenericTree>();// TreeNode集合,存放所有树对象。
        CommonGenericTree<ProductInfo> node;
        for(ProductInfo productInfo : productInfoList) {
            node = new CommonGenericTree();
            node.setId(productInfo.getProductId());
//            node.setLabel("[" + productInfo.getProductNo()+ "]" + productInfo.getProductName());
            node.setLabel(productInfo.getProductName());
            //node.setParentId(null);
            node.setIconClass("");
            node.setType(1);
            node.setEntity(productInfo);
            tree.add(node);
        }
        return tree;
    }
}