燕山石化溯源三维电子沙盘-【后端】-服务
1
13693261870
2023-05-24 5c49c6f9a7e377bb46f7cb617f72b11fc17d5331
src/main/java/com/yssh/utils/CsvParser.java
@@ -12,27 +12,27 @@
import com.yssh.entity.SuYuan;
import com.yssh.service.ISuYuanService;
public class CsvParser extends AbstractCsvFileParser<SuYuan>{
public class CsvParser extends AbstractCsvFileParser<SuYuan> {
   protected final Log logger = LogFactory.getLog(this.getClass());
   /**
    * 每隔3000条存储数据库,然后清理list ,方便内存回收
    */
   public static final int BATCH_COUNT = 100000;
   /**
    * 缓存的数据
    */
   private List<SuYuan> cachedData = new ArrayList<>(BATCH_COUNT);
   private ISuYuanService suYuanService;
   private String time;
   public CsvParser(ISuYuanService suYuanService, String time) {
      this.suYuanService = suYuanService;
      this.time = time;
   }
   /**
    * 所有数据解析完成了 会来调用,防止有数据没有被保存
    */
@@ -49,6 +49,10 @@
   @Override
   protected void invoke(SuYuan t) {
      t.setId(t.getX() + "_" + t.getY() + "_" + t.getZ());
      if ("0_0_0".equals(t.getId())) {
         return; // 解决主键重复
      }
      //System.err.println(t.getId());
      cachedData.add(t);
      // 达到BATCH_COUNT了,需要去存储一次数据库,防止数据几万条数据在内存,容易OOM
@@ -67,5 +71,4 @@
   private void saveSuYuanData() throws Exception {
      suYuanService.insertSuYuanDatas(cachedData, time);
   }
}