fix: 太阳能控制下发指令,自测bug修复。

This commit is contained in:
tianyongbao
2026-07-01 09:59:51 +08:00
parent 6e88edcee1
commit 7ae7c42f34
6 changed files with 220 additions and 33 deletions

View File

@@ -63,6 +63,7 @@ import java.util.concurrent.TimeUnit;
public class DeviceDataHandler {
public static final String PENDING_SOLAR_PROPERTY_KEY_PREFIX = "device:pending:solar:property:";
private static final String PENDING_SOLAR_PROPERTY_FLUSH_LOCK_PREFIX = "device:pending:solar:property:flush:";
private static final int DEVICE_TYPE_SOLAR_CONTROLLER = 3;
/**
@@ -1011,8 +1012,23 @@ public class DeviceDataHandler {
deviceName, device.getId(), device.getDeviceType());
return;
}
if (StrUtil.isBlank(device.getSerialNum())) {
log.debug("[太阳能属性] 上线设备编号为空,跳过补发: deviceName={}, deviceId={}, iotId={}",
deviceName, device.getId(), device.getIotId());
return;
}
String flushLockKey = PENDING_SOLAR_PROPERTY_FLUSH_LOCK_PREFIX + device.getSerialNum();
boolean locked = false;
try {
locked = RedisUtils.setObjectIfAbsent(flushLockKey, "1", Duration.ofSeconds(30));
if (!locked) {
log.debug("[太阳能属性] 已有补发任务执行中,跳过重复补发: deviceName={}, deviceId={}",
deviceName, device.getId());
return;
}
PendingSolarProperty pendingProperty = findPendingSolarProperty(device);
if (pendingProperty == null) {
logNoPendingSolarProperty(trigger, deviceName, device);
@@ -1047,6 +1063,15 @@ public class DeviceDataHandler {
trigger, deviceName, pendingProperty.redisKey, pendingProperty.deviceId, pendingProperty.properties);
} catch (Exception e) {
log.error("[太阳能属性] {}补发异常: deviceName={}, err={}", trigger, deviceName, e.getMessage(), e);
} finally {
if (locked) {
try {
RedisUtils.deleteObject(flushLockKey);
} catch (Exception e) {
log.warn("[太阳能属性] 释放补发锁失败: deviceName={}, lockKey={}, err={}",
deviceName, flushLockKey, e.getMessage());
}
}
}
}