自动化立体仓库 - WMS系统
LSH
2023-08-29 1aae6f4bd840a202ee9db3efa3f6776cd10b81f9
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
package com.zy.asrs.utils;
 
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.Mat;
import com.zy.asrs.entity.Tag;
import com.zy.asrs.mapper.TagMapper;
import com.zy.asrs.service.MatService;
import com.zy.asrs.service.TagService;
import com.zy.common.entity.MatExcel;
import com.zy.common.utils.NodeUtils;
import lombok.extern.slf4j.Slf4j;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
 
@Slf4j
public class MatExcel2Listener extends AnalysisEventListener<MatExcel> {
    private int total = 0;
    private Long userId;
 
    public MatExcel2Listener() {
    }
 
    public MatExcel2Listener(Long userId) {
        this.userId = userId;
    }
 
    /**
     * 每隔5条存储数据库,实际使用中可以3000条,然后清理list ,方便内存回收
     */
    private static final int BATCH_COUNT = 50;
 
    private final List<MatExcel> list = new ArrayList<>();
 
    /**
     * 这里会一行行的返回头
     */
    @Override
    public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) {
    }
 
    /**
     * 这个每一条数据解析都会来调用
     */
    @Override
    public void invoke(MatExcel excel, AnalysisContext ctx) {
        MatService matService = SpringUtils.getBean(MatService.class);
        Date now = new Date();
        // 商品
        Mat mat = matService.selectByMatnr(excel.getMatnr());
        if (mat != null) {
            mat.setMatnrNew(excel.getMatnrNew());
            mat.setUpdateBy(this.userId);
            mat.setUpdateTime(now);
            if (matService.updateById(mat)) {
                total++;
            }
        }
    }
 
    /**
     * 所有数据解析完成了调用
     * 适合事务
     */
    @Override
    public void doAfterAllAnalysed(AnalysisContext ctx) {
        log.info("同步{}条物料信息!", total);
    }
 
    public int getTotal() {
        return total;
    }
}