From 21ab1414c42db1ebec8389ba23ed320970e52442 Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期二, 06 六月 2023 10:21:13 +0800
Subject: [PATCH] 1

---
 src/main/resources/application-scheduled.yml      |    3 +
 src/main/java/com/yssh/scheduled/ReadCsvTask.java |   58 ++++++++++++++++++-----------
 2 files changed, 38 insertions(+), 23 deletions(-)

diff --git a/src/main/java/com/yssh/scheduled/ReadCsvTask.java b/src/main/java/com/yssh/scheduled/ReadCsvTask.java
index 355ced9..05c0bf9 100644
--- a/src/main/java/com/yssh/scheduled/ReadCsvTask.java
+++ b/src/main/java/com/yssh/scheduled/ReadCsvTask.java
@@ -9,7 +9,7 @@
 
 import com.yssh.entity.VocVals;
 import com.yssh.service.VocValsService;
-import com.yssh.utils.VocParser;
+import com.yssh.utils.*;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -23,25 +23,21 @@
 import com.yssh.service.IDictRecordService;
 import com.yssh.service.IWarningAnalyseService;
 import com.yssh.service.impl.SuYuanServiceImpl;
-import com.yssh.utils.CsvParser;
-import com.yssh.utils.DateUtils;
-import com.yssh.utils.TableStrategy;
 
 import javax.annotation.Resource;
 
 @Component
 public class ReadCsvTask {
-
 	protected final Log logger = LogFactory.getLog(this.getClass());
 
-	@Autowired
-	private CsvFilePathConfig csvFilePathConfig;
+	@Resource
+	private VocValsService vocValsService;
 
 	@Autowired
 	private SuYuanServiceImpl suYuanService;
 
-	@Resource
-	private VocValsService vocValsService;
+	@Autowired
+	private CsvFilePathConfig csvFilePathConfig;
 
 	@Autowired
 	private IDictRecordService dictRecordService;
@@ -49,17 +45,17 @@
 	@Autowired
 	private IWarningAnalyseService warningAnalyseService;
 
-	private final static SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHH");
-
 	private final static List<String> md5List = new ArrayList<>();
 
-	@Scheduled(cron = "${csv.cron}")
+	private final static SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHH");
+
 	public void corpReserveDataSync() {
-		loadVoc();
-		loadCsv();
+		loadVocSync();
+		loadCsvSync();
 	}
 
-	private void loadVoc() {
+	@Scheduled(cron = "${csv.voc}")
+	private void loadVocSync() {
 		vocValsService.deleteLastYear();
 		Calendar calendar = getCalendar(96);
 		for (int i = 0; i < 192; i++) {
@@ -73,21 +69,39 @@
 				continue;
 			}
 
-			int count = vocValsService.countByTime(time);
-			if (count > 0) {
-				//continue;
+			String md5 = FileUtils.getFileMd5(filePath);
+			if (null != md5 && md5List.contains(md5)) {
+				continue; // csv宸插叆搴�
 			}
 
-			EasyCsv.read(filePath, VocVals.class, new VocParser(vocValsService, calendar.getTime())).doRead();
+			int count = vocValsService.countByTime(time);
+			if (count > 0) {
+				vocValsService.deleteByTime(time); // 鍒犻櫎宸插叆搴�
+			}
+			addFileMd5(md5);
+
+			try {
+				EasyCsv.read(filePath, VocVals.class, new VocParser(vocValsService, calendar.getTime())).doRead();
+			} catch (Exception e) {
+				logger.error(e);
+			}
 		}
 	}
 
-	private void loadCsv() {
+	private void addFileMd5(String md5) {
+		md5List.add(md5);
+		if (md5List.size() > 512) {
+			md5List.remove(0);
+		}
+	}
+
+	@Scheduled(cron = "${csv.cron}")
+	private void loadCsvSync() {
 		Calendar calendar = getCalendar(1);
-		for (int i = 0; i < 25; i++) {
+		for (int i = 0; i < 49; i++) {
 			calendar.add(Calendar.HOUR, -1);
 			String time = format.format(calendar.getTime());
-			String filePath = csvFilePathConfig.getFilePath() + "\\\\" + time + ".csv";
+			String filePath = csvFilePathConfig.getFilePath() + File.separator + time + ".csv";
 
 			File file = new File(filePath);
 			if (!file.exists()) {
diff --git a/src/main/resources/application-scheduled.yml b/src/main/resources/application-scheduled.yml
index e2610dd..f469379 100644
--- a/src/main/resources/application-scheduled.yml
+++ b/src/main/resources/application-scheduled.yml
@@ -1,2 +1,3 @@
 csv: 
-  cron: '0 5 * * * ? '
+  cron: '0 18 * * * ? '
+  voc: '0 19 10 * * ? '

--
Gitblit v1.9.3