fix: 电话通知逻辑,功能修改,完善机制。
This commit is contained in:
@@ -834,10 +834,12 @@ public class DeviceDataHandler {
|
||||
);
|
||||
|
||||
if (response != null && response.isSuccess()) {
|
||||
// 更新通知记录状态
|
||||
// 更新通知记录状态,同时将 callTime 更新为实际发出时间
|
||||
// 超时判断基于 callTime,必须使用实际发出时间而非预计呼叫时间
|
||||
callNotice.setCallStatus(1); // 呼叫成功,等待结果反馈
|
||||
callNotice.setCallId(response.getCallId());
|
||||
callNotice.setOutId(outId);
|
||||
callNotice.setCallTime(LocalDateTime.now()); // 记录实际发出时间,用于超时判断
|
||||
warnCallNoticeMapper.updateById(callNotice);
|
||||
|
||||
log.info("[告警] 呼叫成功: {}", callNotice.getMobilePhone());
|
||||
@@ -2238,7 +2240,7 @@ public class DeviceDataHandler {
|
||||
new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<Device>()
|
||||
.eq(Device::getSerialNum, deviceName)
|
||||
.select(Device::getId, Device::getIotId, Device::getSerialNum, Device::getDeviceName,
|
||||
Device::getPondId, Device::getValueDissolvedOxygen)
|
||||
Device::getPondId, Device::getValueDissolvedOxygen, Device::getUserId)
|
||||
.last("LIMIT 1")
|
||||
);
|
||||
if (currentDevice == null || currentDevice.getId() == null) {
|
||||
@@ -2334,7 +2336,8 @@ public class DeviceDataHandler {
|
||||
deviceMapper.selectOne(
|
||||
new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<Device>()
|
||||
.eq(Device::getId, id)
|
||||
.select(Device::getId, Device::getIotId, Device::getSerialNum, Device::getDeviceName)
|
||||
.select(Device::getId, Device::getIotId, Device::getSerialNum, Device::getDeviceName,
|
||||
Device::getUserId)
|
||||
.last("LIMIT 1")
|
||||
)
|
||||
);
|
||||
@@ -2356,7 +2359,9 @@ public class DeviceDataHandler {
|
||||
&& effectiveDissolvedOxygen <= linkedCtrl.getOxyLowerValue()) {
|
||||
log.info("[联动控制] 触发设备={} 塘口最低溶解氧={} ≤ 下限={},开启开关(本机上报={})",
|
||||
deviceName, effectiveDissolvedOxygen, linkedCtrl.getOxyLowerValue(), dissolvedOxygen);
|
||||
setDeviceSwitchLinkedOpen(device, switches, true);
|
||||
setDeviceSwitchLinkedOpen(device, switches, true,
|
||||
String.format("溶解氧%.2f ≤ 下限%.2f",
|
||||
effectiveDissolvedOxygen, linkedCtrl.getOxyLowerValue()));
|
||||
}
|
||||
|
||||
// 溶解氧上限联动(带滞回防止重复触发)
|
||||
@@ -2385,7 +2390,9 @@ public class DeviceDataHandler {
|
||||
linkedCtrlMapper.updateById(updateCtrl);
|
||||
log.info("[联动控制] 触发设备={} 塘口最低溶解氧={} ≥ 上限={},关闭开关",
|
||||
deviceName, effectiveDissolvedOxygen, linkedCtrl.getOxyUpperValue());
|
||||
setDeviceSwitchLinkedOpen(device, switches, false);
|
||||
setDeviceSwitchLinkedOpen(device, switches, false,
|
||||
String.format("溶解氧%.2f ≥ 上限%.2f",
|
||||
effectiveDissolvedOxygen, linkedCtrl.getOxyUpperValue()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2396,13 +2403,14 @@ public class DeviceDataHandler {
|
||||
|
||||
/**
|
||||
* 按联动控制开启/关闭一组开关(参考 C# SetDeviceSwitchLinkedOpen)
|
||||
* 下发成功后更新 DeviceSwitch.isOpen 和 lastTurnTime。
|
||||
* 下发成功后更新 DeviceSwitch.isOpen 和 lastTurnTime,并写入操作记录。
|
||||
*
|
||||
* @param device 设备信息(含 iotId)
|
||||
* @param switches 待操作的开关列表
|
||||
* @param open true=开启, false=关闭
|
||||
* @param device 设备信息(含 iotId、userId)
|
||||
* @param switches 待操作的开关列表
|
||||
* @param open true=开启, false=关闭
|
||||
* @param opReasonDesc 操作原因描述(用于操作记录 message 前缀)
|
||||
*/
|
||||
private void setDeviceSwitchLinkedOpen(Device device, List<com.intc.fishery.domain.DeviceSwitch> switches, boolean open) {
|
||||
private void setDeviceSwitchLinkedOpen(Device device, List<com.intc.fishery.domain.DeviceSwitch> switches, boolean open, String opReasonDesc) {
|
||||
if (device == null || device.getIotId() == null || switches == null || switches.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
@@ -2432,16 +2440,32 @@ public class DeviceDataHandler {
|
||||
boolean success = iotCloudService.setProperty(device.getIotId(), properties, false, 1);
|
||||
if (success) {
|
||||
java.util.Date now = new java.util.Date();
|
||||
String deviceLabel = device.getSerialNum() != null ? device.getSerialNum() : device.getIotId();
|
||||
for (com.intc.fishery.domain.DeviceSwitch sw : toChange) {
|
||||
com.intc.fishery.domain.DeviceSwitch updateSw = new com.intc.fishery.domain.DeviceSwitch();
|
||||
updateSw.setId(sw.getId());
|
||||
updateSw.setIsOpen(targetState);
|
||||
updateSw.setLastTurnTime(now);
|
||||
deviceSwitchMapper.updateById(updateSw);
|
||||
// 写入操作记录
|
||||
if (device.getUserId() != null) {
|
||||
String dName = device.getDeviceName() != null ? device.getDeviceName() : deviceLabel;
|
||||
String switchName = sw.getSwitchName() != null ? sw.getSwitchName() : ("Switch" + sw.getIndex());
|
||||
String reasonPart = opReasonDesc != null ? "(" + opReasonDesc + ")" : "";
|
||||
com.intc.fishery.utils.MessageOpRecordUtil.addMessageOpRecordLinked(
|
||||
device.getUserId(),
|
||||
"开关操作",
|
||||
String.format("%s(%s)的开关%s%s:%s%s。",
|
||||
dName, deviceLabel,
|
||||
sw.getIndex() != null ? sw.getIndex() + " " : "",
|
||||
switchName,
|
||||
open ? "开启" : "关闭",
|
||||
reasonPart)
|
||||
);
|
||||
}
|
||||
}
|
||||
log.info("[联动控制] 设备={} 开关下发成功:{} -> {}",
|
||||
device.getSerialNum() != null ? device.getSerialNum() : device.getIotId(),
|
||||
properties.keySet(), open ? "开启" : "关闭");
|
||||
deviceLabel, properties.keySet(), open ? "开启" : "关闭");
|
||||
} else {
|
||||
log.warn("[联动控制] 设备={} 开关下发失败:{}",
|
||||
device.getSerialNum() != null ? device.getSerialNum() : device.getIotId(),
|
||||
|
||||
Reference in New Issue
Block a user