fix(gateway): prefer known JT808 identity snapshot
This commit is contained in:
@@ -612,6 +612,13 @@ func (r *MySQLResolver) enrichResolvedJT808SourceMetadata(ctx context.Context, e
|
||||
func (r *MySQLResolver) lookupJT808Registration(ctx context.Context, phone string) (vin string, deviceID string, plate string, cacheStatus string, err error) {
|
||||
phone = normalizePhone(phone)
|
||||
now := time.Now()
|
||||
// The immutable snapshot is the authoritative vehicle binding. Registration
|
||||
// and authentication frames can create a short-lived local session whose VIN
|
||||
// is still "unknown"; letting that session win would permanently mask a known
|
||||
// snapshot because every location frame refreshes the session TTL.
|
||||
if snapshot, ok := r.snapshotRegistration(phone); ok && snapshot.canResolveVehicle() {
|
||||
return snapshot.vin, snapshot.deviceID, snapshot.plate, "snapshot", nil
|
||||
}
|
||||
var stale registrationCacheEntry
|
||||
hasStale := false
|
||||
r.lookupMu.Lock()
|
||||
@@ -659,6 +666,11 @@ func (r *MySQLResolver) lookupJT808Registration(ctx context.Context, phone strin
|
||||
return entry.vin, entry.deviceID, entry.plate, "", nil
|
||||
}
|
||||
|
||||
func (e registrationCacheEntry) canResolveVehicle() bool {
|
||||
vin := strings.TrimSpace(e.vin)
|
||||
return (vin != "" && !strings.EqualFold(vin, "unknown")) || strings.TrimSpace(e.plate) != ""
|
||||
}
|
||||
|
||||
func addIdentityMetadata(parsed map[string]any, source string, value string) {
|
||||
if parsed == nil {
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user