fix: 控制器新增报警开关控制,过期提醒只在8:00~21:00打电话。

This commit is contained in:
tianyongbao
2026-06-15 09:11:10 +08:00
parent f59f89debe
commit c3bed32d03
8 changed files with 111 additions and 27 deletions

View File

@@ -1654,7 +1654,8 @@ public class DeviceDataHandler {
new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<Device>()
.eq(Device::getSerialNum, deviceName)
.select(Device::getId, Device::getSerialNum, Device::getDeviceName, Device::getWarnCode,
Device::getPondId, Device::getUserId, Device::getDeadTime)
Device::getPondId, Device::getUserId, Device::getDeadTime,
Device::getControllerFaultCallOpen)
.last("LIMIT 1")
);
if (device == null) {
@@ -1732,6 +1733,7 @@ public class DeviceDataHandler {
int switchIndex = 0;
// 告警类型:默认为控制器告警(3),开关相关故障使用开关告警(4)
int warnType = WARN_TYPE_CONTROLLER;
boolean powerOffError = false;
if (errorCode >= DefineDeviceErrorCode.Three_InputLosePhaseA
&& errorCode <= DefineDeviceErrorCode.Three_InputLosePhaseC) {
@@ -1785,12 +1787,10 @@ public class DeviceDataHandler {
String phaseName = DefineDeviceErrorCode.getPhaseName(tempIndex % 3);
switchIndex = tempIndex / 3 + 1;
DeviceSwitch sw = getDeviceSwitchByIndex(deviceId, switchIndex);
boolean electricWarnOpen = sw != null && sw.getElectricWarnOpen() != null && sw.getElectricWarnOpen() == 1;
warnTrigger = warnTrigger && electricWarnOpen;
if (warnTrigger) {
String swPondName = (sw.getPondId() != null) ? getPondName(sw.getPondId()) : pondName;
String swPondName = (sw != null && sw.getPondId() != null) ? getPondName(sw.getPondId()) : pondName;
messagePondName = swPondName;
String swName = sw.getSwitchName() != null ? sw.getSwitchName() : ("开关" + switchIndex);
String swName = sw != null && sw.getSwitchName() != null ? sw.getSwitchName() : ("开关" + switchIndex);
title = "控制器开关输出过流";
message = formatPondWarnMessage(messagePondName,
String.format("%s(%s)的开关%d(%s)输出%s相过流",
@@ -1804,12 +1804,10 @@ public class DeviceDataHandler {
String phaseName = DefineDeviceErrorCode.getPhaseName(tempIndex % 3);
switchIndex = tempIndex / 3 + 1;
DeviceSwitch sw = getDeviceSwitchByIndex(deviceId, switchIndex);
boolean electricWarnOpen = sw != null && sw.getElectricWarnOpen() != null && sw.getElectricWarnOpen() == 1;
warnTrigger = warnTrigger && electricWarnOpen;
if (warnTrigger) {
String swPondName = (sw.getPondId() != null) ? getPondName(sw.getPondId()) : pondName;
String swPondName = (sw != null && sw.getPondId() != null) ? getPondName(sw.getPondId()) : pondName;
messagePondName = swPondName;
String swName = sw.getSwitchName() != null ? sw.getSwitchName() : ("开关" + switchIndex);
String swName = sw != null && sw.getSwitchName() != null ? sw.getSwitchName() : ("开关" + switchIndex);
title = "控制器开关输出欠流";
message = formatPondWarnMessage(messagePondName,
String.format("%s(%s)的开关%d(%s)输出%s相欠流",
@@ -1821,12 +1819,10 @@ public class DeviceDataHandler {
warnType = WARN_TYPE_SWITCH;
switchIndex = errorCode - DefineDeviceErrorCode.Three_Switch1ElectricEmpty + 1;
DeviceSwitch sw = getDeviceSwitchByIndex(deviceId, switchIndex);
boolean electricWarnOpen = sw != null && sw.getElectricWarnOpen() != null && sw.getElectricWarnOpen() == 1;
warnTrigger = warnTrigger && electricWarnOpen;
if (warnTrigger) {
String swPondName = (sw.getPondId() != null) ? getPondName(sw.getPondId()) : pondName;
String swPondName = (sw != null && sw.getPondId() != null) ? getPondName(sw.getPondId()) : pondName;
messagePondName = swPondName;
String swName = sw.getSwitchName() != null ? sw.getSwitchName() : ("开关" + switchIndex);
String swName = sw != null && sw.getSwitchName() != null ? sw.getSwitchName() : ("开关" + switchIndex);
title = "控制器开关输出空载";
message = formatPondWarnMessage(messagePondName,
String.format("%s(%s)的开关%d(%s)输出空载",
@@ -1838,12 +1834,10 @@ public class DeviceDataHandler {
warnType = WARN_TYPE_SWITCH;
switchIndex = errorCode - DefineDeviceErrorCode.One_Switch1OverElectric + 1;
DeviceSwitch sw = getDeviceSwitchByIndex(deviceId, switchIndex);
boolean electricWarnOpen = sw != null && sw.getElectricWarnOpen() != null && sw.getElectricWarnOpen() == 1;
warnTrigger = warnTrigger && electricWarnOpen;
if (warnTrigger) {
String swPondName = (sw.getPondId() != null) ? getPondName(sw.getPondId()) : pondName;
String swPondName = (sw != null && sw.getPondId() != null) ? getPondName(sw.getPondId()) : pondName;
messagePondName = swPondName;
String swName = sw.getSwitchName() != null ? sw.getSwitchName() : ("开关" + switchIndex);
String swName = sw != null && sw.getSwitchName() != null ? sw.getSwitchName() : ("开关" + switchIndex);
title = "控制器开关输出过流";
message = formatPondWarnMessage(messagePondName,
String.format("%s(%s)的开关%d(%s)输出过流",
@@ -1855,12 +1849,10 @@ public class DeviceDataHandler {
warnType = WARN_TYPE_SWITCH;
switchIndex = errorCode - DefineDeviceErrorCode.One_Switch1UnderElectric + 1;
DeviceSwitch sw = getDeviceSwitchByIndex(deviceId, switchIndex);
boolean electricWarnOpen = sw != null && sw.getElectricWarnOpen() != null && sw.getElectricWarnOpen() == 1;
warnTrigger = warnTrigger && electricWarnOpen;
if (warnTrigger) {
String swPondName = (sw.getPondId() != null) ? getPondName(sw.getPondId()) : pondName;
String swPondName = (sw != null && sw.getPondId() != null) ? getPondName(sw.getPondId()) : pondName;
messagePondName = swPondName;
String swName = sw.getSwitchName() != null ? sw.getSwitchName() : ("开关" + switchIndex);
String swName = sw != null && sw.getSwitchName() != null ? sw.getSwitchName() : ("开关" + switchIndex);
title = "控制器开关输出欠流";
message = formatPondWarnMessage(messagePondName,
String.format("%s(%s)的开关%d(%s)输出欠流",
@@ -1872,18 +1864,17 @@ public class DeviceDataHandler {
warnType = WARN_TYPE_SWITCH;
switchIndex = errorCode - DefineDeviceErrorCode.One_Switch1ElectricEmpty + 1;
DeviceSwitch sw = getDeviceSwitchByIndex(deviceId, switchIndex);
boolean electricWarnOpen = sw != null && sw.getElectricWarnOpen() != null && sw.getElectricWarnOpen() == 1;
warnTrigger = warnTrigger && electricWarnOpen;
if (warnTrigger) {
String swPondName = (sw.getPondId() != null) ? getPondName(sw.getPondId()) : pondName;
String swPondName = (sw != null && sw.getPondId() != null) ? getPondName(sw.getPondId()) : pondName;
messagePondName = swPondName;
String swName = sw.getSwitchName() != null ? sw.getSwitchName() : ("开关" + switchIndex);
String swName = sw != null && sw.getSwitchName() != null ? sw.getSwitchName() : ("开关" + switchIndex);
title = "控制器开关输出空载";
message = formatPondWarnMessage(messagePondName,
String.format("%s(%s)的开关%d(%s)输出空载",
displayName, device.getSerialNum(), switchIndex, swName));
}
} else if (errorCode == DefineDeviceErrorCode.PowerOff) {
powerOffError = true;
// 断电:已存在离线状态则不触发断电告警
boolean alreadyOffline = device.getWarnCode() != null
&& (device.getWarnCode() & DefineDeviceWarnCode.DeviceOffline) != 0;
@@ -1905,9 +1896,15 @@ public class DeviceDataHandler {
if (userId != null) {
MessageWarn warn = createMessageWarn(deviceId, userId, messagePondName, title, warnType, message);
messageWarnMapper.insert(warn);
// 创建电话通知记录(全局开关控制)
if (aliyunIotProperties.isCallNoticeEnabled()) {
boolean controllerFaultCallOpen = device.getControllerFaultCallOpen() == null
|| device.getControllerFaultCallOpen() == 1;
boolean shouldCreateCallNotice = powerOffError || controllerFaultCallOpen;
// 创建电话通知记录:断电不受控制器故障电话开关限制,其他故障受该开关限制。
if (aliyunIotProperties.isCallNoticeEnabled() && shouldCreateCallNotice) {
createCallNotices(device, messagePondName, warn);
} else if (!shouldCreateCallNotice) {
log.info("[故障码] 设备={} 控制器故障电话报警开关关闭,仅记录报警消息: title={}",
device.getSerialNum(), title);
}
}
}

View File

@@ -10,6 +10,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.time.LocalTime;
import java.util.Date;
import java.util.List;
@@ -35,6 +36,13 @@ public class DeviceExpirationWarnTask {
@Scheduled(fixedDelay = 7200000)
public void checkDeviceExpirationAndNotify() {
try {
// 只在 8:00 ~ 21:00 之间拨打电话通知,避免夜间打扰用户
LocalTime currentTime = LocalTime.now();
if (currentTime.isBefore(LocalTime.of(8, 0)) || !currentTime.isBefore(LocalTime.of(21, 0))) {
log.debug("[到期告警] 当前时间 {} 不在电话通知时段(08:00~21:00),跳过本次扫描", currentTime);
return;
}
Date now = new Date();
// 24小时后的时间点
Date deadline = new Date(now.getTime() + 24L * 60 * 60 * 1000);