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
114
115
116
117
118
119
120
121
122
123
package org.jeecg.modules.eam.service.impl;
 
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import org.jeecg.common.api.vo.CommonGenericTree;
import org.jeecg.modules.eam.entity.InspectionProjectCategory;
import org.jeecg.modules.eam.entity.TransferMethodCategory;
import org.jeecg.modules.eam.mapper.TransferMethodCategoryMapper;
import org.jeecg.modules.eam.service.ITransferMethodCategoryService;
import org.springframework.stereotype.Service;
 
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * @Description: mom_eam_transfer_method_category
 * @Author: jeecg-boot
 * @Date:   2023-03-15
 * @Version: V1.0
 */
@Service
public class TransferMethodCategoryServiceImpl extends ServiceImpl<TransferMethodCategoryMapper, TransferMethodCategory> implements ITransferMethodCategoryService {
 
    // 初始化工装类别
    private static final String initTransferMethodCategory = "01-增加,02-减少";
 
    @Override
    public List<CommonGenericTree> loadTree() {
        List<TransferMethodCategory> transferMethodCategoryList = this.lambdaQuery().eq(TransferMethodCategory::getDelFlag, "0").list();
        List<CommonGenericTree> commonGenericTrees = loadTree(transferMethodCategoryList);
        return commonGenericTrees;
    }
 
    @SuppressWarnings("unchecked")
    public List<CommonGenericTree> loadTree(List<TransferMethodCategory> transferMethodCategoryList) {
        @SuppressWarnings("unused")
        TransferMethodCategory transferMethodCategory = new TransferMethodCategory();
        List<CommonGenericTree> list = new ArrayList<>();
        Map<String, CommonGenericTree> map = new HashMap<>();
        CommonGenericTree<TransferMethodCategory> node = new CommonGenericTree<>();
        node.setKey("-1");
        node.setValue("-1");
        node.setTitle("增减方式分类");
        node.setRField1("");
        node.setRField2("");
        node.setDisabled(false);
        node.setEntity(new TransferMethodCategory());
        list.add(node);
        if (CollectionUtils.isNotEmpty(list)) {
            CommonGenericTree<TransferMethodCategory> pcNode;
            for (TransferMethodCategory tfc : transferMethodCategoryList) {
                if (tfc.getParentId().equals("-1")) {
                    pcNode = new CommonGenericTree<>();
                    pcNode.setKey(tfc.getId());
                    pcNode.setTitle(tfc.getNum() + "/" + tfc.getName());
                    pcNode.setParentId(node.getKey());
                    pcNode.setIcon("");
                    pcNode.setType(0);
                    pcNode.setValue(tfc.getId());
                    pcNode.setDisabled(false);
                    pcNode.setRField1(tfc.getNum());
                    pcNode.setRField2(tfc.getName());
                    pcNode.setEntity(tfc);
                    node.addChildren(pcNode);
                    map.put(tfc.getId(), pcNode);
                }
            }
            CommonGenericTree<TransferMethodCategory> childNode;
            for (TransferMethodCategory tfc : transferMethodCategoryList) {
                if (map.containsKey(tfc.getParentId())) {
                    pcNode = map.get(tfc.getParentId());
                    childNode = new CommonGenericTree<>();
                    childNode.setKey(tfc.getId());
                    childNode.setTitle(tfc.getNum() + "/" + tfc.getName());
                    childNode.setParentId(tfc.getParentId());
                    childNode.setIcon("");
                    childNode.setType(0);
                    childNode.setValue(tfc.getId());
                    childNode.setDisabled(false);
                    childNode.setRField1(tfc.getNum());
                    childNode.setRField2(tfc.getName());
                    childNode.setEntity(tfc);
                    pcNode.addChildren(childNode);
                }
            }
        }
        return list;
    }
 
    @Override
    public void initFristTransferMethodCategory() {
        String[] initList = initTransferMethodCategory.split(",");
        if (initList.length > 0) {
            TransferMethodCategory transferMethodCategory;
            for (String categoryNumAndName : initList) {
                if (CollectionUtils.isEmpty(
                        listByNumAndName(categoryNumAndName.split("-")[0], categoryNumAndName.split("-")[1]))) {
                    transferMethodCategory = new TransferMethodCategory();
                    transferMethodCategory.setParentId("-1");
                    transferMethodCategory.setNum(categoryNumAndName.split("-")[0]);
                    transferMethodCategory.setName(categoryNumAndName.split("-")[1]);
                    save(transferMethodCategory);
                }
            }
        }
    }
 
    @Override
    public List<TransferMethodCategory> listByNumAndName(String num, String name) {
        return super.lambdaQuery().eq(TransferMethodCategory::getNum, num).eq(TransferMethodCategory::getName, name)
                .orderByAsc(TransferMethodCategory::getNum).list();
    }
 
 
    @Override
    public List<TransferMethodCategory> listByType(String  type) {
        return super.lambdaQuery().eq(TransferMethodCategory::getType, type)
                .orderByAsc(TransferMethodCategory::getNum).list();
    }
}