燕山石化溯源三维电子沙盘-【后端】-服务
1
13693261870
2023-06-16 5b17ccbbe08971f861ff097c62241d2b79e4b5f6
src/main/java/com/yssh/scheduled/ReadCsvTask.java
@@ -12,6 +12,7 @@
import com.yssh.utils.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@@ -44,6 +45,12 @@
   @Resource
   private IWarningAnalyseService warningAnalyseService;
   @Value("${csv.cron_max}")
   private int cronMax = 48;
   @Value("${csv.voc_max}")
   private int vocMax = 120;
   private final static List<String> md5List = new ArrayList<>();
   private final static SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHH");
@@ -57,7 +64,7 @@
   private void loadVocSync() {
      vocValsService.deleteLastYear();
      Calendar calendar = getCalendar(96);
      for (int i = 0; i < 192; i++) {
      for (int i = 0; i < cronMax; i++) {
         calendar.add(Calendar.HOUR, -1);
         String time = format.format(calendar.getTime());
         String filePath = csvFilePathConfig.getVocPath() + File.separator + time + ".csv";
@@ -80,8 +87,11 @@
         addFileMd5(md5);
         try {
            logger.info("loadVocSync:" + filePath);
            EasyCsv.read(filePath, VocVals.class, new VocParser(vocValsService, calendar.getTime())).doRead();
            logger.info("loadVocSync: " + filePath);
            Date date = (Date) calendar.getTime().clone();
            EasyCsv.read(filePath, VocVals.class, new VocParser(vocValsService, date)).doRead();
            // Thread.sleep(3 * 1000);
         } catch (Exception e) {
            logger.error(e.getMessage(), e);
         }
@@ -98,7 +108,7 @@
   @Scheduled(cron = "${csv.cron}")
   private void loadCsvSync() {
      Calendar calendar = getCalendar(1);
      for (int i = 0; i < 49; i++) {
      for (int i = 0; i < vocMax; i++) {
         calendar.add(Calendar.HOUR, -1);
         String time = format.format(calendar.getTime());
         String filePath = csvFilePathConfig.getFilePath() + File.separator + time + ".csv";
@@ -117,18 +127,23 @@
         }
         suYuanService.createNewTable(newTableName);
         dictRecordService.insertDictRecord(new DictRecord(1L, newTableName, Long.parseLong(time), ""));
         logger.info("loadCsvSync:" + filePath);
         Long createTime = Long.parseLong(time);
         DictRecord dr = dictRecordService.selectByCreateTime(createTime);
         if (null == dr) {
            dictRecordService.insertDictRecord(new DictRecord(1L, newTableName, Long.parseLong(time), ""));
         }
         logger.info("loadCsvSync: " + filePath);
         EasyCsv.read(filePath, SuYuan.class, new CsvParser(suYuanService, time)).doRead();
         try {
            // 计算预警/报警,并且进行入库操作
            Thread.sleep(2 * 60 * 1000);
         } catch (InterruptedException e) {
            logger.error("睡眠一分钟后执行预警/报警计算,并且进行入库操作出现异常,异常原因是:", e);
            e.printStackTrace();
         }
//         try {
//            // 计算预警/报警,并且进行入库操作
//            Thread.sleep(2 * 60 * 1000);
//         } catch (InterruptedException e) {
//            logger.error("睡眠一分钟后执行预警/报警计算,并且进行入库操作出现异常,异常原因是:", e);
//            e.printStackTrace();
//         }
         warningAnalyseService.warningOperationStorage(calendar.getTime());
      }
   }