From 3dee2a15cad899b998da637ca07768d7c92f6052 Mon Sep 17 00:00:00 2001
From: “djh” <“3298565835@qq.com”>
Date: Tue, 04 Nov 2025 13:18:03 +0800
Subject: [PATCH] 修改
---
src/main/java/com/gkhy/fourierSpecialGasMonitor/schedule/HeartbeatSchedule.java | 34 ++++++++++++++++++++++++----------
1 files changed, 24 insertions(+), 10 deletions(-)
diff --git a/src/main/java/com/gkhy/fourierSpecialGasMonitor/schedule/HeartbeatSchedule.java b/src/main/java/com/gkhy/fourierSpecialGasMonitor/schedule/HeartbeatSchedule.java
index 6bb7087..2cdf9ff 100644
--- a/src/main/java/com/gkhy/fourierSpecialGasMonitor/schedule/HeartbeatSchedule.java
+++ b/src/main/java/com/gkhy/fourierSpecialGasMonitor/schedule/HeartbeatSchedule.java
@@ -18,7 +18,9 @@
import org.springframework.stereotype.Component;
import java.io.IOException;
+import java.text.MessageFormat;
import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
/**
* @author Mr.huang
@@ -42,26 +44,34 @@
private final Logger logger = LoggerFactory.getLogger(this.getClass());
- //@Scheduled(cron = "1 * * * * *") // 每分钟执行一次
- @Scheduled(cron = "1 * * * * ?") // 每天凌晨执行
+ private static final String deviceExcLogFormat = "【设备预警提示】{0} 硬件设备离线。";
+
+ private static final DateTimeFormatter deviceExcLogFormatter = DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH:mm:ss");
+
+
+
+ @Scheduled(cron = "0 0/10 * * * ?")
@Async(value = "SocketTaskExecutor")
public void gasConcentrationStatus() {
-
GasConcentration gasConcentration = gasConcentrationService.getLastData();
if (gasConcentration != null){
- LocalDateTime lastReceiveTime = gasConcentration.getDataReceivingTime().plusMinutes(1);
+ LocalDateTime lastReceiveTime = gasConcentration.getDataReceivingTime().plusMinutes(10);
if (LocalDateTime.now().compareTo(lastReceiveTime) > 0){
try {
heartbeatExcWebsocketServer.sendInfo(HeartbeatExecEnum.GAS_CONCENTRATION.getStatus()+"",null);
- logger.info(HeartbeatExecEnum.GAS_CONCENTRATION.getDesc());
+ //logger.info(HeartbeatExecEnum.GAS_CONCENTRATION.getDesc());
DeviceExceptionLog deviceExceptionLog = new DeviceExceptionLog();
- deviceExceptionLog.setTime(LocalDateTime.now());
+ LocalDateTime now = LocalDateTime.now();
+ String content = MessageFormat.format(deviceExcLogFormat,deviceExcLogFormatter.format(now));
+ deviceExceptionLog.setTime(now);
+ deviceExceptionLog.setContent(content);
deviceExceptionLog.setExecDesc(HeartbeatExecEnum.GAS_CONCENTRATION.getDesc());
+ deviceExceptionLog.setDelFlag(0);
DeviceExceptionLog save = deviceExceptionLogService.save(deviceExceptionLog);
if (save == null)
throw new BusinessException(this.getClass(), ResultCode.SYSTEM_ERROR_DATABASE_FAIL.getCode(),"设备异常日志保存失败");
} catch (IOException e) {
- e.printStackTrace();
+ throw new BusinessException(this.getClass(), ResultCode.SYSTEM_ERROR_WEBSOCKET_SEND_INFO_FAIL.getCode(),"设备异常消息推送失败");
}
}
}
@@ -76,15 +86,19 @@
if (LocalDateTime.now().compareTo(lastReceiveTime) > 0){
try {
heartbeatExcWebsocketServer.sendInfo(HeartbeatExecEnum.GAS_FLUX.getStatus()+"",null);
- logger.info(HeartbeatExecEnum.GAS_FLUX.getDesc());
+ //logger.info(HeartbeatExecEnum.GAS_FLUX.getDesc());
DeviceExceptionLog deviceExceptionLog = new DeviceExceptionLog();
- deviceExceptionLog.setTime(LocalDateTime.now());
+ LocalDateTime now = LocalDateTime.now();
+ String content = MessageFormat.format(deviceExcLogFormat,deviceExcLogFormatter.format(now));
+ deviceExceptionLog.setTime(now);
+ deviceExceptionLog.setContent(content);
deviceExceptionLog.setExecDesc(HeartbeatExecEnum.GAS_FLUX.getDesc());
+ deviceExceptionLog.setDelFlag(0);
DeviceExceptionLog save = deviceExceptionLogService.save(deviceExceptionLog);
if (save == null)
throw new BusinessException(this.getClass(), ResultCode.SYSTEM_ERROR_DATABASE_FAIL.getCode(),"设备异常日志保存失败");
} catch (IOException e) {
- e.printStackTrace();
+ throw new BusinessException(this.getClass(), ResultCode.SYSTEM_ERROR_WEBSOCKET_SEND_INFO_FAIL.getCode(),"设备异常消息推送失败");
}
}
}
--
Gitblit v1.9.2