#
Junjie
9 天以前 dc3f9cc91759823ce59486f19b138be4b296a0f1
src/main/java/com/zy/core/utils/DeviceLogRedisKeyBuilder.java
@@ -2,8 +2,7 @@
import com.zy.asrs.entity.DeviceDataLog;
import com.zy.core.enums.RedisKeyType;
import java.util.UUID;
import com.zy.core.enums.SlaveType;
public class DeviceLogRedisKeyBuilder {
@@ -14,10 +13,17 @@
        String deviceNo = deviceDataLog == null || deviceDataLog.getDeviceNo() == null
                ? "unknown"
                : String.valueOf(deviceDataLog.getDeviceNo());
        long millis = deviceDataLog != null && deviceDataLog.getCreateTime() != null
                ? deviceDataLog.getCreateTime().getTime()
                : System.currentTimeMillis();
        String uuid = UUID.randomUUID().toString().replace("-", "");
        return RedisKeyType.DEVICE_LOG_KEY.key + type + ":" + deviceNo + ":" + millis + ":" + uuid;
        String stationPart = buildStationPart(deviceDataLog, type);
        // 日志发布器按 lane 只保留最新快照,Redis key 必须稳定,否则会把每次采样都堆成独立 key,
        // 让 DeviceLogScheduler 的消费速度永远追不上写入速度,最终把 Redis 内存打爆。
        return RedisKeyType.DEVICE_LOG_KEY.key + type + ":" + deviceNo + stationPart;
    }
    private static String buildStationPart(DeviceDataLog deviceDataLog, String type) {
        if (!String.valueOf(SlaveType.Devp).equals(type)) {
            return "";
        }
        Integer stationId = deviceDataLog == null ? null : deviceDataLog.getStationId();
        return stationId == null ? ":station:unknown" : ":station:" + stationId;
    }
}