¶Ô±ÈÐÂÎļþ |
| | |
| | | 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æ¡å卿°æ®åºï¼ç¶åæ¸
çlist ï¼æ¹ä¾¿å
ååæ¶ |
| | | */ |
| | | 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("è§£æä¿åæ°æ®åºç°å¼å¸¸ï¼å¼å¸¸åå æ¯ï¼" + 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; // è§£å³ä¸»é®éå¤ |
| | | }*/ |
| | | /*if (t.getZ() > 0 && t.getC() < jcyj) { |
| | | return; // åªå
¥ç¬¬0屿°æ®+Vocå¼å¤§äº1 |
| | | }*/ |
| | | |
| | | // åªå
¥å¼ > =0.05 |
| | | if (t.getC() < 0.01) { |
| | | return; |
| | | } |
| | | |
| | | cachedData.add(t); |
| | | // è¾¾å°BATCH_COUNTäºï¼éè¦å»åå¨ä¸æ¬¡æ°æ®åºï¼é²æ¢æ°æ®å 䏿¡æ°æ®å¨å
åï¼å®¹æOOM |
| | | if (cachedData.size() >= BATCH_COUNT) { |
| | | try { |
| | | saveSuYuanData(); |
| | | } catch (Exception e) { |
| | | logger.error("è§£æä¿åæ°æ®åºç°å¼å¸¸ï¼å¼å¸¸åå æ¯ï¼" + e.getMessage(), e); |
| | | e.printStackTrace(); |
| | | } |
| | | // åå¨å®ææ¸
ç list |
| | | cachedData = new ArrayList<>(BATCH_COUNT); |
| | | } |
| | | } |
| | | |
| | | private void saveSuYuanData() throws Exception { |
| | | suYuanService.insertSuYuanDatas(cachedData, time); |
| | | } |
| | | } |