feat(platform): return service status in vehicle overview
This commit is contained in:
@@ -224,6 +224,9 @@ func TestHandlerVehicleServiceOverviewEndpoint(t *testing.T) {
|
|||||||
if body.Data.SourceCount != 2 || body.Data.OnlineSourceCount != 1 || body.Data.CoverageStatus != "partial" {
|
if body.Data.SourceCount != 2 || body.Data.OnlineSourceCount != 1 || body.Data.CoverageStatus != "partial" {
|
||||||
t.Fatalf("overview endpoint should summarize vehicle service coverage, got %+v", body.Data)
|
t.Fatalf("overview endpoint should summarize vehicle service coverage, got %+v", body.Data)
|
||||||
}
|
}
|
||||||
|
if body.Data.ServiceStatus == nil || body.Data.ServiceStatus.Status != "degraded" || body.Data.ServiceStatus.Title != "部分来源离线" {
|
||||||
|
t.Fatalf("overview endpoint should expose canonical service status, got %+v", body.Data.ServiceStatus)
|
||||||
|
}
|
||||||
if strings.Contains(rec.Body.String(), `"raw"`) || strings.Contains(rec.Body.String(), `"history"`) {
|
if strings.Contains(rec.Body.String(), `"raw"`) || strings.Contains(rec.Body.String(), `"history"`) {
|
||||||
t.Fatalf("overview endpoint should not return heavy detail pages: %s", rec.Body.String())
|
t.Fatalf("overview endpoint should not return heavy detail pages: %s", rec.Body.String())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,21 +95,22 @@ type VehicleDetail struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type VehicleServiceOverview struct {
|
type VehicleServiceOverview struct {
|
||||||
VIN string `json:"vin"`
|
VIN string `json:"vin"`
|
||||||
Plate string `json:"plate"`
|
Plate string `json:"plate"`
|
||||||
Phone string `json:"phone"`
|
Phone string `json:"phone"`
|
||||||
OEM string `json:"oem"`
|
OEM string `json:"oem"`
|
||||||
Protocols []string `json:"protocols"`
|
Protocols []string `json:"protocols"`
|
||||||
PrimaryProtocol string `json:"primaryProtocol"`
|
PrimaryProtocol string `json:"primaryProtocol"`
|
||||||
CoverageStatus string `json:"coverageStatus"`
|
CoverageStatus string `json:"coverageStatus"`
|
||||||
SourceCount int `json:"sourceCount"`
|
SourceCount int `json:"sourceCount"`
|
||||||
OnlineSourceCount int `json:"onlineSourceCount"`
|
OnlineSourceCount int `json:"onlineSourceCount"`
|
||||||
LastSeen string `json:"lastSeen"`
|
LastSeen string `json:"lastSeen"`
|
||||||
RealtimeCount int `json:"realtimeCount"`
|
RealtimeCount int `json:"realtimeCount"`
|
||||||
HistoryCount int `json:"historyCount"`
|
HistoryCount int `json:"historyCount"`
|
||||||
RawCount int `json:"rawCount"`
|
RawCount int `json:"rawCount"`
|
||||||
MileageCount int `json:"mileageCount"`
|
MileageCount int `json:"mileageCount"`
|
||||||
QualityIssueCount int `json:"qualityIssueCount"`
|
QualityIssueCount int `json:"qualityIssueCount"`
|
||||||
|
ServiceStatus *VehicleServiceStatus `json:"serviceStatus,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type VehicleServiceStatus struct {
|
type VehicleServiceStatus struct {
|
||||||
|
|||||||
@@ -296,9 +296,33 @@ func buildVehicleServiceOverview(vin string, lookupKey string, resolution *Vehic
|
|||||||
overview.PrimaryProtocol = overview.Protocols[0]
|
overview.PrimaryProtocol = overview.Protocols[0]
|
||||||
}
|
}
|
||||||
overview.CoverageStatus = coverageStatus(overview.SourceCount, overview.OnlineSourceCount)
|
overview.CoverageStatus = coverageStatus(overview.SourceCount, overview.OnlineSourceCount)
|
||||||
|
resolved := identity != nil && strings.TrimSpace(identity.VIN) != ""
|
||||||
|
if !resolved && resolution != nil {
|
||||||
|
resolved = resolution.Resolved
|
||||||
|
}
|
||||||
|
overview.ServiceStatus = buildVehicleServiceStatus(resolved, statusesForOverview(overview))
|
||||||
return overview
|
return overview
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func statusesForOverview(overview *VehicleServiceOverview) []VehicleSourceStatus {
|
||||||
|
statuses := make([]VehicleSourceStatus, 0, overview.SourceCount)
|
||||||
|
for index, protocol := range overview.Protocols {
|
||||||
|
statuses = append(statuses, VehicleSourceStatus{
|
||||||
|
Protocol: protocol,
|
||||||
|
Online: index < overview.OnlineSourceCount,
|
||||||
|
LastSeen: overview.LastSeen,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
for len(statuses) < overview.SourceCount {
|
||||||
|
statuses = append(statuses, VehicleSourceStatus{
|
||||||
|
Protocol: "UNKNOWN",
|
||||||
|
Online: len(statuses) < overview.OnlineSourceCount,
|
||||||
|
LastSeen: overview.LastSeen,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return statuses
|
||||||
|
}
|
||||||
|
|
||||||
func pageCount(total int, itemCount int) int {
|
func pageCount(total int, itemCount int) int {
|
||||||
if total > 0 {
|
if total > 0 {
|
||||||
return total
|
return total
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ export default function App() {
|
|||||||
const overview = await api.vehicleServiceOverview(new URLSearchParams({ keyword: lookupKey }));
|
const overview = await api.vehicleServiceOverview(new URLSearchParams({ keyword: lookupKey }));
|
||||||
const nextKey = overview.vin || lookupKey;
|
const nextKey = overview.vin || lookupKey;
|
||||||
const resolved = Boolean(overview.vin);
|
const resolved = Boolean(overview.vin);
|
||||||
setCurrentVehicleStatus(serviceStatusFromOverview(overview));
|
setCurrentVehicleStatus(overview.serviceStatus ?? serviceStatusFromOverview(overview));
|
||||||
setCurrentVehicleLabel(resolved ? [overview.plate, overview.vin || nextKey].filter(Boolean).join(' / ') : lookupKey);
|
setCurrentVehicleLabel(resolved ? [overview.plate, overview.vin || nextKey].filter(Boolean).join(' / ') : lookupKey);
|
||||||
return { resolved, nextKey, overview };
|
return { resolved, nextKey, overview };
|
||||||
}, []);
|
}, []);
|
||||||
|
|||||||
@@ -83,7 +83,15 @@ test('vehicleServiceOverview sends keyword to the lightweight overview endpoint'
|
|||||||
historyCount: 0,
|
historyCount: 0,
|
||||||
rawCount: 0,
|
rawCount: 0,
|
||||||
mileageCount: 0,
|
mileageCount: 0,
|
||||||
qualityIssueCount: 0
|
qualityIssueCount: 0,
|
||||||
|
serviceStatus: {
|
||||||
|
status: 'degraded',
|
||||||
|
severity: 'warning',
|
||||||
|
title: '部分来源离线',
|
||||||
|
detail: '1/2 个来源在线',
|
||||||
|
sourceCount: 2,
|
||||||
|
onlineSourceCount: 1
|
||||||
|
}
|
||||||
},
|
},
|
||||||
traceId: 'trace-test',
|
traceId: 'trace-test',
|
||||||
timestamp: 1783094400000
|
timestamp: 1783094400000
|
||||||
@@ -94,6 +102,7 @@ test('vehicleServiceOverview sends keyword to the lightweight overview endpoint'
|
|||||||
|
|
||||||
expect(fetchMock).toHaveBeenCalledWith('/api/vehicle-service/overview?keyword=%E7%B2%A4AG18312', undefined);
|
expect(fetchMock).toHaveBeenCalledWith('/api/vehicle-service/overview?keyword=%E7%B2%A4AG18312', undefined);
|
||||||
expect(result.coverageStatus).toBe('partial');
|
expect(result.coverageStatus).toBe('partial');
|
||||||
|
expect(result.serviceStatus?.status).toBe('degraded');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('api errors include backend message, detail, and trace id', async () => {
|
test('api errors include backend message, detail, and trace id', async () => {
|
||||||
|
|||||||
@@ -107,6 +107,7 @@ export interface VehicleServiceOverview {
|
|||||||
rawCount: number;
|
rawCount: number;
|
||||||
mileageCount: number;
|
mileageCount: number;
|
||||||
qualityIssueCount: number;
|
qualityIssueCount: number;
|
||||||
|
serviceStatus?: VehicleServiceStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface VehicleServiceStatus {
|
export interface VehicleServiceStatus {
|
||||||
|
|||||||
@@ -100,7 +100,15 @@ test('shows resolved vehicle service status after topbar search', async () => {
|
|||||||
historyCount: 0,
|
historyCount: 0,
|
||||||
rawCount: 0,
|
rawCount: 0,
|
||||||
mileageCount: 0,
|
mileageCount: 0,
|
||||||
qualityIssueCount: 0
|
qualityIssueCount: 0,
|
||||||
|
serviceStatus: {
|
||||||
|
status: 'degraded',
|
||||||
|
severity: 'warning',
|
||||||
|
title: '后端判定部分离线',
|
||||||
|
detail: '后端统一车辆服务状态',
|
||||||
|
sourceCount: 2,
|
||||||
|
onlineSourceCount: 1
|
||||||
|
}
|
||||||
},
|
},
|
||||||
traceId: 'trace-test',
|
traceId: 'trace-test',
|
||||||
timestamp: 1783094400000
|
timestamp: 1783094400000
|
||||||
@@ -143,7 +151,7 @@ test('shows resolved vehicle service status after topbar search', async () => {
|
|||||||
fireEvent.change(screen.getByPlaceholderText('搜索 VIN / 车牌 / 手机号'), { target: { value: '粤AG18312' } });
|
fireEvent.change(screen.getByPlaceholderText('搜索 VIN / 车牌 / 手机号'), { target: { value: '粤AG18312' } });
|
||||||
fireEvent.click(screen.getByRole('button', { name: '查询车辆' }));
|
fireEvent.click(screen.getByRole('button', { name: '查询车辆' }));
|
||||||
|
|
||||||
expect(await screen.findByText('当前车辆:部分来源离线')).toBeInTheDocument();
|
expect(await screen.findByText('当前车辆:后端判定部分离线')).toBeInTheDocument();
|
||||||
expect(screen.getByText('粤AG18312 / LB9A32A24R0LS1426')).toBeInTheDocument();
|
expect(screen.getByText('粤AG18312 / LB9A32A24R0LS1426')).toBeInTheDocument();
|
||||||
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('/api/vehicle-service/overview?keyword=%E7%B2%A4AG18312'), undefined);
|
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('/api/vehicle-service/overview?keyword=%E7%B2%A4AG18312'), undefined);
|
||||||
expect(fetchMock).not.toHaveBeenCalledWith(expect.stringContaining('/api/vehicles/resolve'), undefined);
|
expect(fetchMock).not.toHaveBeenCalledWith(expect.stringContaining('/api/vehicles/resolve'), undefined);
|
||||||
|
|||||||
Reference in New Issue
Block a user