feat: expose vehicle map data APIs

This commit is contained in:
lingniu
2026-08-03 19:55:38 +08:00
parent 3c4bece72c
commit 8539af13e6
8 changed files with 492 additions and 7 deletions

View File

@@ -17,10 +17,12 @@ import (
)
const (
HydrogenQueryPath = "/api/v1/vehicles/hydrogen-consumption/query"
MileageQueryPath = "/api/v1/vehicles/mileage/query"
MileageRangeQueryPath = "/api/v1/vehicles/mileage/range/query"
TotalMileageQueryPath = "/api/v1/vehicles/total-mileage/query"
HydrogenQueryPath = "/api/v1/vehicles/hydrogen-consumption/query"
MileageQueryPath = "/api/v1/vehicles/mileage/query"
MileageRangeQueryPath = "/api/v1/vehicles/mileage/range/query"
TotalMileageQueryPath = "/api/v1/vehicles/total-mileage/query"
RealtimeVehicleQueryPath = "/api/v1/vehicles/realtime/query"
HydrogenStationQueryPath = "/api/v1/hydrogen-stations/query"
)
type Handler struct {
@@ -59,6 +61,8 @@ func (h *Handler) registerExternalDataRoutes() {
h.mux.HandleFunc("POST "+MileageQueryPath, h.mileage)
h.mux.HandleFunc("POST "+MileageRangeQueryPath, h.mileageRange)
h.mux.HandleFunc("POST "+TotalMileageQueryPath, h.totalMileage)
h.mux.HandleFunc("POST "+RealtimeVehicleQueryPath, h.realtimeVehicles)
h.mux.HandleFunc("POST "+HydrogenStationQueryPath, h.hydrogenStations)
}
func (h *Handler) registerAdminAppRoutes() {
@@ -106,6 +110,8 @@ func NewDataHandler(service *Service) *Handler {
handler.mux.HandleFunc("POST "+MileageQueryPath, handler.mileage)
handler.mux.HandleFunc("POST "+MileageRangeQueryPath, handler.mileageRange)
handler.mux.HandleFunc("POST "+TotalMileageQueryPath, handler.totalMileage)
handler.mux.HandleFunc("POST "+RealtimeVehicleQueryPath, handler.realtimeVehicles)
handler.mux.HandleFunc("POST "+HydrogenStationQueryPath, handler.hydrogenStations)
return handler
}
@@ -114,7 +120,35 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
func IsPublicPath(path string) bool {
return path == HydrogenQueryPath || path == MileageQueryPath || path == MileageRangeQueryPath || path == TotalMileageQueryPath
return path == HydrogenQueryPath || path == MileageQueryPath || path == MileageRangeQueryPath || path == TotalMileageQueryPath || path == RealtimeVehicleQueryPath || path == HydrogenStationQueryPath
}
func (h *Handler) realtimeVehicles(w http.ResponseWriter, r *http.Request) {
traceID := externalTraceID(r)
var request RealtimeVehicleRequest
if !decodeExternalBody(w, r, traceID, &request) {
return
}
data, err := h.service.QueryRealtimeVehicles(r.Context(), externalBearer(r), traceID, request)
if err != nil {
writeExternalError(w, traceID, err)
return
}
writeExternal(w, http.StatusOK, ExternalResponse{Code: "SUCCESS", Message: "success", Data: data, TraceID: traceID})
}
func (h *Handler) hydrogenStations(w http.ResponseWriter, r *http.Request) {
traceID := externalTraceID(r)
var request HydrogenStationRequest
if !decodeExternalBody(w, r, traceID, &request) {
return
}
data, err := h.service.QueryHydrogenStations(r.Context(), externalBearer(r), traceID, request)
if err != nil {
writeExternalError(w, traceID, err)
return
}
writeExternal(w, http.StatusOK, ExternalResponse{Code: "SUCCESS", Message: "success", Data: data, TraceID: traceID})
}
func (h *Handler) hydrogen(w http.ResponseWriter, r *http.Request) {
@@ -725,5 +759,17 @@ func dataProducts() []DataProduct {
Version: "v1", Status: "available", Method: http.MethodPost,
Path: TotalMileageQueryPath, Unit: "km",
},
{
Code: "realtime_vehicle", Name: "车辆实时位置与状态",
Description: "查询应用授权车辆的最新位置、在线状态、速度、总里程和采集协议。",
Version: "v1", Status: "available", Method: http.MethodPost,
Path: RealtimeVehicleQueryPath, Unit: "",
},
{
Code: "hydrogen_station", Name: "加氢站地图点位",
Description: "只读查询资产管理库中的加氢站名称、经纬度、行政区划和合作状态。",
Version: "v1", Status: "available", Method: http.MethodPost,
Path: HydrogenStationQueryPath, Unit: "座",
},
}
}