fix(open-platform): align realtime online status across protocols

This commit is contained in:
lingniu
2026-08-03 21:49:33 +08:00
parent 8539af13e6
commit 22f3904ad7
6 changed files with 68 additions and 5 deletions

View File

@@ -162,13 +162,20 @@ ORDER BY l.vin,
return nil, err
}
defer rows.Close()
onlineThreshold := now.Add(-time.Minute)
for rows.Next() {
var point RealtimeVehiclePoint
if err := rows.Scan(&point.VIN, &point.Protocol, &point.Longitude, &point.Latitude, &point.SpeedKmh, &point.TotalMileageKm, &point.ObservedAt); err != nil {
return nil, err
}
if _, exists := out[point.VIN]; !exists {
point.Online = !point.ObservedAt.Before(onlineThreshold)
if selected, exists := out[point.VIN]; !exists {
out[point.VIN] = point
} else if point.Online && !selected.Online {
// The selected source still follows the documented protocol priority, but
// online means that any source for this VIN reported in the last minute.
selected.Online = true
out[point.VIN] = selected
}
}
return out, rows.Err()