refactor: use stateless identity fallback

This commit is contained in:
lingniu
2026-07-01 02:58:38 +08:00
parent 1ce4f80161
commit 7a245215b8
7 changed files with 111 additions and 12 deletions

View File

@@ -0,0 +1,34 @@
package com.lingniu.ingest.identity;
/**
* Stateless production fallback used when a caller has no injected identity service.
*
* <p>Persistent binding belongs to {@link MySqlVehicleIdentityService}; this resolver only keeps
* ingestion flowing with explicit VIN or stable external identifiers.
*/
public final class StatelessVehicleIdentityResolver implements VehicleIdentityResolver {
@Override
public VehicleIdentity resolve(VehicleIdentityLookup lookup) {
if (lookup == null) {
return unknown();
}
if (!lookup.vin().isBlank()) {
return new VehicleIdentity(lookup.vin(), true, VehicleIdentitySource.EXPLICIT_VIN);
}
if (!lookup.deviceId().isBlank()) {
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 unknown();
}
private static VehicleIdentity unknown() {
return new VehicleIdentity("unknown", false, VehicleIdentitySource.UNKNOWN);
}
}