diff --git a/vehicle-data-platform/apps/api/internal/platform/production_store.go b/vehicle-data-platform/apps/api/internal/platform/production_store.go index 15fe0c21..9444fe9a 100644 --- a/vehicle-data-platform/apps/api/internal/platform/production_store.go +++ b/vehicle-data-platform/apps/api/internal/platform/production_store.go @@ -285,9 +285,60 @@ func (s *ProductionStore) HistoryLocationsFromTDengine(ctx context.Context, quer if built.CountText == "" { total = len(items) } + if err := s.enrichHistoryLocationPlates(ctx, items); err != nil { + return Page[HistoryLocationRow]{}, err + } return Page[HistoryLocationRow]{Items: items, Total: total, Limit: limit, Offset: offset}, nil } +func (s *ProductionStore) enrichHistoryLocationPlates(ctx context.Context, items []HistoryLocationRow) error { + vins := make([]string, 0) + seen := map[string]struct{}{} + for _, item := range items { + vin := strings.TrimSpace(item.VIN) + if vin == "" { + continue + } + if _, ok := seen[vin]; ok { + continue + } + seen[vin] = struct{}{} + vins = append(vins, vin) + } + if len(vins) == 0 { + return nil + } + placeholders := make([]string, len(vins)) + args := make([]any, len(vins)) + for index, vin := range vins { + placeholders[index] = "?" + args[index] = vin + } + rows, err := s.db.QueryContext(ctx, `SELECT vin, COALESCE(plate, '') FROM vehicle_identity_binding WHERE vin IN (`+strings.Join(placeholders, ",")+`)`, args...) + if err != nil { + return err + } + defer rows.Close() + plates := map[string]string{} + for rows.Next() { + var vin, plate string + if err := rows.Scan(&vin, &plate); err != nil { + return err + } + plates[vin] = plate + } + if err := rows.Err(); err != nil { + return err + } + for index := range items { + if strings.TrimSpace(items[index].Plate) != "" { + continue + } + items[index].Plate = plates[items[index].VIN] + } + return nil +} + func (s *ProductionStore) RawFrames(ctx context.Context, query RawFrameQuery) (Page[RawFrameRow], error) { if s.tdengine == nil { return Page[RawFrameRow]{Items: []RawFrameRow{}, Total: 0, Limit: query.Limit, Offset: query.Offset}, nil diff --git a/vehicle-data-platform/apps/web/src/pages/History.tsx b/vehicle-data-platform/apps/web/src/pages/History.tsx index 2f918160..4670397f 100644 --- a/vehicle-data-platform/apps/web/src/pages/History.tsx +++ b/vehicle-data-platform/apps/web/src/pages/History.tsx @@ -15,9 +15,8 @@ type HistoryFilters = { }; const defaultFilters: HistoryFilters = { - protocol: 'GB32960', vin: 'LB9A32A24R0LS1426', - includeFields: true + includeFields: false }; const defaultPage = { items: [], total: 0, limit: 10, offset: 0 }; @@ -94,7 +93,7 @@ export function History() { return (