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();
|
}
|
}
|
}
|