feat(platform): summarize vehicle action queue

This commit is contained in:
lingniu
2026-07-04 09:15:02 +08:00
parent c4ff0079cf
commit 5952bb1a6f
2 changed files with 91 additions and 1 deletions

View File

@@ -155,6 +155,27 @@ export function Vehicles({
}
return items;
}, [pagination.total, summary]);
const actionQueue = useMemo<Array<{ label: string; count: number; filters: Record<string, string>; color: 'orange' | 'red' }>>(() => {
const items: Array<{ label: string; count: number; filters: Record<string, string>; color: 'orange' | 'red' }> = [];
const unboundCount = summary?.unboundVehicles ?? 0;
if (unboundCount > 0) {
items.push({ label: '维护身份绑定', count: unboundCount, filters: { bindingStatus: 'unbound' }, color: 'orange' });
}
const noDataCount = summary?.noDataVehicles ?? 0;
if (noDataCount > 0) {
items.push({ label: '确认平台转发', count: noDataCount, filters: { serviceStatus: 'no_data' }, color: 'orange' });
}
for (const source of summary?.missingSources ?? []) {
if (source.count <= 0) continue;
items.push({
label: `补齐 ${source.protocol} 来源`,
count: source.count,
filters: { missingProtocol: source.protocol },
color: 'orange'
});
}
return items;
}, [summary]);
const filterSummary = [
filters.keyword ? `关键词:${filters.keyword}` : '',
filters.protocol ? `数据来源:${filters.protocol}` : '',
@@ -344,6 +365,17 @@ export function Vehicles({
))}
</div>
</Card>
{actionQueue.length > 0 ? (
<Card bordered title="处置队列" style={{ marginTop: 16 }}>
<Space wrap>
{actionQueue.map((item) => (
<Button key={`${item.label}-${item.count}`} size="small" theme="light" type={item.color === 'red' ? 'danger' : 'warning'} onClick={() => applyFilters({ ...filters, ...item.filters })}>
{item.label} {item.count.toLocaleString()}
</Button>
))}
</Space>
</Card>
) : null}
<Card bordered style={{ marginTop: 16 }}>
{rows.length === 0 && !loading ? (
<DataEmpty />

View File

@@ -510,7 +510,9 @@ test('shows vehicle service result summary on vehicle list filters', async () =>
onlineVehicles: 73,
singleSourceVehicles: 0,
multiSourceVehicles: 181,
unboundVehicles: 9
noDataVehicles: 4,
unboundVehicles: 9,
missingSources: [{ protocol: 'YUTONG_MQTT', count: 181 }]
},
traceId: 'trace-test',
timestamp: 1783094400000
@@ -577,6 +579,10 @@ test('shows vehicle service result summary on vehicle list filters', async () =>
expect(screen.getByText('单源车辆')).toBeInTheDocument();
expect(screen.getByText('暂无来源车辆')).toBeInTheDocument();
expect(screen.getByText('待绑定')).toBeInTheDocument();
expect(screen.getByText('处置队列')).toBeInTheDocument();
expect(screen.getByRole('button', { name: '维护身份绑定 9' })).toBeInTheDocument();
expect(screen.getByRole('button', { name: '确认平台转发 4' })).toBeInTheDocument();
expect(screen.getByRole('button', { name: '补齐 YUTONG_MQTT 来源 181' })).toBeInTheDocument();
expect(screen.getByText('VIN-MULTI-001')).toBeInTheDocument();
expect(screen.getAllByText('来源证据').length).toBeGreaterThanOrEqual(1);
expect(screen.getByText('GB32960 在线')).toBeInTheDocument();
@@ -668,6 +674,58 @@ test('filters vehicle list from recommended action', async () => {
expect(window.location.hash).toBe('#/vehicles?missingProtocol=YUTONG_MQTT');
});
test('filters vehicle list from action queue', async () => {
window.history.replaceState(null, '', '/#/vehicles');
const fetchMock = vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/ops/health')) {
return {
ok: true,
json: async () => ({
data: { linkHealth: [], kafkaLag: 0, activeConnections: 0, capacityFindings: [], redisOnlineKeys: 0, tdengineWritable: true, mysqlWritable: true, runtime: { requestTimeoutMs: 5000 } },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/vehicles/coverage/summary')) {
return {
ok: true,
json: async () => ({
data: {
totalVehicles: 181,
onlineVehicles: 73,
singleSourceVehicles: 0,
multiSourceVehicles: 181,
noDataVehicles: 4,
unboundVehicles: 9,
missingSources: [{ protocol: 'YUTONG_MQTT', count: 181 }]
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 20, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
fireEvent.click(await screen.findByRole('button', { name: '确认平台转发 4' }));
await waitFor(() => {
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('/api/vehicles/coverage?limit=20&offset=0&serviceStatus=no_data'), undefined);
});
expect(window.location.hash).toBe('#/vehicles?serviceStatus=no_data');
});
test('shows and clears current vehicle service filters', async () => {
window.history.replaceState(null, '', '/#/vehicles?keyword=%E7%B2%A4A&protocol=JT808&coverage=multi&missingProtocol=YUTONG_MQTT&serviceStatus=degraded&online=online&bindingStatus=bound');
const fetchMock = vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {