SchedulerTask.java 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. package com.its.vds.scheduler;
  2. import com.its.app.AppUtils;
  3. import com.its.app.utils.Elapsed;
  4. import com.its.vds.config.ProcessConfig;
  5. import com.its.vds.service.StatisticsServices;
  6. import com.its.vds.service.UnitSystService;
  7. import com.its.vds.service.VdsCtlrService;
  8. import lombok.AllArgsConstructor;
  9. import lombok.extern.slf4j.Slf4j;
  10. import org.springframework.scheduling.annotation.EnableScheduling;
  11. import org.springframework.scheduling.annotation.Scheduled;
  12. import org.springframework.stereotype.Component;
  13. import javax.annotation.PreDestroy;
  14. @Slf4j
  15. @AllArgsConstructor
  16. @EnableScheduling
  17. @Component
  18. public class SchedulerTask {
  19. private final ProcessConfig processConfig;
  20. private final UnitSystService unitSystService;
  21. private final VdsCtlrService vdsCtlrService;
  22. private final StatisticsServices statisticsServices;
  23. @Scheduled(cron = "5 * * * * *") // 1분주기 작업 실행
  24. public void UnitSystSchedule() {
  25. if (!this.processConfig.isStartSchedule()) {
  26. return;
  27. }
  28. Elapsed elapsed = new Elapsed();
  29. log.info(" UnitSystSchedule: start. {}", Thread.currentThread().getName());
  30. // 프로세스 상태정보 업데이트
  31. this.unitSystService.updateUnitSystStts(true);
  32. // 제어기 상태정보 업데이트(제어기/프로세스 상태정보 UDP 전송)
  33. this.vdsCtlrService.updateCtlrStts(true);
  34. log.info(" UnitSystSchedule: ..end. {} ms. {}", elapsed.milliSeconds(), Thread.currentThread().getName());
  35. /*
  36. TcpServerDataProcess tcpServerDataProcess = (TcpServerDataProcess) AppUtils.getBean(TcpServerDataProcess.class);
  37. for (int ii = 0; ii < 100; ii++) {
  38. String id = Integer.toString(ii);
  39. tcpServerDataProcess.add(new TcpServerData(id, null, null));
  40. }*/
  41. }
  42. // @Scheduled(cron = "10/30 * * * * *") // 30초마다 요청(10초, 40초)
  43. // public void VdsTrafficRequestSchedule() {
  44. // if (!this.processConfig.isStartSchedule()) {
  45. // return;
  46. // }
  47. // Elapsed elapsed = new Elapsed();
  48. // log.info("VdsTrafficRequestSchedule: start. {}", Thread.currentThread().getName());
  49. // // 제어기 동기화 요청
  50. // // 교통데이터 요청
  51. // this.vdsCtlrService.requestTraffic();
  52. // log.info("VdsTrafficRequestSchedule: ..end. {} ms. {}", elapsed.milliSeconds(), Thread.currentThread().getName());
  53. // }
  54. // @Scheduled(cron = "15/30 * * * * *") // 30초마다 요청(15초, 45초)
  55. // public void VdsVehicleRequestSchedule() {
  56. // if (!this.processConfig.isStartSchedule()) {
  57. // return;
  58. // }
  59. // Elapsed elapsed = new Elapsed();
  60. // // VDS 교통 데이터를 요청한 다음에 차량 정보를 요청한다.
  61. // // 제어기에서 동기화가 안되기 때문에 교통 데이터를 요청한 다음에 5초 후에 요청한다.
  62. // log.info("VdsVehicleRequestSchedule: start. {}", Thread.currentThread().getName());
  63. // this.vdsCtlrService.requestVehicle();
  64. // log.info("VdsVehicleRequestSchedule: ..end. {} ms. {}", elapsed.milliSeconds(), Thread.currentThread().getName());
  65. // }
  66. @Scheduled(cron = "40 0/5 * * * *") // 정주기 5분 40초에 스케쥴 실행
  67. public void StatisticsSchedule() {
  68. if (!this.processConfig.isStartSchedule()) {
  69. return;
  70. }
  71. Elapsed elapsed = new Elapsed();
  72. log.info(" StatisticsSchedule: start. {}", Thread.currentThread().getName());
  73. ProcessConfig processConfig = (ProcessConfig) AppUtils.getBean(ProcessConfig.class);
  74. // if (applicationConfig.getTaskStatistics().equals("true")) {
  75. // StatisticsTime its = new StatisticsTime();
  76. // its.init();
  77. // its.setProcessing(true);
  78. //
  79. // if (true) {
  80. // // VDS 검지기 5분 가공
  81. // this.statisticsServices.CRT_TB_VDS_DTCT_HS(its.getPrcsFiveMin(), its.getPrcsFiveMinFrom(), its.getPrcsFiveMinTo());
  82. // }
  83. //
  84. // if (its.isStat15Min()) {
  85. // // 5분 정주기 가공이 끝나고 15분 주기일 경우(00, 15, 30, 45 분 일경우 15분 통계 정보를 생성한다)
  86. // this.statisticsServices.CRT_TB_VDS_DTCT_15M_STAT(its.getStat15MinFrom(), its.getStat15MinFrom(), its.getStat15MinTo());
  87. // }
  88. //
  89. // if (its.isStatHour()) {
  90. // // 매시 5분 가공완료후 1시간 통계
  91. // this.statisticsServices.CRT_TB_VDS_DTCT_HH_STAT(its.getStatHourTime(), its.getStatHourTime(), its.getStatHourTo());
  92. // }
  93. //
  94. // if (its.isStatDay()) {
  95. // // 00시 10분 가공이 끝나면 이전일의 통계 정보를 가공.
  96. // this.statisticsServices.CRT_TB_VDS_DTCT_DD_STAT(its.getStatDayFrom(), its.getStatDayFrom(), its.getStatDayTo());
  97. // }
  98. //
  99. // if (its.isStatMon()) {
  100. // // 02시 10분 가공이 끝나면 이전일의 월통계 정보를 누적 가공.
  101. // String STAT_DT = its.getStatMonFrom().substring(0, 6) + "00000000";
  102. // this.statisticsServices.CRT_TB_VDS_DTCT_MN_STAT(STAT_DT, its.getStatMonFrom(), its.getStatMonTo());
  103. // }
  104. // if (its.isStatYear()) {
  105. // // 02시 35분 가공이 끝나면 이전일의 연통계 정보를 누적 가공.
  106. // String STAT_DT = its.getStatYearFrom().substring(0, 4) + "0000000000";
  107. // this.statisticsServices.CRT_TB_VDS_DTCT_YY_STAT(STAT_DT, its.getStatYearFrom(), its.getStatYearTo());
  108. // }
  109. // its.setProcessing(false);
  110. // }
  111. log.info(" StatisticsSchedule: ..end. {} ms. {}", elapsed.milliSeconds(), Thread.currentThread().getName());
  112. }
  113. @PreDestroy
  114. public void onShutDown() {
  115. this.unitSystService.updateUnitSystStts(false);
  116. }
  117. }