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
package org.jeecg.modules.eam.service.impl;
 
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.common.api.vo.CommonGenericTree;
import org.jeecg.modules.eam.entity.ShutdownCause;
import org.jeecg.modules.eam.entity.ShutdownCauseCategory;
import org.jeecg.modules.eam.mapper.ShutdownCauseMapper;
import org.jeecg.modules.eam.service.IShutDownCauseCategoryService;
import org.jeecg.modules.eam.service.IShutdownCauseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.ArrayList;
import java.util.List;
 
/**
 * @Description: mom_eam_shutdown_cause
 * @Author: jeecg-boot
 * @Date: 2023-03-16
 * @Version: V1.0
 */
@Service
public class ShutdownCauseServiceImpl extends ServiceImpl<ShutdownCauseMapper, ShutdownCause> implements IShutdownCauseService {
 
    @Autowired
    private IShutDownCauseCategoryService shutDownCauseCategoryService;
 
 
    @Override
    public List<CommonGenericTree> loadTree() {
        // 根节点
        CommonGenericTree rootNode = initRootNode();
        // 停机原因
        List<ShutdownCauseCategory> shutdownCauseCategoryList = shutDownCauseCategoryService.list();
        List<CommonGenericTree> shutdownCauseCategoryTree = new ArrayList<CommonGenericTree>();
        for (ShutdownCauseCategory shutdownCauseCategory : shutdownCauseCategoryList) {
            shutdownCauseCategoryTree.add(shutdownCauseCategory2Tree(shutdownCauseCategory));
        }
        // 停机原因
        List<ShutdownCause> shutdownCauseList = this.list();
        List<CommonGenericTree> shutdownCauseTree = new ArrayList<CommonGenericTree>();
 
        shutdownCauseCategoryTree = this.list2Tree(shutdownCauseCategoryTree, shutdownCauseTree);
        for (CommonGenericTree temp : shutdownCauseCategoryTree) {
            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 shutdownCauseCategory2Tree(ShutdownCauseCategory shutdownCauseCategory) {
        CommonGenericTree<ShutdownCauseCategory> shutdownCauseCategoryNode = new CommonGenericTree<>();
        shutdownCauseCategoryNode.setKey(shutdownCauseCategory.getId());
        shutdownCauseCategoryNode.setTitle(shutdownCauseCategory.getNum() + "/" + shutdownCauseCategory.getName());
        shutdownCauseCategoryNode.setParentId("-1");
        shutdownCauseCategoryNode.setIcon("");
        shutdownCauseCategoryNode.setType(1);
        shutdownCauseCategoryNode.setDisabled(true);
        shutdownCauseCategoryNode.setEntity(shutdownCauseCategory);
        shutdownCauseCategoryNode.setValue(shutdownCauseCategory.getId());
        return shutdownCauseCategoryNode;
    }
 
}