fix: 盐度设置,Redis失效问题解决。
This commit is contained in:
@@ -2112,9 +2112,13 @@ public class IotController extends BaseController {
|
||||
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));
|
||||
}
|
||||
// 忽略租户前缀: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);
|
||||
return true;
|
||||
@@ -2137,7 +2141,9 @@ public class IotController extends BaseController {
|
||||
if (serialNum == null || serialNum.isBlank()) {
|
||||
return;
|
||||
}
|
||||
com.intc.common.redis.utils.RedisUtils.deleteObject(DeviceDataHandler.PENDING_SOLAR_SALINITY_KEY_PREFIX + serialNum);
|
||||
TenantHelper.ignore(() ->
|
||||
com.intc.common.redis.utils.RedisUtils.deleteObject(DeviceDataHandler.PENDING_SOLAR_SALINITY_KEY_PREFIX + serialNum)
|
||||
);
|
||||
}
|
||||
|
||||
private java.util.List<String> buildPendingSolarSalinityKeys(Device device) {
|
||||
|
||||
@@ -32,6 +32,7 @@ import com.intc.tdengine.domain.DeviceSensorData;
|
||||
import com.intc.tdengine.service.IDeviceSensorDataService;
|
||||
import com.intc.iot.config.AliyunIotProperties;
|
||||
import com.intc.common.redis.utils.RedisUtils;
|
||||
import com.intc.common.tenant.helper.TenantHelper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
@@ -1045,14 +1046,18 @@ public class DeviceDataHandler {
|
||||
addCacheName(cacheNames, device.getSerialNum());
|
||||
addCacheName(cacheNames, device.getIotId());
|
||||
|
||||
for (String cacheName : cacheNames) {
|
||||
String redisKey = PENDING_SOLAR_SALINITY_KEY_PREFIX + cacheName;
|
||||
Object rawPending = RedisUtils.getCacheObject(redisKey);
|
||||
if (rawPending != null) {
|
||||
return new PendingSolarSalinity(redisKey, rawPending);
|
||||
// 太阳能盐度缓存为跨上下文共享数据(HTTP线程写入 + AMQP消费线程读取),
|
||||
// 必须忽略租户前缀,避免写入带租户前缀而读取不带前缀导致 key 不匹配
|
||||
return TenantHelper.ignore(() -> {
|
||||
for (String cacheName : cacheNames) {
|
||||
String redisKey = PENDING_SOLAR_SALINITY_KEY_PREFIX + cacheName;
|
||||
Object rawPending = RedisUtils.getCacheObject(redisKey);
|
||||
if (rawPending != null) {
|
||||
return new PendingSolarSalinity(redisKey, rawPending);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
private boolean hasPendingSolarSalinity(String deviceName, Device device) {
|
||||
@@ -1077,10 +1082,13 @@ public class DeviceDataHandler {
|
||||
}
|
||||
|
||||
private void clearPendingSolarSalinity(String deviceName, Device device, String matchedRedisKey) {
|
||||
RedisUtils.deleteObject(matchedRedisKey);
|
||||
deletePendingSolarSalinityByName(deviceName);
|
||||
deletePendingSolarSalinityByName(device.getSerialNum());
|
||||
deletePendingSolarSalinityByName(device.getIotId());
|
||||
// 忽略租户前缀,确保与写入侧 key 一致(写入在 HTTP 线程,删除在 AMQP 线程)
|
||||
TenantHelper.ignore(() -> {
|
||||
RedisUtils.deleteObject(matchedRedisKey);
|
||||
deletePendingSolarSalinityByName(deviceName);
|
||||
deletePendingSolarSalinityByName(device.getSerialNum());
|
||||
deletePendingSolarSalinityByName(device.getIotId());
|
||||
});
|
||||
}
|
||||
|
||||
private void deletePendingSolarSalinityByName(String cacheName) {
|
||||
|
||||
Reference in New Issue
Block a user