feat(platform): enrich history locations with plates

This commit is contained in:
lingniu
2026-07-03 23:14:40 +08:00
parent 55b069e27d
commit a644a6617c
2 changed files with 53 additions and 3 deletions

View File

@@ -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

View File

@@ -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 (
<div className="vp-page">
<PageHeader title="历史查询" description="位置历史和 RAW 帧历史的分页查询工作台" />
<PageHeader title="历史查询" description="按车辆查询位置历史和 RAW 帧历史,协议作为来源过滤和诊断维度" />
<Card bordered>
<Form initValues={filters} layout="horizontal" onSubmit={(values) => submit(values)}>
<Form.Input field="vin" label="VIN" placeholder="输入 VIN" style={{ width: 260 }} />