feat(platform): expose source consistency in vehicle coverage

This commit is contained in:
lingniu
2026-07-04 07:12:54 +08:00
parent df78bb5e20
commit c9a809d13d
9 changed files with 134 additions and 14 deletions

View File

@@ -59,6 +59,7 @@ export interface VehicleCoverageRow {
lastSeen: string;
bindingStatus: string;
serviceStatus?: VehicleServiceStatus;
sourceConsistency?: VehicleSourceConsistency;
}
export interface VehicleCoverageSummary {

View File

@@ -33,6 +33,15 @@ function sourceEvidenceText(row: VehicleCoverageRow) {
return `${row.onlineSourceCount}/${row.sourceCount} 来源在线`;
}
function sourceConsistencyTag(row: VehicleCoverageRow) {
const consistency = row.sourceConsistency;
if (!consistency) {
return <Tag color="grey"></Tag>;
}
const color = consistency.severity === 'ok' ? 'green' as const : consistency.severity === 'error' ? 'red' as const : 'orange' as const;
return <Tag color={color}>{consistency.title || consistency.status}</Tag>;
}
async function copyVehicleShareURL() {
try {
await navigator.clipboard.writeText(`${window.location.origin}${window.location.pathname}${window.location.hash}`);
@@ -154,6 +163,11 @@ export function Vehicles({
</Space>
)
},
{
title: '来源一致性',
width: 140,
render: (_: unknown, row: VehicleCoverageRow) => sourceConsistencyTag(row)
},
{ title: '证据覆盖', width: 120, render: (_: unknown, row: VehicleCoverageRow) => sourceEvidenceText(row) },
{ title: '在线', width: 90, render: (_: unknown, row: VehicleCoverageRow) => <StatusTag status={row.online ? 'ok' : 'offline'} /> },
{ title: '最后在线', dataIndex: 'lastSeen', width: 170 },

View File

@@ -2760,6 +2760,87 @@ test('shows vehicle service status in vehicle list', async () => {
expect(screen.getByText('部分来源离线')).toBeInTheDocument();
});
test('shows source consistency diagnosis in vehicle service list', async () => {
window.history.replaceState(null, '', '/#/vehicles');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/vehicles/coverage/summary')) {
return {
ok: true,
json: async () => ({
data: {
totalVehicles: 1,
onlineVehicles: 1,
singleSourceVehicles: 0,
multiSourceVehicles: 1,
noDataVehicles: 0,
unboundVehicles: 0,
missingSources: []
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/vehicles/coverage')) {
return {
ok: true,
json: async () => ({
data: {
items: [{
vin: 'VIN-CONSISTENCY-LIST',
plate: '粤A一致',
phone: '13307795425',
oem: 'G7s',
protocols: ['GB32960', 'JT808'],
missingProtocols: ['YUTONG_MQTT'],
sourceCount: 2,
onlineSourceCount: 2,
online: true,
lastSeen: '2026-07-03 20:12:10',
bindingStatus: 'bound',
sourceConsistency: {
sourceCount: 2,
onlineSourceCount: 2,
locatedSourceCount: 0,
missingProtocols: ['YUTONG_MQTT'],
mileageDeltaKm: 0,
sourceTimeDeltaSeconds: 0,
scope: 'coverage',
status: 'degraded',
severity: 'warning',
title: '来源不完整',
detail: '2/2 个来源在线,车辆服务可用但缺少 YUTONG_MQTT 来源。'
}
}],
total: 1,
limit: 20,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: path.includes('/api/ops/health')
? { linkHealth: [], kafkaLag: 0, redisOnlineKeys: 0, tdengineWritable: true, mysqlWritable: true, runtime: { requestTimeoutMs: 5000 } }
: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('VIN-CONSISTENCY-LIST')).toBeInTheDocument();
expect(screen.getByText('来源一致性')).toBeInTheDocument();
expect(screen.getByText('来源不完整')).toBeInTheDocument();
});
test('opens vehicle service from source-filtered vehicle list with source evidence', async () => {
window.history.replaceState(null, '', '/#/vehicles?protocol=JT808');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {