feat(platform): summarize missing vehicle sources
This commit is contained in:
@@ -144,6 +144,12 @@ export interface VehicleServiceSummary {
|
||||
identityRequiredVehicles: number;
|
||||
serviceStatuses: ServiceStatusStat[];
|
||||
protocols: ProtocolStat[];
|
||||
missingSources: MissingSourceStat[];
|
||||
}
|
||||
|
||||
export interface MissingSourceStat {
|
||||
protocol: string;
|
||||
count: number;
|
||||
}
|
||||
|
||||
export interface VehicleServiceStatus {
|
||||
|
||||
@@ -120,6 +120,7 @@ export function Dashboard({ onOpenVehicle, onOpenQuality, onOpenVehicles }: { on
|
||||
{ label: '暂无来源车辆', value: formatCount(serviceSummary?.noDataVehicles), filters: { serviceStatus: 'no_data' } },
|
||||
{ label: '身份未绑定', value: formatCount(serviceSummary?.identityRequiredVehicles), filters: { serviceStatus: 'identity_required' } }
|
||||
];
|
||||
const missingSourceCounts = new Map((serviceSummary?.missingSources ?? []).map((item) => [item.protocol, item.count]));
|
||||
|
||||
return (
|
||||
<div className="vp-page">
|
||||
@@ -175,6 +176,24 @@ export function Dashboard({ onOpenVehicle, onOpenQuality, onOpenVehicles }: { on
|
||||
{
|
||||
title: '在线率',
|
||||
render: (_: unknown, row: ProtocolStat) => `${Math.round((row.online / row.total) * 100)}%`
|
||||
},
|
||||
{
|
||||
title: '缺失车辆',
|
||||
render: (_: unknown, row: ProtocolStat) => {
|
||||
const missingCount = missingSourceCounts.get(row.protocol);
|
||||
if (missingCount == null) {
|
||||
return '-';
|
||||
}
|
||||
return (
|
||||
<Button
|
||||
aria-label={`查看缺 ${row.protocol}`}
|
||||
size="small"
|
||||
onClick={() => loadCoverage({ missingProtocol: row.protocol })}
|
||||
>
|
||||
{formatCount(missingCount)}
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
}
|
||||
]}
|
||||
/>
|
||||
|
||||
@@ -128,6 +128,72 @@ test('dashboard renders vehicle service summary metrics', async () => {
|
||||
expect(fetchMock).toHaveBeenCalledWith('/api/vehicle-service/summary', undefined);
|
||||
});
|
||||
|
||||
test('opens dashboard coverage from missing source distribution', async () => {
|
||||
window.history.replaceState(null, '', '/#/dashboard');
|
||||
const fetchMock = vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
|
||||
const path = String(input);
|
||||
if (path.includes('/api/dashboard/summary')) {
|
||||
return {
|
||||
ok: true,
|
||||
json: async () => ({
|
||||
data: {
|
||||
onlineVehicles: 3,
|
||||
activeToday: 4,
|
||||
frameToday: 1286320,
|
||||
issueVehicles: 7,
|
||||
kafkaLag: 0,
|
||||
protocols: [],
|
||||
serviceStatuses: [],
|
||||
linkHealth: []
|
||||
},
|
||||
traceId: 'trace-test',
|
||||
timestamp: 1783094400000
|
||||
})
|
||||
} as Response;
|
||||
}
|
||||
if (path.includes('/api/vehicle-service/summary')) {
|
||||
return {
|
||||
ok: true,
|
||||
json: async () => ({
|
||||
data: {
|
||||
totalVehicles: 1033,
|
||||
boundVehicles: 1024,
|
||||
onlineVehicles: 208,
|
||||
singleSourceVehicles: 391,
|
||||
multiSourceVehicles: 181,
|
||||
noDataVehicles: 461,
|
||||
identityRequiredVehicles: 9,
|
||||
serviceStatuses: [],
|
||||
protocols: [{ protocol: 'YUTONG_MQTT', online: 1, total: 8 }],
|
||||
missingSources: [{ protocol: 'YUTONG_MQTT', count: 983 }]
|
||||
},
|
||||
traceId: 'trace-test',
|
||||
timestamp: 1783094400000
|
||||
})
|
||||
} as Response;
|
||||
}
|
||||
return {
|
||||
ok: true,
|
||||
json: async () => ({
|
||||
data: { items: [], total: 0, limit: 8, offset: 0 },
|
||||
traceId: 'trace-test',
|
||||
timestamp: 1783094400000
|
||||
})
|
||||
} as Response;
|
||||
});
|
||||
|
||||
render(<App />);
|
||||
|
||||
expect(await screen.findByText('缺失车辆')).toBeInTheDocument();
|
||||
expect(screen.getByText('983')).toBeInTheDocument();
|
||||
fireEvent.click(screen.getByRole('button', { name: '查看缺 YUTONG_MQTT' }));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('missingProtocol=YUTONG_MQTT'), undefined);
|
||||
});
|
||||
expect(screen.getByText('当前筛选:缺 YUTONG_MQTT')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('opens vehicle list filtered by service summary KPI', async () => {
|
||||
window.history.replaceState(null, '', '/#/dashboard');
|
||||
const fetchMock = vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
|
||||
|
||||
Reference in New Issue
Block a user