cuijian
2023-08-19 bdd0875d4b13a3f1ef472f64d4b6a95e0ef64b22
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
package org.jeecg.modules.eam.service.impl;
 
 
import org.jeecg.common.api.vo.CommonGenericTree;
import org.jeecg.common.system.api.ISysBaseAPI;
//import org.jeecg.modules.base.service.IUnitService;
import org.jeecg.modules.eam.entity.ProcessParameters;
import org.jeecg.modules.eam.entity.ProcessParametersCategory;
import org.jeecg.modules.eam.mapper.ProcessParametersMapper;
import org.jeecg.modules.eam.service.IProcessParametersCategoryService;
import org.jeecg.modules.eam.service.IProcessParametersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 
import java.util.ArrayList;
import java.util.List;
 
/**
 * @Description: 工艺参数
 * @Author: houjie
 * @Date: 2023-03-07
 * @Version: V1.0
 */
@Service
public class ProcessParametersServiceImpl extends ServiceImpl<ProcessParametersMapper, ProcessParameters> implements IProcessParametersService {
 
    @Autowired
    private IProcessParametersCategoryService processParametersCategoryService;
 
    //    @Autowired
//    private IUnitService unitService;
    @Autowired
    private ISysBaseAPI sysBaseApi;
 
    @Override
    public List<CommonGenericTree> loadTree() {
        // 根节点
        CommonGenericTree rootNode = initRootNode();
        // 工艺参数类别
        List<ProcessParametersCategory> processParametersCategoryList = processParametersCategoryService.list();
        List<CommonGenericTree> processParametersCategoryTree = new ArrayList<CommonGenericTree>();
        for (ProcessParametersCategory processParametersCategory : processParametersCategoryList) {
            processParametersCategoryTree.add(processParametersCategory2Tree(processParametersCategory));
        }
        // 工艺参数
        List<ProcessParameters> processParametersList = this.list();
        List<CommonGenericTree> processParametersTree = new ArrayList<CommonGenericTree>();
        for (ProcessParameters processParameters : processParametersList) {
            String unitName  = sysBaseApi.getUnitNameById(processParameters.getUnitId());
            processParameters.setUnit(unitName);
            processParametersTree.add(processParameters2Tree(processParameters));
        }
        processParametersCategoryTree = this.list2Tree(processParametersCategoryTree, processParametersTree);
        for (CommonGenericTree temp : processParametersCategoryTree) {
            rootNode.addChildren(temp);
        }
        // 返回的结果是list
        List<CommonGenericTree> list = new ArrayList<>();
        list.add(rootNode);
        return list;
    }
 
    private CommonGenericTree initRootNode() {
        CommonGenericTree node = new CommonGenericTree<>();
        node.setKey("-1");
        node.setTitle("工艺参数类别");
        node.setType(0);
        node.setDisabled(true);
        node.setEntity(null);
        node.setValue("-1");
        return node;
    }
 
    private List<CommonGenericTree> list2Tree(List<CommonGenericTree> parentList, List<CommonGenericTree> childList) {
        for (CommonGenericTree tree : parentList) {
            String id = tree.getKey();
            for (CommonGenericTree cTree : childList) {
                if (id.equals(cTree.getParentId())) {
                    tree.addChildren(cTree);
                }
            }
        }
        return parentList;
    }
 
    private CommonGenericTree processParametersCategory2Tree(ProcessParametersCategory processParametersCategory) {
        CommonGenericTree<ProcessParametersCategory> processParametersCategoryNode = new CommonGenericTree<>();
        processParametersCategoryNode.setKey(processParametersCategory.getId());
        processParametersCategoryNode.setTitle(processParametersCategory.getNum() + "/" + processParametersCategory.getName());
        processParametersCategoryNode.setParentId("-1");
        processParametersCategoryNode.setIcon("");
        processParametersCategoryNode.setType(1);
        processParametersCategoryNode.setDisabled(true);
        processParametersCategoryNode.setEntity(processParametersCategory);
        processParametersCategoryNode.setValue(processParametersCategory.getId());
        return processParametersCategoryNode;
    }
 
    private CommonGenericTree processParameters2Tree(ProcessParameters processParameters) {
        CommonGenericTree<ProcessParameters> processParametersNode = new CommonGenericTree<>();
        processParametersNode.setKey(processParameters.getId());
        processParametersNode.setTitle(processParameters.getNum() + "/" + processParameters.getName());
        processParametersNode.setParentId(processParameters.getProcessParametersCategoryId());
        processParametersNode.setIcon("");
        processParametersNode.setType(2);
        processParametersNode.setDisabled(false);
        processParametersNode.setEntity(processParameters);
        processParametersNode.setValue(processParameters.getId());
        return processParametersNode;
    }
}