fix: 开关改变塘口时,不对定时任务清除,保留原来状态。

This commit is contained in:
tianyongbao
2026-07-04 22:13:04 +08:00
parent 0f320472cf
commit 2bcb2824b5

View File

@@ -3099,58 +3099,8 @@ public class IotController extends BaseController {
return R.ok();
}
// 如果开关原本有塘口,需要清理定时控制
if (oldPondId != null) {
// 查询设备的IotId
Device device = deviceMapper.selectById(vo.getDeviceId());
if (device != null && com.intc.common.core.utils.StringUtils.isNotBlank(device.getIotId())) {
// 检查设备是否在线通过判断warnCode判断设备状态
boolean isOnline = device.getWarnCode() != null && device.getWarnCode() != 99;
if (isOnline && iotCloudService != null) {
try {
// 构造清空定时控制的属性
Map<String, Object> properties = new java.util.HashMap<>();
// 清空定时器localTimer_switch{Index}
properties.put("localTimer_switch" + vo.getIndex(), java.util.Collections.emptyList());
// 如果开关是打开状态,需要关闭它
if (vo.getIsOpen() != null && vo.getIsOpen() == 1) {
// 关闭开关Switch{Index} = 0
properties.put(IOTPropertyName.SWITCH_INDEX + vo.getIndex(), 0);
// 更新数据库中的开关状态
deviceSwitchMapper.update(null,
new com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper<DeviceSwitch>()
.eq(DeviceSwitch::getId, switchId)
.set(DeviceSwitch::getIsOpen, 0)
);
}
// 调用物联网服务设置属性
boolean success = iotCloudService.setProperty(device.getIotId(), properties, false, 0);
if (success) {
log.info("成功通过物联网服务清空开关定时控制和关闭开关, switchId={}", switchId);
} else {
log.warn("通过物联网服务清空开关定时控制失败, switchId={}", switchId);
}
} catch (Exception e) {
log.error("调用物联网服务失败, switchId={}", switchId, e);
}
}
}
// 删除该开关的所有定时控制记录
if (timingCtrlMapper != null) {
timingCtrlMapper.delete(
new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<TimingCtrl>()
.eq(TimingCtrl::getSwitchId, switchId)
);
}
log.info("已清除开关ID={}的定时控制数据", switchId);
}
// 注意定时任务绑定在开关维度TimingCtrl 仅含 switchId不随塘口变化。
// 切换塘口只更新归属,不清空设备端 localTimer、不关开关、不删除定时任务记录。
// 处理新塘口分配
if (pondId != null && pondId > 0) {