feat(platform): use vehicle keyword for data queries

This commit is contained in:
lingniu
2026-07-04 00:42:40 +08:00
parent f62fe13647
commit 20e2781f35
6 changed files with 74 additions and 27 deletions

View File

@@ -26,6 +26,7 @@ type Store interface {
type RawFrameQuery struct {
Protocol string `json:"protocol"`
VIN string `json:"vin"`
Keyword string `json:"keyword"`
DateFrom string `json:"dateFrom"`
DateTo string `json:"dateTo"`
Fields []string `json:"fields"`
@@ -55,7 +56,11 @@ func (s *Service) VehicleCoverage(ctx context.Context, query url.Values) (Page[V
}
func (s *Service) VehicleRealtime(ctx context.Context, query url.Values) (Page[VehicleRealtimeRow], error) {
return s.store.VehicleRealtime(ctx, query)
resolvedQuery, err := s.resolveVehicleQuery(ctx, query)
if err != nil {
return Page[VehicleRealtimeRow]{}, err
}
return s.store.VehicleRealtime(ctx, resolvedQuery)
}
func (s *Service) VehicleDetail(ctx context.Context, vin string, protocol string) (VehicleDetail, error) {
@@ -239,6 +244,9 @@ func (s *Service) RawFrames(ctx context.Context, query RawFrameQuery) (Page[RawF
if query.Limit <= 0 || query.Limit > 500 {
query.Limit = 100
}
if strings.TrimSpace(query.VIN) == "" {
query.VIN = query.Keyword
}
resolvedVIN, err := s.resolveVehicleVIN(ctx, query.VIN, query.Protocol)
if err != nil {
return Page[RawFrameRow]{}, err
@@ -279,7 +287,7 @@ func (s *Service) OpsHealth(ctx context.Context) (OpsHealth, error) {
func (s *Service) resolveVehicleQuery(ctx context.Context, query url.Values) (url.Values, error) {
resolved := cloneValues(query)
vin := strings.TrimSpace(resolved.Get("vin"))
vin := firstNonEmpty(resolved.Get("vin"), resolved.Get("keyword"))
if vin == "" {
return resolved, nil
}