对比新文件 |
| | |
| | | package com.yssh.utils; |
| | | |
| | | import com.github.biyanwen.impl.AbstractCsvFileParser; |
| | | import com.yssh.entity.VocVals; |
| | | import com.yssh.service.VocValsService; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | |
| | | import java.math.BigInteger; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | public class VocParser extends AbstractCsvFileParser<VocVals> { |
| | | protected final Logger logger = LoggerFactory.getLogger(this.getClass()); |
| | | |
| | | private final SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHH0000"); |
| | | |
| | | 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); |
| | | this.vocValsService.insertVocSync(list); |
| | | } |
| | | } catch (Exception e) { |
| | | logger.error(e.getMessage(), e); |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |