fix: 盐度设置,功能优化,打印日志。

This commit is contained in:
tianyongbao
2026-06-29 10:39:50 +08:00
parent 4c60e3a66f
commit f6f968b6a0
2 changed files with 145 additions and 23 deletions

View File

@@ -2100,16 +2100,23 @@ public class IotController extends BaseController {
private boolean cachePendingSolarSalinity(Device device, Double salinityCompensation) {
try {
String key = DeviceDataHandler.PENDING_SOLAR_SALINITY_KEY_PREFIX + device.getSerialNum();
Map<String, Object> cacheValue = new java.util.HashMap<>();
cacheValue.put("deviceId", device.getId());
cacheValue.put("iotId", device.getIotId());
cacheValue.put("serialNum", device.getSerialNum());
cacheValue.put("salinityCompensation", salinityCompensation);
cacheValue.put("updatedAt", System.currentTimeMillis());
com.intc.common.redis.utils.RedisUtils.setCacheObject(key, cn.hutool.json.JSONUtil.toJsonStr(cacheValue), Duration.ofDays(7));
log.info("太阳能网控盐度已缓存,等待上线补发: deviceId={}, serialNum={}, salinityCompensation={}",
device.getId(), device.getSerialNum(), salinityCompensation);
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;
}
for (String key : cacheKeys) {
com.intc.common.redis.utils.RedisUtils.setCacheObject(key, cacheJson, Duration.ofDays(7));
}
log.info("太阳能网控盐度已缓存,等待上线补发: deviceId={}, serialNum={}, iotId={}, cacheKeys={}, salinityCompensation={}",
device.getId(), device.getSerialNum(), device.getIotId(), cacheKeys, salinityCompensation);
return true;
} catch (Exception e) {
log.error("缓存太阳能网控盐度失败: deviceId={}, serialNum={}, err={}",
@@ -2133,6 +2140,23 @@ public class IotController extends BaseController {
com.intc.common.redis.utils.RedisUtils.deleteObject(DeviceDataHandler.PENDING_SOLAR_SALINITY_KEY_PREFIX + serialNum);
}
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);
}
}
/**
* 修改设备输入电压类型
*