TrafficSchedule.java 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package egovframework.scheduler;
  2. import egovframework.service.impl.CommonServiceImpl;
  3. import egovframework.utill.TrafficData;
  4. import lombok.RequiredArgsConstructor;
  5. import lombok.extern.slf4j.Slf4j;
  6. import org.springframework.scheduling.annotation.EnableScheduling;
  7. import org.springframework.scheduling.annotation.Scheduled;
  8. import org.springframework.stereotype.Component;
  9. import javax.annotation.PostConstruct;
  10. import javax.annotation.PreDestroy;
  11. import java.text.SimpleDateFormat;
  12. import java.util.Date;
  13. @Slf4j
  14. @RequiredArgsConstructor
  15. @EnableScheduling
  16. @Component
  17. public class TrafficSchedule {
  18. private final CommonServiceImpl cs;
  19. public String getSysTime() {
  20. SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  21. Date dtLog = new Date();
  22. return sdfDate.format(dtLog);
  23. }
  24. @Scheduled(cron = "0 0/5 * * * ?") // 5분주기 작업 실행
  25. public void trafficSchedule() {
  26. log.info("Traffic Schedule Work Time : {}", getSysTime());
  27. TrafficData.setRoad(this.cs.getRoadVertexArr());
  28. TrafficData.setIfsc(this.cs.getIfscVertexArr());
  29. TrafficData.setLink(this.cs.getLinkVertexArr());
  30. }
  31. @PostConstruct
  32. private void init() {
  33. log.info("Traffic Schedule init : {}", getSysTime());
  34. TrafficData.setRoad(this.cs.getRoadVertexArr());
  35. TrafficData.setIfsc(this.cs.getIfscVertexArr());
  36. TrafficData.setLink(this.cs.getLinkVertexArr());
  37. }
  38. @PreDestroy
  39. public void preDestroy() {
  40. }
  41. }