fix: 盐度补偿设定,太阳能网控缓存逻辑修改完善。
This commit is contained in:
@@ -58,6 +58,8 @@ import java.util.Map;
|
||||
@ConditionalOnBean(IDeviceSensorDataService.class)
|
||||
public class DeviceDataHandler {
|
||||
|
||||
public static final String PENDING_SOLAR_SALINITY_KEY_PREFIX = "device:pending:solar:salinity:";
|
||||
|
||||
/**
|
||||
* TDengine 服务,用于存储设备时序数据
|
||||
*/
|
||||
@@ -955,11 +957,56 @@ public class DeviceDataHandler {
|
||||
log.info("[离线告警] 设备已上线,取消离线告警: {}", deviceName);
|
||||
}
|
||||
|
||||
flushPendingSolarSalinity(deviceName);
|
||||
|
||||
// 同步更新 Device.warnCode,清除离线和休眠标志位
|
||||
setDeviceWarnCodeBit(deviceName, DefineDeviceWarnCode.DeviceOffline, false);
|
||||
setDeviceWarnCodeBit(deviceName, DefineDeviceWarnCode.DeviceSleeping, false);
|
||||
}
|
||||
|
||||
private void flushPendingSolarSalinity(String deviceName) {
|
||||
String redisKey = PENDING_SOLAR_SALINITY_KEY_PREFIX + deviceName;
|
||||
Object rawPending = RedisUtils.getCacheObject(redisKey);
|
||||
if (rawPending == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
JSONObject pending = JSONUtil.parseObj(rawPending);
|
||||
Double salinityCompensation = pending.getDouble("salinityCompensation");
|
||||
String iotId = pending.getStr("iotId");
|
||||
Long deviceId = pending.getLong("deviceId");
|
||||
if (salinityCompensation == null || iotId == null || deviceId == null) {
|
||||
log.warn("[太阳能盐度] 缓存数据不完整,跳过补发: deviceName={}, pending={}", deviceName, pending);
|
||||
return;
|
||||
}
|
||||
|
||||
Map<String, Object> properties = new HashMap<>();
|
||||
properties.put("salinitySet", salinityCompensation);
|
||||
boolean success = iotCloudService.setProperty(iotId, properties, true, 2);
|
||||
if (!success) {
|
||||
log.warn("[太阳能盐度] 上线补发失败,保留缓存: deviceName={}, deviceId={}, salinityCompensation={}",
|
||||
deviceName, deviceId, salinityCompensation);
|
||||
return;
|
||||
}
|
||||
|
||||
Device updateDevice = new Device();
|
||||
updateDevice.setId(deviceId);
|
||||
updateDevice.setSalinityCompensation(salinityCompensation);
|
||||
int updated = deviceMapper.updateById(updateDevice);
|
||||
if (updated > 0) {
|
||||
RedisUtils.deleteObject(redisKey);
|
||||
log.info("[太阳能盐度] 上线补发成功并清除缓存: deviceName={}, deviceId={}, salinityCompensation={}",
|
||||
deviceName, deviceId, salinityCompensation);
|
||||
} else {
|
||||
log.warn("[太阳能盐度] 上线补发成功但设备表更新失败,保留缓存以便重试: deviceName={}, deviceId={}",
|
||||
deviceName, deviceId);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("[太阳能盐度] 上线补发异常: deviceName={}, err={}", deviceName, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 太阳能网控设备离线超时:从休眠状态转为真正离线
|
||||
* 置 DeviceOffline 位,清 DeviceSleeping 位
|
||||
|
||||
Reference in New Issue
Block a user