From 2b75d84cabc3416d903f425239c713b65a98503f Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期五, 01 十一月 2024 13:17:38 +0800 Subject: [PATCH] 1 --- src/main/java/com/yssh/utils/CsvParser.java | 85 ++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 85 insertions(+), 0 deletions(-) diff --git a/src/main/java/com/yssh/utils/CsvParser.java b/src/main/java/com/yssh/utils/CsvParser.java new file mode 100644 index 0000000..0fc343d --- /dev/null +++ b/src/main/java/com/yssh/utils/CsvParser.java @@ -0,0 +1,85 @@ +package com.yssh.utils; + +import java.util.ArrayList; +import java.util.List; + +import com.yssh.entity.AlertConfig; +import com.yssh.entity.SuYuan; +import com.yssh.mapper.AlertConfigMapper; +import com.yssh.service.SuYuanService; + +import com.github.biyanwen.impl.AbstractCsvFileParser; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.annotation.Resource; + +public class CsvParser extends AbstractCsvFileParser<SuYuan> { + protected final Logger logger = LoggerFactory.getLogger(this.getClass()); + + /** + * 姣忛殧100000鏉″瓨鍌ㄦ暟鎹簱锛岀劧鍚庢竻鐞唋ist 锛屾柟渚垮唴瀛樺洖鏀� + */ + public static final int BATCH_COUNT = 100000; + + /** + * 缂撳瓨鐨勬暟鎹� + */ + private List<SuYuan> cachedData = new ArrayList<>(BATCH_COUNT); + + private SuYuanService suYuanService; + + private String time; + + private double jcyj; + + public CsvParser(SuYuanService suYuanService, String time) { + this.suYuanService = suYuanService; + this.time = time; + this.jcyj = suYuanService.getJcyj(); + } + + /** + * 鎵�鏈夋暟鎹В鏋愬畬鎴愪簡 浼氭潵璋冪敤,闃叉鏈夋暟鎹病鏈夎淇濆瓨 + */ + protected void doAfterAllAnalysed() { + try { + saveSuYuanData(); + } catch (Exception e) { + logger.error("瑙f瀽淇濆瓨鏁版嵁鍑虹幇寮傚父锛屽紓甯稿師鍥犳槸锛�" + e.getMessage(), e); + e.printStackTrace(); + } + } + + protected void invoke(SuYuan t) { + t.setId(t.getX() + "_" + t.getY() + "_" + t.getZ()); + /*if ("0_0_0".equals(t.getId())) { + return; // 瑙e喅涓婚敭閲嶅 + }*/ + /*if (t.getZ() > 0 && t.getC() < jcyj) { + return; // 鍙叆绗�0灞傛暟鎹�+Voc鍊煎ぇ浜�1 + }*/ + + // 鍙叆鍊� > =0.05 + if (t.getC() < 0.1) { + return; + } + + cachedData.add(t); + // 杈惧埌BATCH_COUNT浜嗭紝闇�瑕佸幓瀛樺偍涓�娆℃暟鎹簱锛岄槻姝㈡暟鎹嚑涓囨潯鏁版嵁鍦ㄥ唴瀛橈紝瀹规槗OOM + if (cachedData.size() >= BATCH_COUNT) { + try { + saveSuYuanData(); + } catch (Exception e) { + logger.error("瑙f瀽淇濆瓨鏁版嵁鍑虹幇寮傚父锛屽紓甯稿師鍥犳槸锛�" + e.getMessage(), e); + e.printStackTrace(); + } + // 瀛樺偍瀹屾垚娓呯悊 list + cachedData = new ArrayList<>(BATCH_COUNT); + } + } + + private void saveSuYuanData() throws Exception { + suYuanService.insertSuYuanDatas(cachedData, time); + } +} -- Gitblit v1.9.3