feat(platform): enrich history locations with plates
This commit is contained in:
@@ -285,9 +285,60 @@ func (s *ProductionStore) HistoryLocationsFromTDengine(ctx context.Context, quer
|
|||||||
if built.CountText == "" {
|
if built.CountText == "" {
|
||||||
total = len(items)
|
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
|
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) {
|
func (s *ProductionStore) RawFrames(ctx context.Context, query RawFrameQuery) (Page[RawFrameRow], error) {
|
||||||
if s.tdengine == nil {
|
if s.tdengine == nil {
|
||||||
return Page[RawFrameRow]{Items: []RawFrameRow{}, Total: 0, Limit: query.Limit, Offset: query.Offset}, nil
|
return Page[RawFrameRow]{Items: []RawFrameRow{}, Total: 0, Limit: query.Limit, Offset: query.Offset}, nil
|
||||||
|
|||||||
@@ -15,9 +15,8 @@ type HistoryFilters = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const defaultFilters: HistoryFilters = {
|
const defaultFilters: HistoryFilters = {
|
||||||
protocol: 'GB32960',
|
|
||||||
vin: 'LB9A32A24R0LS1426',
|
vin: 'LB9A32A24R0LS1426',
|
||||||
includeFields: true
|
includeFields: false
|
||||||
};
|
};
|
||||||
|
|
||||||
const defaultPage = { items: [], total: 0, limit: 10, offset: 0 };
|
const defaultPage = { items: [], total: 0, limit: 10, offset: 0 };
|
||||||
@@ -94,7 +93,7 @@ export function History() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="vp-page">
|
<div className="vp-page">
|
||||||
<PageHeader title="历史查询" description="位置历史和 RAW 帧历史的分页查询工作台" />
|
<PageHeader title="历史查询" description="按车辆查询位置历史和 RAW 帧历史,协议作为来源过滤和诊断维度" />
|
||||||
<Card bordered>
|
<Card bordered>
|
||||||
<Form initValues={filters} layout="horizontal" onSubmit={(values) => submit(values)}>
|
<Form initValues={filters} layout="horizontal" onSubmit={(values) => submit(values)}>
|
||||||
<Form.Input field="vin" label="VIN" placeholder="输入 VIN" style={{ width: 260 }} />
|
<Form.Input field="vin" label="VIN" placeholder="输入 VIN" style={{ width: 260 }} />
|
||||||
|
|||||||
Reference in New Issue
Block a user