fix: 盐度设置,设备上线后,直接下发,去掉原来的1.5秒延时。

This commit is contained in:
tianyongbao
2026-06-30 10:32:19 +08:00
parent 9f9c4fc4a2
commit fa2cc8e77a
2 changed files with 21 additions and 82 deletions

View File

@@ -2099,6 +2099,10 @@ public class IotController extends BaseController {
}
private boolean cachePendingSolarSalinity(Device device, Double salinityCompensation) {
if (device.getSerialNum() == null || device.getSerialNum().isBlank()) {
log.warn("太阳能网控盐度缓存失败: deviceId={}, serialNum为空", device.getId());
return false;
}
try {
Map<String, Object> cacheValue = new java.util.HashMap<>();
cacheValue.put("deviceId", device.getId());
@@ -2107,20 +2111,13 @@ public class IotController extends BaseController {
cacheValue.put("salinityCompensation", salinityCompensation);
cacheValue.put("updatedAt", System.currentTimeMillis());
String cacheJson = cn.hutool.json.JSONUtil.toJsonStr(cacheValue);
java.util.List<String> cacheKeys = buildPendingSolarSalinityKeys(device);
if (cacheKeys.isEmpty()) {
log.warn("太阳能网控盐度缓存失败: deviceId={}, serialNum和iotId均为空", device.getId());
return false;
}
String cacheKey = DeviceDataHandler.PENDING_SOLAR_SALINITY_KEY_PREFIX + device.getSerialNum();
// 忽略租户前缀HTTP线程写入带租户前缀AMQP消费线程读取不带前缀需统一
final String cacheJsonRef = cacheJson;
TenantHelper.ignore(() -> {
for (String key : cacheKeys) {
com.intc.common.redis.utils.RedisUtils.setCacheObject(key, cacheJsonRef, Duration.ofDays(7));
}
});
log.info("太阳能网控盐度已缓存,等待上线补发: deviceId={}, serialNum={}, iotId={}, cacheKeys={}, salinityCompensation={}",
device.getId(), device.getSerialNum(), device.getIotId(), cacheKeys, salinityCompensation);
TenantHelper.ignore(() ->
com.intc.common.redis.utils.RedisUtils.setCacheObject(cacheKey, cacheJson, Duration.ofDays(7))
);
log.info("太阳能网控盐度已缓存,等待上线补发: deviceId={}, serialNum={}, salinityCompensation={}",
device.getId(), device.getSerialNum(), salinityCompensation);
return true;
} catch (Exception e) {
log.error("缓存太阳能网控盐度失败: deviceId={}, serialNum={}, err={}",
@@ -2146,22 +2143,6 @@ public class IotController extends BaseController {
);
}
private java.util.List<String> buildPendingSolarSalinityKeys(Device device) {
java.util.List<String> keys = new java.util.ArrayList<>();
addPendingSolarSalinityKey(keys, device.getSerialNum());
addPendingSolarSalinityKey(keys, device.getIotId());
return keys;
}
private void addPendingSolarSalinityKey(java.util.List<String> keys, String cacheName) {
if (cacheName == null || cacheName.isBlank()) {
return;
}
String key = DeviceDataHandler.PENDING_SOLAR_SALINITY_KEY_PREFIX + cacheName;
if (!keys.contains(key)) {
keys.add(key);
}
}
/**
* 修改设备输入电压类型