自动化立体仓库 - WMS系统
#
lsh
2024-01-13 3f194f5ef62ef33d16291540da3fc8f47fa9bc63
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
141
142
143
144
145
146
package com.zy.common.entity;
 
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.core.common.Cools;
import com.core.common.SpringUtils;
import com.core.exception.CoolException;
import com.zy.asrs.entity.Node;
import com.zy.asrs.mapper.NodeMapper;
import com.zy.asrs.service.NodeService;
import com.zy.common.utils.NodeUtils;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
 
public class NodeExcelListener extends AnalysisEventListener<NodeExcel> {
    private int total = 0;
    private Long userId;
    private Long hostId;
 
    public NodeExcelListener() {
    }
 
    public NodeExcelListener(Long userId, Long hostId) {
        this.userId = userId;
        this.hostId = hostId;
    }
 
    /**
     * 每隔5条存储数据库,实际使用中可以3000条,然后清理list ,方便内存回收
     */
    private static final int BATCH_COUNT = 50;
 
    private final List<NodeExcel> list = new ArrayList<>();
 
    /**
     * 这里会一行行的返回头
     */
    @Override
    public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) {
    }
 
    /**
     * 这个每一条数据解析都会来调用
     */
    @Override
    public void invoke(NodeExcel excel, AnalysisContext ctx) {
        NodeService nodeService = SpringUtils.getBean(NodeService.class);
        NodeMapper nodeMapper = SpringUtils.getBean(NodeMapper.class);
        Date now = new Date();
        Node top = nodeService.getTop();
        // 仓库
        if (!Cools.isEmpty(excel.getWarehouse())) {
            Node wareHouse = nodeService.selectByUuid(excel.getWarehouse(), hostId, 1, top.getId());
            if (wareHouse == null) {
                wareHouse = new Node();
                wareHouse.setHostId(this.hostId);
                wareHouse.setUuid(excel.getWarehouse());
                wareHouse.setName(excel.getWarehouse());
                wareHouse.setType(1);
                wareHouse.setParentId(top.getId());
                wareHouse.setParentName(top.getName());
                wareHouse.setLevel(top.getLevel() + 1);
                NodeUtils nodeUtils = new NodeUtils();
                nodeUtils.executePath(wareHouse);
                wareHouse.setPath(nodeUtils.path.toString());
                wareHouse.setNamePath(nodeUtils.pathName.toString());
                wareHouse.setStatus(1);
                wareHouse.setCreateTime(now);
                wareHouse.setUpdateTime(now);
                if (nodeMapper.insert(wareHouse) == 0) {
                    throw new CoolException("保存仓库数据失败");
                }
                total ++;
            }
 
            // 库区
            if (!Cools.isEmpty(excel.getArea())) {
                Node area = nodeService.selectByUuid(excel.getArea(), hostId, 2, wareHouse.getId());
                if (area == null) {
                    area = new Node();
                    area.setHostId(this.hostId);
                    area.setUuid(excel.getArea());
                    area.setName(excel.getArea());
                    area.setType(2);
                    area.setParentId(wareHouse.getId());
                    area.setParentName(wareHouse.getName());
                    area.setLevel(wareHouse.getLevel() + 1);
                    NodeUtils nodeUtils = new NodeUtils();
                    nodeUtils.executePath(area);
                    area.setPath(nodeUtils.path.toString());
                    area.setNamePath(nodeUtils.pathName.toString());
                    area.setStatus(1);
                    area.setCreateTime(now);
                    area.setUpdateTime(now);
                    if (nodeMapper.insert(area) == 0) {
                        throw new CoolException("保存库区数据失败");
                    }
                    total ++;
                }
 
                // 货位
                if (!Cools.isEmpty(excel.getAllo())) {
                    Node allo = nodeService.selectByUuid(excel.getAllo(), hostId, 3);
                    if (allo == null) {
                        allo = new Node();
                        allo.setHostId(this.hostId);
                        allo.setUuid(excel.getAllo());
                        allo.setName(excel.getAllo());
                        allo.setType(3);
                        allo.setParentId(area.getId());
                        allo.setParentName(area.getName());
                        allo.setLevel(area.getLevel() + 1);
                        NodeUtils nodeUtils = new NodeUtils();
                        nodeUtils.executePath(allo);
                        allo.setPath(nodeUtils.path.toString());
                        allo.setNamePath(nodeUtils.pathName.toString());
                        allo.setStatus(1);
                        allo.setCreateTime(now);
                        allo.setUpdateTime(now);
                        if (nodeMapper.insert(allo) == 0) {
                            throw new CoolException("保存货位数据失败");
                        }
                        total ++;
                    }
                }
 
            }
        }
    }
 
    /**
     * 所有数据解析完成了调用
     * 适合事务
     */
    @Override
    public void doAfterAllAnalysed(AnalysisContext ctx) {
        //log.info("新增{}条物料信息!", total);
    }
 
    public int getTotal() {
        return total;
    }
}