From aaa42c070d59c46ff0ed42a1d2748df6dd6a06d7 Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期一, 05 六月 2023 16:05:22 +0800 Subject: [PATCH] 添加Voc操作接口 --- src/main/java/com/yssh/scheduled/ReadCsvTask.java | 94 ++++++++++++++++++++++++++++++---------------- 1 files changed, 61 insertions(+), 33 deletions(-) diff --git a/src/main/java/com/yssh/scheduled/ReadCsvTask.java b/src/main/java/com/yssh/scheduled/ReadCsvTask.java index ab36e89..89732a4 100644 --- a/src/main/java/com/yssh/scheduled/ReadCsvTask.java +++ b/src/main/java/com/yssh/scheduled/ReadCsvTask.java @@ -8,8 +8,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; @@ -43,43 +41,36 @@ @Autowired private IWarningAnalyseService warningAnalyseService; + private final SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHH"); + @Scheduled(cron = "${csv.cron}") public void corpReserveDataSync() { - /*Date date = DateUtils.getNowDate(); - String time = DateUtils.parseDateToStr(DateUtils.YYYYMMDDHH, date); - String filePath = csvFilePathConfig.getFilePath() + "\\\\" + time + ".csv"; - File file = new File(filePath); - if (!file.exists()) { - logger.error(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(1000 * 60 * 1); - } catch (InterruptedException e) { - logger.error("鐫$湢涓�鍒嗛挓鍚庢墽琛岄璀�/鎶ヨ璁$畻,骞朵笖杩涜鍏ュ簱鎿嶄綔鍑虹幇寮傚父锛屽紓甯稿師鍥犳槸锛�", e); - e.printStackTrace(); + loadVoc(); + loadCsv(); + } + + private void loadVoc() { + Calendar calendar = getCalendar(96); + for (int i = 0; i < 192; i++) { + calendar.add(Calendar.HOUR, -1); + String time = format.format(calendar.getTime()); + String filePath = csvFilePathConfig.getVocPath() + File.separator + time + ".csv"; + + File file = new File(filePath); + if (!file.exists()) { + logger.error(file.getAbsolutePath() + " is not exist 锛�"); + continue; + } + + } - warningAnalyseService.warningOperationStorage(date);*/ + } - SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHH"); - Calendar calendar = Calendar.getInstance(); - calendar.setTime(new Date()); - calendar.add(Calendar.HOUR, 1); - - // 娴嬭瘯 -> 2023-04-23 19:00 - //calendar.set(Calendar.MONTH, 3); - //calendar.set(Calendar.DAY_OF_MONTH, 23); - //calendar.set(Calendar.HOUR_OF_DAY, 20); - + private void loadCsv() { + Calendar calendar = getCalendar(1); for (int i = 0; i < 25; i++) { calendar.add(Calendar.HOUR, -1); - String time = dateFormat.format(calendar.getTime()); + String time = format.format(calendar.getTime()); String filePath = csvFilePathConfig.getFilePath() + "\\\\" + time + ".csv"; File file = new File(filePath); @@ -109,4 +100,41 @@ warningAnalyseService.warningOperationStorage(calendar.getTime()); } } + + private Calendar getCalendar(int start) { + Calendar calendar = Calendar.getInstance(); + calendar.setTime(new Date()); + calendar.add(Calendar.HOUR, start); + + // 娴嬭瘯 -> 2023-04-23 19:00 + //calendar.set(Calendar.MONTH, 3); + //calendar.set(Calendar.DAY_OF_MONTH, 23); + //calendar.set(Calendar.HOUR_OF_DAY, 20); + + return calendar; + } + + private void loadCsv_old() { + Date date = DateUtils.getNowDate(); + String time = DateUtils.parseDateToStr(DateUtils.YYYYMMDDHH, date); + String filePath = csvFilePathConfig.getFilePath() + "\\\\" + time + ".csv"; + File file = new File(filePath); + if (!file.exists()) { + logger.error(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(1000 * 60 * 1); + } catch (InterruptedException e) { + logger.error("鐫$湢涓�鍒嗛挓鍚庢墽琛岄璀�/鎶ヨ璁$畻,骞朵笖杩涜鍏ュ簱鎿嶄綔鍑虹幇寮傚父锛屽紓甯稿師鍥犳槸锛�", e); + e.printStackTrace(); + } + warningAnalyseService.warningOperationStorage(date); + } } -- Gitblit v1.9.3