燕山石化溯源三维电子沙盘-【后端】-服务
13693261870
2023-06-09 498718ad129e8a9010e6f2af2fde2f9d4508fd32
src/main/java/com/yssh/scheduled/ReadCsvTask.java
@@ -9,10 +9,9 @@
import com.yssh.entity.VocVals;
import com.yssh.service.VocValsService;
import com.yssh.utils.VocParser;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import com.yssh.utils.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@@ -23,43 +22,39 @@
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;
   @Autowired
   private SuYuanServiceImpl suYuanService;
   protected final Logger logger = LoggerFactory.getLogger(this.getClass());
   @Resource
   private VocValsService vocValsService;
   @Autowired
   @Resource
   private SuYuanServiceImpl suYuanService;
   @Resource
   private CsvFilePathConfig csvFilePathConfig;
   @Resource
   private IDictRecordService dictRecordService;
   @Autowired
   @Resource
   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++) {
@@ -69,29 +64,48 @@
         File file = new File(filePath);
         if (!file.exists()) {
            logger.error(file.getAbsolutePath() + " is not exist !");
            logger.info(file.getAbsolutePath() + " is not exist !");
            continue;
         }
         String md5 = FileUtils.getFileMd5(filePath);
         if (null != md5 && md5List.contains(md5)) {
            continue; // csv已入库
         }
         int count = vocValsService.countByTime(time);
         if (count > 0) {
            //continue;
            vocValsService.deleteByTime(time); // 删除已入库
         }
         addFileMd5(md5);
         EasyCsv.read(filePath, VocVals.class, new VocParser(vocValsService, calendar.getTime())).doRead();
         try {
            logger.info("loadVocSync:" + filePath);
            EasyCsv.read(filePath, VocVals.class, new VocParser(vocValsService, calendar.getTime())).doRead();
         } catch (Exception e) {
            logger.error(e.getMessage(), 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()) {
            logger.error(file.getAbsolutePath() + " is not exist !");
            logger.info(file.getAbsolutePath() + " is not exist !");
            continue;
         }
@@ -104,11 +118,13 @@
         suYuanService.createNewTable(newTableName);
         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(60000);
            Thread.sleep(10000); // 60000
         } catch (InterruptedException e) {
            logger.error("睡眠一分钟后执行预警/报警计算,并且进行入库操作出现异常,异常原因是:", e);
            e.printStackTrace();
@@ -136,7 +152,7 @@
      String filePath = csvFilePathConfig.getFilePath() + "\\\\" + time + ".csv";
      File file = new File(filePath);
      if (!file.exists()) {
         logger.error(file.getAbsolutePath() + " is not exist !");
         logger.info(file.getAbsolutePath() + " is not exist !");
         return;
      }
      //创建表