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