燕山石化溯源三维电子沙盘-【后端】-服务
1
13693261870
2024-11-13 2f55cebbad3dea187a5f91d16ec80a9677dab699
src/main/java/com/yssh/config/ScheduleConfig.java
@@ -58,22 +58,32 @@
   @Value("${email.enable}")
   private Boolean enableEmail;
   private static boolean flag = false;
   private static final Object OBJ = new Object();
   private final static List<String> md5List = new ArrayList<>();
   private final static SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHH");
   public void corpReserveDataSync() {
      loadVocSync();
      //loadVocSync();
      loadCsvSync();
   }
   @Scheduled(cron = "${csv.cron}")
   private void loadCsvSync() {
      synchronized (OBJ) {
         if (flag) return;
         flag = true;
      }
      logger.info("***************** 开始执行CSV入库 *****************" + "\n");
      Calendar calendar = getCalendar(1);
      calendar.add(Calendar.HOUR, -cronMax);
      for (int i = 0; i < cronMax; i++) {
         try {
            calendar.add(Calendar.HOUR, -1);
            calendar.add(Calendar.HOUR, 1);
            String time = format.format(calendar.getTime());
            String filePath = csvFilePathConfig.getFilePath() + File.separator + time + ".csv";
@@ -102,6 +112,7 @@
         }
      }
      logger.info("***************** CSV入库执行完成 *****************" + "\n");
      flag = false;
   }
   public Calendar getCalendar(int start) {
@@ -124,7 +135,7 @@
   private void loadVocSync() {
      logger.info("***************** 开始全域CSV入库 *****************" + "\n");
      vocValsService.deleteLastYear();
      Calendar calendar = getCalendar(96);
      Calendar calendar = getCalendar(vocMax);
      for (int i = 0; i < vocMax; i++) {
         calendar.add(Calendar.HOUR, -1);
         String time = format.format(calendar.getTime());
@@ -136,18 +147,19 @@
            continue;
         }
         String md5 = FileUtils.getFileMd5(filePath);
         if (null != md5 && md5List.contains(md5)) {
            continue; // csv已入库
         }
         //String md5 = FileUtils.getFileMd5(filePath);
         //if (null != md5 && md5List.contains(md5)) {
         //   continue;
         //}
         int count = vocValsService.countByTime(time);
         if (count > 0) {
            vocValsService.deleteByTime(time); // 删除已入库
            //vocValsService.deleteByTime(time);
            continue;
         }
         try {
            addFileMd5(md5);
            //addFileMd5(md5);
            logger.info("loadVocSync: " + filePath);
            Date date = (Date) calendar.getTime().clone();
            EasyCsv.read(filePath, VocVals.class, new VocParser(vocValsService, date)).doRead();
@@ -174,12 +186,12 @@
         logger.info(file.getAbsolutePath() + " is not exist !");
         return;
      }
      //创建表
      String newTableName = TableStrategy.getTableStrategy(time);
      suYuanService.createNewTable(newTableName);
      dictRecordService.insertDictRecord(new DictRecord(1L, newTableName, Long.parseLong(time), ""));
      EasyCsv.read(filePath, SuYuan.class, new CsvParser(suYuanService, time)).doRead();
      //计算预警/报警,并且进行入库操作
      try {
         Thread.sleep(60 * 1000);
      } catch (InterruptedException e) {
@@ -189,9 +201,6 @@
      warningAnalyseService.warningOperationStorage(date);
   }
   /**
    * 创建日报:每日0时1分
    */
   @Scheduled(cron = "0 1 0 * * ?")
   public void createDayReport() {
      Calendar calendar = getCalendar(1);
@@ -206,9 +215,6 @@
      }
   }
   /**
    * 创建周报:每周一0时5分
    */
   @Scheduled(cron = "0 5 0 ? * MON")
   public void createWeekReport() {
      Calendar calendar = getCalendar(7 * 24);
@@ -223,9 +229,6 @@
      }
   }
   /**
    * 创建月报:每月1日0时9分
    */
   @Scheduled(cron = "0 9 0 1 * ?")
   public void createMonthReport() {
      Calendar calendar = Calendar.getInstance();
@@ -242,7 +245,7 @@
      }
   }
   @Scheduled(cron = "${email.times}")
   //@Scheduled(cron = "${email.times}")
   public void autoCalcData() {
      if (enableEmail) {
         //System.out.println("${email.times}");