chore: remove in-memory identity store

This commit is contained in:
lingniu
2026-07-01 14:58:39 +08:00
parent faeee0c2a8
commit 5910d23dd9
3 changed files with 12 additions and 129 deletions

View File

@@ -1,82 +0,0 @@
package com.lingniu.ingest.identity;
import com.lingniu.ingest.api.ProtocolId;
import java.util.Locale;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
public final class InMemoryVehicleIdentityService implements VehicleIdentityResolver, VehicleIdentityRegistry {
private final ConcurrentMap<String, String> phoneToVin = new ConcurrentHashMap<>();
private final ConcurrentMap<String, String> deviceIdToVin = new ConcurrentHashMap<>();
private final ConcurrentMap<String, String> plateToVin = new ConcurrentHashMap<>();
@Override
public void bind(VehicleIdentityBinding binding) {
if (binding == null || !binding.hasResolvedVin()) {
return;
}
if (!binding.phone().isBlank()) {
phoneToVin.put(key(binding.protocol(), binding.phone()), binding.vin());
}
if (!binding.deviceId().isBlank()) {
deviceIdToVin.put(key(binding.protocol(), binding.deviceId()), binding.vin());
}
if (!binding.plate().isBlank()) {
plateToVin.put(key(binding.protocol(), binding.plate()), binding.vin());
}
}
@Override
public VehicleIdentity resolve(VehicleIdentityLookup lookup) {
if (lookup == null) {
return new VehicleIdentity("unknown", false, VehicleIdentitySource.UNKNOWN);
}
if (!lookup.vin().isBlank()) {
// 协议报文已经携带可信 VIN 时直接采用;绑定表主要服务 JT808/MQTT/信达这类外部 ID。
return new VehicleIdentity(lookup.vin(), true, VehicleIdentitySource.EXPLICIT_VIN);
}
// 绑定优先级phone > deviceId > plate。顺序要稳定否则同一车辆多外部号会产生不同内部 VIN。
VehicleIdentity phone = resolveBound(phoneToVin, lookup.protocol(), lookup.phone(), VehicleIdentitySource.BOUND_PHONE);
if (phone != null) return phone;
VehicleIdentity device = resolveBound(deviceIdToVin, lookup.protocol(), lookup.deviceId(), VehicleIdentitySource.BOUND_DEVICE_ID);
if (device != null) return device;
VehicleIdentity plate = resolveBound(plateToVin, lookup.protocol(), lookup.plate(), VehicleIdentitySource.BOUND_PLATE);
if (plate != null) return plate;
if (!lookup.deviceId().isBlank()) {
// fallback 不是已确认绑定只用于不中断接收和冷存metadata.identityResolved=false 会保留这个事实。
return new VehicleIdentity(lookup.deviceId(), false, VehicleIdentitySource.FALLBACK_DEVICE_ID);
}
if (!lookup.phone().isBlank()) {
return new VehicleIdentity(lookup.phone(), false, VehicleIdentitySource.FALLBACK_PHONE);
}
if (!lookup.plate().isBlank()) {
return new VehicleIdentity(lookup.plate(), false, VehicleIdentitySource.FALLBACK_PLATE);
}
return new VehicleIdentity("unknown", false, VehicleIdentitySource.UNKNOWN);
}
private static VehicleIdentity resolveBound(ConcurrentMap<String, String> map,
ProtocolId protocol,
String externalId,
VehicleIdentitySource source) {
if (externalId == null || externalId.isBlank()) {
return null;
}
String vin = map.get(key(protocol, externalId));
if (vin == null) {
return null;
}
return new VehicleIdentity(vin, true, source);
}
private static String key(ProtocolId protocol, String value) {
String p = protocol == null ? "UNKNOWN" : protocol.name();
// 绑定 key 带协议前缀,避免 JT808 phone 与 MQTT deviceId 数值相同时互相覆盖。
return p + ":" + value.trim().toUpperCase(Locale.ROOT);
}
}