hyingbo
7 天以前 cc0e9036de6e922e8fe254fef01d8de9996024b7
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
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<ProcessSpecVersion> processSpecVersionList,
                                                   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> pvsMap = new HashMap<>();
        Map<String, CommonGenericTree> processMap = new HashMap<>();
        CommonGenericTree<ProductInfo> node;
        CommonGenericTree<ComponentInfo> componentNode;
        CommonGenericTree<PartsInfo> partsNode;
        CommonGenericTree<ProcessSpecVersion> pvsNode;
        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(ProcessSpecVersion processSpecVersion : processSpecVersionList) {
            pvsNode = new CommonGenericTree();
            pvsNode.setId(processSpecVersion.getId());
            pvsNode.setLabel("[" + processSpecVersion.getProcessSpecVersionCode()+ "]" + processSpecVersion.getProcessSpecVersionName());
            pvsNode.setParentId(null);
            pvsNode.setIconClass("");
            pvsNode.setType(4);
            pvsNode.setRField(processSpecVersion.getPartsId());
            pvsNode.setEntity(processSpecVersion);
            if(partsMap.containsKey(pvsNode.getRField())) {
                partsNode = partsMap.get(pvsNode.getRField());
                pvsNode.setParentId(partsNode.getId());
                partsNode.addChildren(pvsNode);
            }
            pvsMap.put(processSpecVersion.getId(),pvsNode);
        }
 
        //工序存在部件或者工艺规程版本下
        for(ProcessStream processStream : processStreams) {
            processNode = new CommonGenericTree();
            processNode.setId(processStream.getProcessId());
            processNode.setLabel("[" + processStream.getProcessCode()+ "]" + processStream.getProcessName());
            processNode.setParentId(null);
            processNode.setIconClass("");
            processNode.setType(5);
            if (StrUtil.isEmpty(processStream.getPsvId())) {
                //没有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 {
                //有psvId,零件下的工序
                processNode.setRField(processStream.getPsvId());
                processNode.setEntity(processStream);
                if(pvsMap.containsKey(processNode.getRField())) {
                    pvsNode = pvsMap.get(processNode.getRField());
                    processNode.setParentId(pvsNode.getId());
                    pvsNode.addChildren(processNode);
                }
            }
            processMap.put(processStream.getProcessId(),processNode);
        }
 
        //工步存在工序下
        for (WorkStep workStep : workStepList) {
            workStepNode = new CommonGenericTree();
            workStepNode.setId(workStep.getId());
            workStepNode.setLabel("[" + workStep.getStepCode() + "]" + workStep.getStepName());
            workStepNode.setParentId(null);
            workStepNode.setIconClass("");
            workStepNode.setType(6);
            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;
    }
}