SchedulerTask.java 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. package com.its.vms.scheduler;
  2. import com.its.app.AppUtils;
  3. import com.its.app.utils.Elapsed;
  4. import com.its.vms.config.ApplicationConfig;
  5. import com.its.vms.config.DebugConfig;
  6. import com.its.vms.service.*;
  7. import lombok.AllArgsConstructor;
  8. import lombok.extern.slf4j.Slf4j;
  9. import org.springframework.scheduling.annotation.EnableScheduling;
  10. import org.springframework.scheduling.annotation.Scheduled;
  11. import org.springframework.stereotype.Component;
  12. import javax.annotation.PreDestroy;
  13. @Slf4j
  14. @AllArgsConstructor
  15. @EnableScheduling
  16. @Component
  17. public class SchedulerTask {
  18. private final ApplicationConfig config;
  19. private final UnitSystService unitSystService;
  20. private final VmsCtlrService vmsCtlrService;
  21. private final VmsManageService vmsManageService;
  22. private final VmsDisplayOnOffService displayOnOffService;
  23. private final VmsSymbService symbService;
  24. // private final EsbVmsTcpService esbVmsTcpService;
  25. private final AppRepositoryService repoService;
  26. @PreDestroy
  27. public void onShutDown() {
  28. this.unitSystService.updateUnitSystStts(false);
  29. DebugConfig debug = (DebugConfig) AppUtils.getBean(DebugConfig.class);
  30. debug.saveDebugInfo();
  31. }
  32. /**
  33. * 프로세스와 제어기 상태정보를 업데이트 한다.
  34. */
  35. @Scheduled(cron = "5 * * * * *") // 1분주기 작업 실행
  36. public void scheduleUnitSystStts() {
  37. if (!this.config.isStartSchedule()) {
  38. return;
  39. }
  40. Elapsed elapsed = new Elapsed();
  41. log.info("scheduleUnitSystStts: start. {}", Thread.currentThread().getName());
  42. // 1. 프로세스 상태정보 업데이트
  43. this.unitSystService.updateUnitSystStts(true);
  44. // 2. 제어기 상태정보 업데이트
  45. this.vmsCtlrService.updateCtlrStts(true, null);
  46. log.info("scheduleUnitSystStts: ..end. {} ms. {}", elapsed.milliSeconds(), Thread.currentThread().getName());
  47. }
  48. /**
  49. * 제어기의 상태정보 제어기로 전송한다.
  50. */
  51. @Scheduled(cron = "8 * * * * *") // 1분주기 작업 실행
  52. public void scheduleVmsStatusRequest() {
  53. if (!this.config.isStartSchedule()) {
  54. return;
  55. }
  56. Elapsed elapsed = new Elapsed();
  57. log.info("scheduleVmsStatusRequest: start. {}", Thread.currentThread().getName());
  58. this.vmsManageService.requestStatus();
  59. log.info("scheduleVmsStatusRequest: ..end. {} ms. {}", elapsed.milliSeconds(), Thread.currentThread().getName());
  60. }
  61. /**
  62. * 제어기 전광판 On/Off 시각에 명령을 전송한다.
  63. */
  64. //@Scheduled(cron = "${application.atmp.crontab:40 0/30 * * * *}")
  65. @Scheduled(cron = "15 * * * * *") // 1분주기 작업 실행
  66. public void scheduleVmsOnOffControl() {
  67. if (!this.config.isStartSchedule()) {
  68. return;
  69. }
  70. Elapsed elapsed = new Elapsed();
  71. log.info("scheduleVmsOnOffControl: start. {}", Thread.currentThread().getName());
  72. this.displayOnOffService.loadVmsOnOffTime();
  73. log.info("scheduleVmsOnOffControl: ..end. {} ms. {}", elapsed.milliSeconds(), Thread.currentThread().getName());
  74. }
  75. /**
  76. * 정주기 VMS 다운로드 메시지를 생성하고 제어기로 다운로드 한다.
  77. */
  78. @Scheduled(cron = "30 0/5 * * * *") // 정주기 5분 30초에 스케쥴 실행
  79. public void scheduleVmsFormDownload() {
  80. if (!this.config.isStartSchedule()) {
  81. return;
  82. }
  83. Elapsed elapsed = new Elapsed();
  84. log.info("scheduleVmsFormDownload..: start. {}", Thread.currentThread().getName());
  85. this.repoService.setStaticCycle(true);
  86. this.vmsManageService.jobMakeDownloadVmsForm();
  87. log.info("scheduleVmsFormDownload..: ..end. {} ms. {}", elapsed.milliSeconds(), Thread.currentThread().getName());
  88. }
  89. /**
  90. * VMS 심벌 다운로드 정보를 조회하여 제어기로 다운로드 한다.
  91. */
  92. @Scheduled(cron = "10 3,8,13,18,23,28,33,38,43,48,53,58 * * * *") // 5분주기 작업 실행
  93. public void scheduleVmsDnldSymb() {
  94. if (!this.config.isStartSchedule()) {
  95. return;
  96. }
  97. Elapsed elapsed = new Elapsed();
  98. log.info("scheduleVmsDnldSymb: start. {}", Thread.currentThread().getName());
  99. this.symbService.loadVmsScheSymbLib();
  100. log.info("scheduleVmsDnldSymb: ..end. {} ms. {}", elapsed.milliSeconds(), Thread.currentThread().getName());
  101. }
  102. /**
  103. * ESB VMS 연계 서버에 전송할 단문 메시지가 존재하는 지 1분 주기로 체크하여 데이터를 전송한다.
  104. */
  105. // @Scheduled(cron = "15 * * * * *") // 1분주기 작업 실행
  106. // public void scheduleEsbVmsShortMsg() {
  107. // if (!this.config.isStartSchedule()) {
  108. // return;
  109. // }
  110. // Elapsed elapsed = new Elapsed();
  111. // log.info("scheduleEsbVmsShortMsg: start. {}", Thread.currentThread().getName());
  112. // this.esbVmsTcpService.loadVmsShorMsg();
  113. // log.info("scheduleEsbVmsShortMsg: ..end. {} ms. {}", elapsed.milliSeconds(), Thread.currentThread().getName());
  114. // }
  115. }