cuilei
2025-06-03 05968d59354115ebd20736faee1127b187000e51
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
128
129
130
131
132
133
134
135
136
137
138
139
140
package org.jeecg.modules.tms.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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.Warehouse;
import org.jeecg.modules.tms.entity.vo.DictVo;
import org.jeecg.modules.tms.mapper.WarehouseMapper;
import org.jeecg.modules.tms.service.IWarehouseService;
import org.springframework.stereotype.Service;
 
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 
import java.util.*;
 
/**
 * @Description: tms_warehouse
 * @Author: jeecg-boot
 * @Date:   2025-05-06
 * @Version: V1.0
 */
@Service
public class WarehouseServiceImpl extends ServiceImpl<WarehouseMapper, Warehouse> implements IWarehouseService {
 
    @Override
    public List<CommonGenericTree<Warehouse>> loadTree() {
        List<Warehouse> warehouseList = list(new LambdaQueryWrapper<Warehouse>()
                .eq(Warehouse::getStatus, CommonConstant.STATUS_1).orderByAsc(Warehouse::getSeq));
        return loadTree(warehouseList);
    }
 
    @Override
    public IPage<Warehouse> queryPageList(Page<Warehouse> page, Map<String, String[]> parameterMap) {
        QueryWrapper<Warehouse> queryWrapper = Wrappers.query();
        String[] warehouseNames = parameterMap.get("warehouseName");
        if (warehouseNames != null && warehouseNames.length > 0) {
            queryWrapper.like("t.warehouse_name", warehouseNames[0]);
        }
        String[] parentIds = parameterMap.get("parentId");
        if (parentIds != null && parentIds.length > 0) {
            queryWrapper.eq("t.parent_id", parentIds[0]);
        }
        String[] beginTimes = parameterMap.get("beginTime");
        String[] endTimes = parameterMap.get("endTime");
        if (beginTimes != null && beginTimes.length > 0) {
            queryWrapper.ge("t.create_time", beginTimes[0]);
        }
        if (endTimes != null && endTimes.length > 0) {
            queryWrapper.le("t.create_time", endTimes[0]);
        }
        queryWrapper.orderByAsc("t.seq");
        return this.baseMapper.queryPageList(page, queryWrapper);
    }
 
    @Override
    public List<DictVo> queryWarehouseDictList() {
        return this.baseMapper.queryWarehouseDictList();
    }
 
    private List<CommonGenericTree<Warehouse>> loadTree(List<Warehouse> warehouseList) {
        Warehouse warehouse = new Warehouse();
        List<CommonGenericTree<Warehouse>> list = new ArrayList<>();
        Map<String, CommonGenericTree<Warehouse>> map = new HashMap<>();
        CommonGenericTree<Warehouse> node = new CommonGenericTree<>();//手动创建根节点
        node.setKey("-1");
        node.setTitle("航宇救生");
        node.setRField1("");
        node.setRField2("");
        node.setEntity(new Warehouse()
                .setId("-1")
                .setWarehouseId("-1")
                .setWarehouseName("航宇救生")
                .setLeafFlag("2"));
        list.add(node);
        if (CollectionUtils.isNotEmpty(warehouseList)) {
            CommonGenericTree<Warehouse> tcNode;
            for (Warehouse wh : warehouseList) {
                if (StrUtils.isBlankOrNull(wh.getParentId()) || wh.getParentId().equals("-1")) {
                    tcNode = new CommonGenericTree<>();
                    tcNode.setKey(wh.getId());
                    tcNode.setTitle(wh.getWarehouseId() + "/" + wh.getWarehouseName());
                    tcNode.setParentId(node.getKey());
                    tcNode.setIcon("");
                    tcNode.setType(1);
                    tcNode.setValue(wh.getWarehouseName());
                    //tcNode.setDisabled(CommonConstant.STATUS_0.equals(wh.getStatus()) ? true : false);
                    tcNode.setRField1(wh.getWarehouseId());
                    tcNode.setRField2(getBaseParent(wh.getId(), 0).getWarehouseId());
                    tcNode.setEntity(wh);
                    node.addChildren(tcNode);
                    map.put(wh.getId(), tcNode);
                }
            }
            CommonGenericTree<Warehouse> childNode;
            for (Warehouse wh : warehouseList) {
                Warehouse child = wh;
                if (map.containsKey(child.getParentId())) {
                    if (StrUtils.isBlankOrNull(wh.getParentId()) || wh.getParentId().equals("-1")) {
                        warehouse = wh;
                    } else {
                        tcNode = map.get(child.getParentId());
                        childNode = new CommonGenericTree<>();
                        childNode.setKey(wh.getId());
                        childNode.setTitle(wh.getWarehouseId() + "/" + wh.getWarehouseName());
                        childNode.setParentId(wh.getParentId());
                        childNode.setIcon("");
                        childNode.setType(0);
                        childNode.setValue(wh.getWarehouseName());
                        //childNode.setDisabled(CommonConstant.STATUS_0.equals(wh.getStatus()) ? true : false);
                        childNode.setRField1(wh.getWarehouseId());
                        childNode.setRField2(getBaseParent(wh.getId(), 0).getWarehouseId());
                        childNode.setEntity(wh);
                        tcNode.addChildren(childNode);
                        map.put(child.getId(), childNode);
                    }
                }
            }
        }
        return list;
    }
 
    public Warehouse getBaseParent(String id, int index) {
        Warehouse warehouse = null;
        if (index < 99) {
            warehouse = getById(id);
            if (StrUtils.isNotBlankOrNull(warehouse.getParentId())) {
                if (!warehouse.getParentId().equals("-1")) {
                    warehouse = getBaseParent(warehouse.getParentId(), index++);
                }
            }
        }
        return warehouse;
    }
}