12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- package com.hfln.device.application.service;
- import com.hfln.device.domain.service.DeviceManagerService;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.scheduling.annotation.Scheduled;
- import org.springframework.stereotype.Service;
- /**
- * 设备定时任务调度器
- * 负责定时执行设备管理相关任务
- */
- @Service
- @Slf4j
- public class DeviceSchedulerService {
- @Autowired
- private DeviceManagerService deviceManagerService;
- /**
- * 设备保活超时时间(毫秒)
- */
- private static final long KEEPALIVE_TIMEOUT = 90000L; // 90秒
- /**
- * 告警确认超时时间(毫秒)
- */
- private static final long ALARM_ACK_TIMEOUT = 300000L; // 5分钟
- /**
- * 定时检查设备保活状态
- * 每30秒执行一次
- */
- // @Scheduled(fixedRate = 30000)
- public void checkDeviceKeepAlive() {
- try {
- log.debug("开始执行设备保活状态检查任务");
- long currentTime = System.currentTimeMillis();
- deviceManagerService.checkDeviceKeepAlive(currentTime, KEEPALIVE_TIMEOUT);
- log.debug("设备保活状态检查任务执行完成");
- } catch (Exception e) {
- log.error("设备保活状态检查任务执行异常", e);
- }
- }
- /**
- * 定时检查设备告警确认状态
- * 每分钟执行一次
- */
- // @Scheduled(fixedRate = 60000)
- public void checkDeviceAlarmAck() {
- try {
- log.debug("开始执行设备告警确认状态检查任务");
- long currentTime = System.currentTimeMillis();
- deviceManagerService.checkDeviceAlarmAck(currentTime, ALARM_ACK_TIMEOUT);
- log.debug("设备告警确认状态检查任务执行完成");
- } catch (Exception e) {
- log.error("设备告警确认状态检查任务执行异常", e);
- }
- }
- /**
- * 定时检查设备停留时间
- * 每分钟执行一次
- */
- // @Scheduled(fixedRate = 60000)
- public void checkDeviceStayTime() {
- try {
- log.debug("开始执行设备停留时间检查任务");
- deviceManagerService.checkAllDeviceStayTime();
- log.debug("设备停留时间检查任务执行完成");
- } catch (Exception e) {
- log.error("设备停留时间检查任务执行异常", e);
- }
- }
- /**
- * 定时检查设备告警计划
- * 每分钟执行一次
- */
- // @Scheduled(fixedRate = 60000)
- public void checkDeviceAlarmPlan() {
- try {
- log.debug("开始执行设备告警计划检查任务");
- deviceManagerService.checkAllDeviceAlarmPlan();
- log.debug("设备告警计划检查任务执行完成");
- } catch (Exception e) {
- log.error("设备告警计划检查任务执行异常", e);
- }
- }
- }
|