feat(platform): expose missing vehicle source slots
This commit is contained in:
@@ -56,6 +56,8 @@ type Service struct {
|
||||
runtime RuntimeInfo
|
||||
}
|
||||
|
||||
var canonicalVehicleProtocols = []string{"GB32960", "JT808", "YUTONG_MQTT"}
|
||||
|
||||
func NewService(store Store) *Service {
|
||||
return &Service{store: store}
|
||||
}
|
||||
@@ -278,6 +280,7 @@ func (s *Service) VehicleDetail(ctx context.Context, vin string, protocol string
|
||||
}
|
||||
sourceStatus := vehicleSourceStatus(vehicles.Items, realtime.Items, history.Items, raw.Items, mileage.Items)
|
||||
sourceStatus = s.enrichVehicleSourceStatus(ctx, queryVIN, sourceStatus)
|
||||
sourceStatus = completeVehicleSourceStatus(sourceStatus, protocol)
|
||||
return VehicleDetail{
|
||||
VIN: resolvedVIN,
|
||||
LookupKey: keyword,
|
||||
@@ -834,6 +837,42 @@ func vehicleSourceStatus(vehicles []VehicleRow, realtime []RealtimeLocationRow,
|
||||
return out
|
||||
}
|
||||
|
||||
func completeVehicleSourceStatus(statuses []VehicleSourceStatus, protocol string) []VehicleSourceStatus {
|
||||
protocol = strings.TrimSpace(protocol)
|
||||
if protocol != "" {
|
||||
for _, status := range statuses {
|
||||
if status.Protocol == protocol {
|
||||
return []VehicleSourceStatus{status}
|
||||
}
|
||||
}
|
||||
return []VehicleSourceStatus{{Protocol: protocol}}
|
||||
}
|
||||
byProtocol := map[string]VehicleSourceStatus{}
|
||||
for _, status := range statuses {
|
||||
if strings.TrimSpace(status.Protocol) == "" {
|
||||
continue
|
||||
}
|
||||
byProtocol[status.Protocol] = status
|
||||
}
|
||||
out := make([]VehicleSourceStatus, 0, len(canonicalVehicleProtocols)+len(statuses))
|
||||
seen := map[string]struct{}{}
|
||||
for _, protocol := range canonicalVehicleProtocols {
|
||||
if status, ok := byProtocol[protocol]; ok {
|
||||
out = append(out, status)
|
||||
} else {
|
||||
out = append(out, VehicleSourceStatus{Protocol: protocol})
|
||||
}
|
||||
seen[protocol] = struct{}{}
|
||||
}
|
||||
for _, status := range statuses {
|
||||
if _, ok := seen[status.Protocol]; ok || strings.TrimSpace(status.Protocol) == "" {
|
||||
continue
|
||||
}
|
||||
out = append(out, status)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func buildVehicleServiceStatus(resolved bool, statuses []VehicleSourceStatus) *VehicleServiceStatus {
|
||||
if !resolved {
|
||||
return &VehicleServiceStatus{
|
||||
|
||||
Reference in New Issue
Block a user