Junjie
2026-04-27 892e45141a55bfea0e28c6a34a384f2ce8ee7d16
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package com.zy.core.utils;
 
import com.zy.asrs.entity.DeviceDataLog;
import com.zy.core.enums.RedisKeyType;
import com.zy.core.enums.SlaveType;
 
public class DeviceLogRedisKeyBuilder {
 
    public static String build(DeviceDataLog deviceDataLog) {
        String type = deviceDataLog == null || deviceDataLog.getType() == null
                ? "unknown"
                : deviceDataLog.getType();
        String deviceNo = deviceDataLog == null || deviceDataLog.getDeviceNo() == null
                ? "unknown"
                : String.valueOf(deviceDataLog.getDeviceNo());
        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;
    }
}