From cea3da9eb39128e47ab27bb44375b941d19a1f31 Mon Sep 17 00:00:00 2001
From: huangzhen <867217663@qq.com>
Date: Thu, 22 Feb 2024 08:50:16 +0800
Subject: [PATCH] 心跳改为10分钟一次
---
src/main/java/com/gkhy/fourierSpecialGasMonitor/schedule/HeartbeatSchedule.java | 25 +++++++++++++++++++------
1 files changed, 19 insertions(+), 6 deletions(-)
diff --git a/src/main/java/com/gkhy/fourierSpecialGasMonitor/schedule/HeartbeatSchedule.java b/src/main/java/com/gkhy/fourierSpecialGasMonitor/schedule/HeartbeatSchedule.java
index 57078f3..bc2a00e 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,19 +44,27 @@
private final Logger logger = LoggerFactory.getLogger(this.getClass());
+ private static final String deviceExcLogFormat = "【设备预警提示】{0} 硬件设备离线。";
- @Scheduled(cron = "1 * * * * ?") // 每天凌晨执行
+ 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(5);
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 save = deviceExceptionLogService.save(deviceExceptionLog);
if (save == null)
@@ -75,9 +85,12 @@
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 save = deviceExceptionLogService.save(deviceExceptionLog);
if (save == null)
--
Gitblit v1.9.2