燕山石化溯源三维电子沙盘-【后端】-服务
1
13693261870
2023-06-06 21ab1414c42db1ebec8389ba23ed320970e52442
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()) {