FcltSttsJobThread.java 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package com.its.api.scheduler.job;
  2. import com.fasterxml.jackson.core.JsonProcessingException;
  3. import com.fasterxml.jackson.databind.ObjectMapper;
  4. import com.its.api.bis.service.BitService;
  5. import com.its.api.its.model.dto.common.FcltSttsListDto;
  6. import com.its.api.its.service.common.CommonSttsService;
  7. import com.its.api.websocket.ItsWebSocketMessage;
  8. import com.its.api.websocket.ItsWebSocketSessionManager;
  9. import lombok.AllArgsConstructor;
  10. import lombok.extern.slf4j.Slf4j;
  11. import org.springframework.scheduling.annotation.Async;
  12. import org.springframework.stereotype.Service;
  13. import org.springframework.util.StopWatch;
  14. import org.springframework.web.socket.TextMessage;
  15. import javax.annotation.PostConstruct;
  16. @Slf4j
  17. @AllArgsConstructor
  18. @Service
  19. public class FcltSttsJobThread {
  20. private final CommonSttsService itsService;
  21. private final BitService bitService;
  22. private ObjectMapper mapper;
  23. @PostConstruct
  24. private void init() {
  25. this.mapper = new ObjectMapper();
  26. log.info("{}", this);
  27. }
  28. @Async("schJobExecutor")
  29. public void run() {
  30. log.info("START: FcltSttsJobThread.run: {}", Thread.currentThread().getName());
  31. StopWatch stopWatch = new StopWatch();
  32. stopWatch.start();
  33. // ITS Fclt Stts
  34. FcltSttsListDto itsSttsDto = this.itsService.findAllFcltSttsTotal();
  35. ItsWebSocketMessage itsMessage = new ItsWebSocketMessage("itsFcltStts", itsSttsDto);
  36. try {
  37. String itsSttsJsonData = this.mapper.writeValueAsString(itsMessage);
  38. ItsWebSocketSessionManager.getInstance().sendBroadcastMessage(itsMessage.getCommand(), new TextMessage(itsSttsJsonData));
  39. }
  40. catch(JsonProcessingException e){
  41. log.error("FcltSttsJobThread ItsFcltSttsDto Json parsing Exception: {}, {}", itsSttsDto, e.getMessage());
  42. }
  43. // BIS BIT Stts
  44. FcltSttsListDto bitSttsDto = this.bitService.findAllListSttsTotal(true);
  45. ItsWebSocketMessage bisMessage = new ItsWebSocketMessage("bisFcltStts", bitSttsDto);
  46. try {
  47. String bitSttsJsonData = this.mapper.writeValueAsString(bisMessage);
  48. ItsWebSocketSessionManager.getInstance().sendBroadcastMessage(bisMessage.getCommand(), new TextMessage(bitSttsJsonData));
  49. }
  50. catch(JsonProcessingException e){
  51. log.error("FcltSttsJobThread BisFcltSttsDto Json parsing Exception: {}, {}", itsSttsDto, e.getMessage());
  52. }
  53. stopWatch.stop();
  54. log.info("--END: FcltSttsJobThread.run: {}, {} ms.", Thread.currentThread().getName(), stopWatch.getTotalTimeMillis());
  55. }
  56. }