| | |
| | | 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()); |
| | |
| | | @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"; |
| | | |
| | |
| | | } |
| | | } |
| | | logger.info("***************** CSV入库执行完成 *****************" + "\n"); |
| | | flag = false; |
| | | } |
| | | |
| | | public Calendar getCalendar(int start) { |
| | |
| | | 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()); |
| | |
| | | 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; // csv已入库 |
| | | //} |
| | | |
| | | 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(); |
| | |
| | | } |
| | | } |
| | | |
| | | @Scheduled(cron = "${email.times}") |
| | | //@Scheduled(cron = "${email.times}") |
| | | public void autoCalcData() { |
| | | if (enableEmail) { |
| | | //System.out.println("${email.times}"); |
| | | logger.info("***************** 开始数据预警计算 *****************" + "\n"); |
| | | emailService.calcData(); |
| | | logger.info("***************** 数据预警计算完成 *****************" + "\n"); |
| | | } |
| | | } |
| | | } |