燕山石化溯源三维电子沙盘-【后端】-服务
13693261870
2023-06-05 1198ea43ca127f0a14968d5d57b544a7a2d0cde7
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
package com.yssh.utils;
 
import com.github.biyanwen.impl.AbstractCsvFileParser;
import com.yssh.entity.VocVals;
import com.yssh.service.VocValsService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
 
import java.math.BigInteger;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
/**
 * VOC转换类
 * @author WWW
 * @date 2023-06-05
 */
public class VocParser extends AbstractCsvFileParser<VocVals> {
    protected final Log logger = LogFactory.getLog(this.getClass());
 
    private final SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHH0000");
 
    /**
     * 每隔5000条入库一次
     */
    public static final int BATCH_COUNT = 100000;
 
    private BigInteger startId;
 
    private VocValsService vocValsService;
 
    private Date date;
 
    private List<VocVals> list = new ArrayList<>(BATCH_COUNT);
 
    public VocParser(VocValsService vocValsService, Date date) {
        this.vocValsService = vocValsService;
        this.date = date;
        this.startId = new BigInteger(format.format(date));
    }
 
    public BigInteger getId() {
        startId = startId.add(BigInteger.valueOf(1));
 
        return startId;
    }
 
    @Override
    protected void doAfterAllAnalysed() {
        inserts();
    }
 
    @Override
    protected void invoke(VocVals vv) {
        if (null == vv.getX() || vv.getX() < 0 || null == vv.getY() || vv.getY() < 0 || null == vv.getVal() || vv.getVal() <= 0) {
            return;
        }
 
        vv.setCreateTime(this.date);
        vv.setId(getId());
        list.add(vv);
 
        if (list.size() >= BATCH_COUNT) {
            inserts();
            list = new ArrayList<>(BATCH_COUNT);
        }
    }
 
    private void inserts() {
        try {
            if (list.size() > 0) {
                this.vocValsService.insertVocVals(list);
            }
        } catch (Exception e) {
            logger.error(e.getMessage());
            e.printStackTrace();
        }
    }
}