DeviceSchedulerService.java 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. package com.hfln.device.application.service;
  2. import com.hfln.device.domain.service.DeviceManagerService;
  3. import lombok.extern.slf4j.Slf4j;
  4. import org.springframework.beans.factory.annotation.Autowired;
  5. import org.springframework.scheduling.annotation.Scheduled;
  6. import org.springframework.stereotype.Service;
  7. /**
  8. * 设备定时任务调度器
  9. * 负责定时执行设备管理相关任务
  10. */
  11. @Service
  12. @Slf4j
  13. public class DeviceSchedulerService {
  14. @Autowired
  15. private DeviceManagerService deviceManagerService;
  16. /**
  17. * 设备保活超时时间(毫秒)
  18. */
  19. private static final long KEEPALIVE_TIMEOUT = 90000L; // 90秒
  20. /**
  21. * 告警确认超时时间(毫秒)
  22. */
  23. private static final long ALARM_ACK_TIMEOUT = 300000L; // 5分钟
  24. /**
  25. * 定时检查设备保活状态
  26. * 每30秒执行一次
  27. */
  28. // @Scheduled(fixedRate = 30000)
  29. public void checkDeviceKeepAlive() {
  30. try {
  31. log.debug("开始执行设备保活状态检查任务");
  32. long currentTime = System.currentTimeMillis();
  33. deviceManagerService.checkDeviceKeepAlive(currentTime, KEEPALIVE_TIMEOUT);
  34. log.debug("设备保活状态检查任务执行完成");
  35. } catch (Exception e) {
  36. log.error("设备保活状态检查任务执行异常", e);
  37. }
  38. }
  39. /**
  40. * 定时检查设备告警确认状态
  41. * 每分钟执行一次
  42. */
  43. // @Scheduled(fixedRate = 60000)
  44. public void checkDeviceAlarmAck() {
  45. try {
  46. log.debug("开始执行设备告警确认状态检查任务");
  47. long currentTime = System.currentTimeMillis();
  48. deviceManagerService.checkDeviceAlarmAck(currentTime, ALARM_ACK_TIMEOUT);
  49. log.debug("设备告警确认状态检查任务执行完成");
  50. } catch (Exception e) {
  51. log.error("设备告警确认状态检查任务执行异常", e);
  52. }
  53. }
  54. /**
  55. * 定时检查设备停留时间
  56. * 每分钟执行一次
  57. */
  58. // @Scheduled(fixedRate = 60000)
  59. public void checkDeviceStayTime() {
  60. try {
  61. log.debug("开始执行设备停留时间检查任务");
  62. deviceManagerService.checkAllDeviceStayTime();
  63. log.debug("设备停留时间检查任务执行完成");
  64. } catch (Exception e) {
  65. log.error("设备停留时间检查任务执行异常", e);
  66. }
  67. }
  68. /**
  69. * 定时检查设备告警计划
  70. * 每分钟执行一次
  71. */
  72. // @Scheduled(fixedRate = 60000)
  73. public void checkDeviceAlarmPlan() {
  74. try {
  75. log.debug("开始执行设备告警计划检查任务");
  76. deviceManagerService.checkAllDeviceAlarmPlan();
  77. log.debug("设备告警计划检查任务执行完成");
  78. } catch (Exception e) {
  79. log.error("设备告警计划检查任务执行异常", e);
  80. }
  81. }
  82. }