From 2f55cebbad3dea187a5f91d16ec80a9677dab699 Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期三, 13 十一月 2024 11:16:53 +0800 Subject: [PATCH] 1 --- src/main/java/com/yssh/config/ScheduleConfig.java | 102 ++++++++++++++++++++++++++++++++++++--------------- 1 files changed, 72 insertions(+), 30 deletions(-) diff --git a/src/main/java/com/yssh/config/ScheduleConfig.java b/src/main/java/com/yssh/config/ScheduleConfig.java index 8058abd..3d0f8cc 100644 --- a/src/main/java/com/yssh/config/ScheduleConfig.java +++ b/src/main/java/com/yssh/config/ScheduleConfig.java @@ -15,15 +15,15 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.Scheduled; -import org.springframework.stereotype.Component; import com.github.biyanwen.EasyCsv; import javax.annotation.Resource; -@Component +@Configuration @EnableScheduling public class ScheduleConfig { protected final Logger logger = LoggerFactory.getLogger(this.getClass()); @@ -44,7 +44,10 @@ WarningAnalyseService warningAnalyseService; @Resource - XlsExportService xlsExportService; + XlsReportService xlsReportService; + + @Resource + EmailService emailService; @Value("${csv.voc_max}") private int vocMax = 96; @@ -52,27 +55,35 @@ @Value("${csv.cron_max}") private int cronMax = 48; - private static boolean isBusy = false; + @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() { - if (isBusy) return; + synchronized (OBJ) { + if (flag) return; + flag = true; + } - isBusy = true; logger.info("***************** 寮�濮嬫墽琛孋SV鍏ュ簱 *****************" + "\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"; @@ -101,7 +112,7 @@ } } logger.info("***************** CSV鍏ュ簱鎵ц瀹屾垚 *****************" + "\n"); - isBusy = false; + flag = false; } public Calendar getCalendar(int start) { @@ -124,7 +135,7 @@ private void loadVocSync() { logger.info("***************** 寮�濮嬪叏鍩烠SV鍏ュ簱 *****************" + "\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,27 +201,57 @@ warningAnalyseService.warningOperationStorage(date); } - /** - * 鍒涘缓鏃ユ姤锛氭瘡鏃�0鏃�1鍒� - */ @Scheduled(cron = "0 1 0 * * ?") public void createDayReport() { - xlsExportService.createDayReport(new Date()); + Calendar calendar = getCalendar(1); + for (int i = 0; i < 31; i++) { + try { + calendar.add(Calendar.DATE, -1); + xlsReportService.createDayReport(calendar.getTime()); + // System.out.println(DateUtils.getYyyyMmDd(calendar.getTime())); + } catch (Exception ex) { + logger.error(ex.getMessage(), ex); + } + } } - /** - * 鍒涘缓鍛ㄦ姤锛氭瘡鍛ㄤ竴0鏃�5鍒� - */ @Scheduled(cron = "0 5 0 ? * MON") public void createWeekReport() { - xlsExportService.createWeekReport(new Date()); + Calendar calendar = getCalendar(7 * 24); + for (int i = 1; i < 8; i++) { + try { + calendar.add(Calendar.DATE, -7); + xlsReportService.createWeekReport(calendar.getTime()); + // System.out.println(DateUtils.getYyyyMmDd(calendar.getTime())); + } catch (Exception ex) { + logger.error(ex.getMessage(), ex); + } + } } - /** - * 鍒涘缓鏈堟姤锛氭瘡鏈�1鏃�0鏃�9鍒� - */ @Scheduled(cron = "0 9 0 1 * ?") public void createMonthReport() { - xlsExportService.createMonthReport(new Date()); + Calendar calendar = Calendar.getInstance(); + calendar.setTime(new Date()); + calendar.add(Calendar.MONTH, 1); + for (int i = 0; i < 6; i++) { + try { + calendar.add(Calendar.MONTH, -1); + xlsReportService.createMonthReport(calendar.getTime()); + // System.out.println(DateUtils.getYyyyMmDd(calendar.getTime())); + } catch (Exception ex) { + logger.error(ex.getMessage(), ex); + } + } + } + + //@Scheduled(cron = "${email.times}") + public void autoCalcData() { + if (enableEmail) { + //System.out.println("${email.times}"); + logger.info("***************** 寮�濮嬫暟鎹璀﹁绠� *****************" + "\n"); + emailService.calcData(); + logger.info("***************** 鏁版嵁棰勮璁$畻瀹屾垚 *****************" + "\n"); + } } } -- Gitblit v1.9.3