feat(monitor): retain authorized vehicles without locations

This commit is contained in:
lingniu
2026-07-16 16:04:23 +08:00
parent 4688abadef
commit c224907fad
12 changed files with 352 additions and 100 deletions

View File

@@ -411,6 +411,10 @@ func (bounds monitorBounds) contains(longitude, latitude float64) bool {
return longitude >= bounds.minLongitude && longitude <= bounds.maxLongitude && latitude >= bounds.minLatitude && latitude <= bounds.maxLatitude
}
func validRealtimeCoordinate(longitude, latitude float64) bool {
return longitude >= -180 && longitude <= 180 && latitude >= -90 && latitude <= 90 && (longitude != 0 || latitude != 0)
}
func monitorVehicleStatus(row VehicleRealtimeRow) string {
if strings.TrimSpace(row.LastSeen) == "" {
return "unknown"
@@ -480,6 +484,9 @@ func vehicleSearchKeywords(query url.Values) []string {
func matchesMonitorStatus(row VehicleRealtimeRow, requested string) bool {
requested = strings.TrimSpace(requested)
if requested == "no_location" {
return !row.LocationAvailable
}
return requested == "" || monitorVehicleStatus(row) == requested || requested == "online" && row.Online
}
@@ -522,6 +529,11 @@ func (s *Service) buildMonitorSummary(ctx context.Context, query url.Values, veh
continue
}
result.TotalVehicles++
if vehicle.LocationAvailable {
result.LocationVehicles++
} else {
result.NoLocationVehicles++
}
if _, active := activeAlertVINs[vehicle.VIN]; active {
result.AlertVehicles++
}
@@ -607,10 +619,10 @@ func buildMonitorMapResponse(vehicles Page[VehicleRealtimeRow], query url.Values
if !matchesMonitorStatus(vehicle, query.Get("status")) {
continue
}
result.Total++
if vehicle.Longitude < 73 || vehicle.Longitude > 135 || vehicle.Latitude < 18 || vehicle.Latitude > 54 {
if !vehicle.LocationAvailable || vehicle.Longitude < 73 || vehicle.Longitude > 135 || vehicle.Latitude < 18 || vehicle.Latitude > 54 {
continue
}
result.Total++
if hasBounds && !bounds.contains(vehicle.Longitude, vehicle.Latitude) {
continue
}