lyh
2025-01-13 137d008bd9b7d932160436a3a560b24512f6d1db
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
package org.jeecg.modules.dnc.service.support;
 
import org.jeecg.modules.dnc.entity.PartsInfo;
import org.jeecg.modules.dnc.entity.ProductInfo;
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<CommonGenericTree> tree = new ArrayList<CommonGenericTree>();// TreeNode集合,存放所有树对象。
        Map<String, CommonGenericTree> productMap = new HashMap<>();
        Map<String, CommonGenericTree> componentMap = new HashMap<>();
        CommonGenericTree<ProductInfo> node;
        CommonGenericTree<ComponentInfo> componentNode;
        CommonGenericTree<PartsInfo> partsNode;
        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);
            }
        }
        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;
    }
}