cuijian
2025-05-09 cd8b267053dd314a3a2c17ed1cc2b90316870712
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
package org.jeecg.modules.tms.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.jeecg.common.api.vo.CommonGenericTree;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.util.StrUtils;
import org.jeecg.modules.tms.entity.ToolsClassify;
import org.jeecg.modules.tms.mapper.ToolsClassifyMapper;
import org.jeecg.modules.tms.service.IToolsClassifyService;
import org.springframework.stereotype.Service;
 
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 
import javax.tools.Tool;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * @Description: tms_tools_classify
 * @Author: jeecg-boot
 * @Date:   2025-05-06
 * @Version: V1.0
 */
@Service
public class ToolsClassifyServiceImpl extends ServiceImpl<ToolsClassifyMapper, ToolsClassify> implements IToolsClassifyService {
 
    @Override
    public IPage<ToolsClassify> queryPageList(Page<ToolsClassify> page, Map<String, String[]> parameterMap) {
        QueryWrapper<ToolsClassify> queryWrapper = Wrappers.query();
        String[] classifyIds = parameterMap.get("classifyId");
        if (classifyIds != null && classifyIds.length > 0) {
            queryWrapper.like("t.classify_id", classifyIds[0]);
        }
        String[] typeNames = parameterMap.get("typeName");
        if (typeNames != null && typeNames.length > 0) {
            queryWrapper.like("t.type_name", typeNames[0]);
        }
        String[] parentIds = parameterMap.get("parentId");
        if (parentIds != null && parentIds.length > 0) {
            queryWrapper.eq("t.parent_id", parentIds[0]);
        }
        queryWrapper.orderByAsc("t.seq");
        return this.baseMapper.queryPageList(page, queryWrapper);
    }
    public List<CommonGenericTree> loadTree() {
        List<ToolsClassify> toolsClassifyList = this.list();
        List<CommonGenericTree> commonGenericTreeList = loadTree(toolsClassifyList);
        return commonGenericTreeList;
    }
 
    public List<CommonGenericTree> loadTree(List<ToolsClassify> toolsClassifyList) {
        @SuppressWarnings("unused") ToolsClassify toolsClassify = new ToolsClassify();
        List<CommonGenericTree> list = new ArrayList<>();
        Map<String, CommonGenericTree> map = new HashMap<>();
        CommonGenericTree<ToolsClassify> node = new CommonGenericTree<>();
        node.setKey("-1");
        node.setTitle("工具分类");
        node.setRField1("");
        node.setRField2("");
        node.setEntity(new ToolsClassify().setId("-1").setClassifyId("0").setTypeName("工具分类").setLeafFlag("2"));
        list.add(node);
        if (CollectionUtils.isNotEmpty(toolsClassifyList)) {
            CommonGenericTree<ToolsClassify> tcNode;
            for (ToolsClassify tc : toolsClassifyList) {
                if (StrUtils.isBlankOrNull(tc.getParentId()) || tc.getParentId().equals("-1")) {
                    tcNode = new CommonGenericTree<>();
                    tcNode.setKey(tc.getId());
                    tcNode.setTitle(tc.getClassifyId() + "/" + tc.getTypeName());
                    tcNode.setParentId(node.getKey());
                    tcNode.setIcon("");
                    tcNode.setType(1);
                    tcNode.setValue(tc.getId());
                    tcNode.setDisabled(CommonConstant.STATUS_0.equals(tc.getStatus()) ? true : false);
                    tcNode.setRField1(tc.getClassifyId());
                    tcNode.setRField2(getBaseParent(tc.getId(), 0).getClassifyId());
                    tcNode.setEntity(tc);
                    node.addChildren(tcNode);
                    map.put(tc.getId(), tcNode);
                }
            }
            CommonGenericTree<ToolsClassify> childNode;
            for (ToolsClassify tc : toolsClassifyList) {
                ToolsClassify child = tc;
                if (map.containsKey(child.getParentId())) {
                    if (StrUtils.isBlankOrNull(tc.getParentId()) || tc.getParentId().equals("-1")) {
                        toolsClassify = tc;
                    } else {
                        tcNode = map.get(child.getParentId());
                        childNode = new CommonGenericTree<>();
                        childNode.setKey(tc.getId());
                        childNode.setTitle(tc.getClassifyId() + "/" + tc.getTypeName());
                        childNode.setParentId(tc.getParentId());
                        childNode.setIcon("");
                        childNode.setType(0);
                        childNode.setValue(tc.getId());
                        childNode.setDisabled(CommonConstant.STATUS_0.equals(tc.getStatus()) ? true : false);
                        childNode.setRField1(tc.getClassifyId());
                        childNode.setRField2(getBaseParent(tc.getId(), 0).getClassifyId());
                        childNode.setEntity(tc);
                        tcNode.addChildren(childNode);
                        map.put(child.getId(), childNode);
                    }
                }
            }
        }
        return list;
    }
 
    public ToolsClassify getBaseParent(String id, int index) {
        ToolsClassify toolsClassify = null;
        if (index < 99) {
            toolsClassify = getById(id);
            if (StrUtils.isNotBlankOrNull(toolsClassify.getParentId())) {
                if (!toolsClassify.getParentId().equals("-1")) {
                    toolsClassify = getBaseParent(toolsClassify.getParentId(), index++);
                }
            }
        }
        return toolsClassify;
    }
}