feat(platform): link mileage rows to raw evidence
This commit is contained in:
@@ -319,6 +319,22 @@ export default function App() {
|
|||||||
replaceHash('history', nextVin, nextProtocol, { tab: 'raw' });
|
replaceHash('history', nextVin, nextProtocol, { tab: 'raw' });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const openRawWithFilters = (filters: Record<string, string> = {}) => {
|
||||||
|
const nextFilters = normalizeHistoryFilterValues(filters);
|
||||||
|
const nextVin = nextFilters.keyword?.trim() || analysisVin;
|
||||||
|
const nextProtocol = nextFilters.protocol?.trim() ?? activeProtocol;
|
||||||
|
if (!nextVin) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setAnalysisVin(nextVin);
|
||||||
|
setActiveProtocol(nextProtocol);
|
||||||
|
setHistoryTab('raw');
|
||||||
|
setHistoryFilters({ ...nextFilters, keyword: nextVin, protocol: nextProtocol });
|
||||||
|
setActivePage('history');
|
||||||
|
const { keyword, protocol, ...restFilters } = nextFilters;
|
||||||
|
replaceHash('history', keyword ?? nextVin, protocol ?? nextProtocol, { ...restFilters, tab: 'raw' });
|
||||||
|
};
|
||||||
|
|
||||||
const openRealtimeForVehicle = (vin: string, protocol?: string) => {
|
const openRealtimeForVehicle = (vin: string, protocol?: string) => {
|
||||||
const nextVin = vin.trim();
|
const nextVin = vin.trim();
|
||||||
const nextProtocol = protocol?.trim() ?? activeProtocol;
|
const nextProtocol = protocol?.trim() ?? activeProtocol;
|
||||||
@@ -378,7 +394,7 @@ export default function App() {
|
|||||||
realtime: <Realtime onOpenVehicle={openVehicle} onOpenHistory={openHistoryForVehicle} onOpenQuality={openQuality} onFiltersChange={updateRealtimeFilters} initialFilters={realtimeFilters} />,
|
realtime: <Realtime onOpenVehicle={openVehicle} onOpenHistory={openHistoryForVehicle} onOpenQuality={openQuality} onFiltersChange={updateRealtimeFilters} initialFilters={realtimeFilters} />,
|
||||||
detail: <VehicleDetail vin={activeVin} protocol={activeProtocol} onOpenRealtime={openRealtimeForVehicle} onOpenHistory={openHistoryForVehicle} onOpenRaw={openRawForVehicle} onOpenMileage={openMileageForVehicle} onOpenVehicles={openVehicles} onOpenQuality={openQuality} onQueryChange={updateVehicleDetailQuery} />,
|
detail: <VehicleDetail vin={activeVin} protocol={activeProtocol} onOpenRealtime={openRealtimeForVehicle} onOpenHistory={openHistoryForVehicle} onOpenRaw={openRawForVehicle} onOpenMileage={openMileageForVehicle} onOpenVehicles={openVehicles} onOpenQuality={openQuality} onQueryChange={updateVehicleDetailQuery} />,
|
||||||
history: <History initialVin={analysisVin} initialProtocol={activeProtocol} initialTab={historyTab} initialFilters={historyFilters} onFiltersChange={updateHistoryFilters} onOpenVehicle={openVehicle} onOpenMileage={openMileageWithFilters} />,
|
history: <History initialVin={analysisVin} initialProtocol={activeProtocol} initialTab={historyTab} initialFilters={historyFilters} onFiltersChange={updateHistoryFilters} onOpenVehicle={openVehicle} onOpenMileage={openMileageWithFilters} />,
|
||||||
mileage: <Mileage initialVin={analysisVin} initialProtocol={activeProtocol} initialFilters={mileageFilters} onFiltersChange={updateMileageFilters} onOpenVehicle={openVehicle} onOpenHistory={openHistoryWithFilters} />,
|
mileage: <Mileage initialVin={analysisVin} initialProtocol={activeProtocol} initialFilters={mileageFilters} onFiltersChange={updateMileageFilters} onOpenVehicle={openVehicle} onOpenHistory={openHistoryWithFilters} onOpenRaw={openRawWithFilters} />,
|
||||||
quality: <Quality onOpenVehicle={openVehicle} onOpenRealtime={openRealtime} onOpenHistory={openHistoryWithFilters} onOpenMileage={openMileageWithFilters} onHealthLoaded={(health) => setLinkIssueCount(health.linkHealth.filter((item) => item.status !== 'ok').length)} onFiltersChange={updateQualityFilters} initialFilters={qualityFilters} />
|
quality: <Quality onOpenVehicle={openVehicle} onOpenRealtime={openRealtime} onOpenHistory={openHistoryWithFilters} onOpenMileage={openMileageWithFilters} onHealthLoaded={(health) => setLinkIssueCount(health.linkHealth.filter((item) => item.status !== 'ok').length)} onFiltersChange={updateQualityFilters} initialFilters={qualityFilters} />
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -99,7 +99,8 @@ export function Mileage({
|
|||||||
initialFilters = {},
|
initialFilters = {},
|
||||||
onFiltersChange,
|
onFiltersChange,
|
||||||
onOpenVehicle,
|
onOpenVehicle,
|
||||||
onOpenHistory
|
onOpenHistory,
|
||||||
|
onOpenRaw
|
||||||
}: {
|
}: {
|
||||||
initialVin: string;
|
initialVin: string;
|
||||||
initialProtocol?: string;
|
initialProtocol?: string;
|
||||||
@@ -107,6 +108,7 @@ export function Mileage({
|
|||||||
onFiltersChange?: (filters: Record<string, string>) => void;
|
onFiltersChange?: (filters: Record<string, string>) => void;
|
||||||
onOpenVehicle: (vin: string, protocol?: string) => void;
|
onOpenVehicle: (vin: string, protocol?: string) => void;
|
||||||
onOpenHistory?: (filters: Record<string, string>) => void;
|
onOpenHistory?: (filters: Record<string, string>) => void;
|
||||||
|
onOpenRaw?: (filters: Record<string, string>) => void;
|
||||||
}) {
|
}) {
|
||||||
const [rows, setRows] = useState<DailyMileageRow[]>([]);
|
const [rows, setRows] = useState<DailyMileageRow[]>([]);
|
||||||
const [summary, setSummary] = useState<MileageSummary>(emptySummary);
|
const [summary, setSummary] = useState<MileageSummary>(emptySummary);
|
||||||
@@ -170,6 +172,16 @@ export function Mileage({
|
|||||||
...(dateTo ? { dateTo } : {})
|
...(dateTo ? { dateTo } : {})
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
const openMileageRawEvidence = (row: DailyMileageRow) => {
|
||||||
|
const dateFrom = row.date?.trim() ?? '';
|
||||||
|
const dateTo = nextDate(dateFrom);
|
||||||
|
onOpenRaw?.({
|
||||||
|
keyword: row.vin,
|
||||||
|
protocol: row.source,
|
||||||
|
...(dateFrom ? { dateFrom } : {}),
|
||||||
|
...(dateTo ? { dateTo } : {})
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const nextFilters = mergeInitialFilters(initialVin, initialProtocol, initialFilters);
|
const nextFilters = mergeInitialFilters(initialVin, initialProtocol, initialFilters);
|
||||||
@@ -338,10 +350,11 @@ export function Mileage({
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '操作',
|
title: '操作',
|
||||||
width: 190,
|
width: 270,
|
||||||
render: (_: unknown, row: DailyMileageRow) => (
|
render: (_: unknown, row: DailyMileageRow) => (
|
||||||
<Space spacing={4} wrap>
|
<Space spacing={4} wrap>
|
||||||
<Button disabled={!canOpenVehicle(row.vin) || !onOpenHistory} onClick={() => openMileageEvidence(row)}>核对轨迹</Button>
|
<Button disabled={!canOpenVehicle(row.vin) || !onOpenHistory} onClick={() => openMileageEvidence(row)}>核对轨迹</Button>
|
||||||
|
<Button disabled={!canOpenVehicle(row.vin) || !onOpenRaw} onClick={() => openMileageRawEvidence(row)}>核对 RAW</Button>
|
||||||
<Button disabled={!canOpenVehicle(row.vin)} onClick={() => onOpenVehicle(row.vin, row.source)}>车辆服务</Button>
|
<Button disabled={!canOpenVehicle(row.vin)} onClick={() => onOpenVehicle(row.vin, row.source)}>车辆服务</Button>
|
||||||
</Space>
|
</Space>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -4185,6 +4185,91 @@ test('opens same-day trajectory playback from mileage row for evidence review',
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('opens same-day raw frame evidence from mileage row', async () => {
|
||||||
|
window.history.replaceState(null, '', '/#/mileage?keyword=VIN-MILEAGE-RAW&protocol=JT808');
|
||||||
|
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, redisOnlineKeys: 0, tdengineWritable: true, mysqlWritable: true, runtime: { requestTimeoutMs: 5000 } },
|
||||||
|
traceId: 'trace-test',
|
||||||
|
timestamp: 1783094400000
|
||||||
|
})
|
||||||
|
} as Response;
|
||||||
|
}
|
||||||
|
if (path.includes('/api/mileage/summary')) {
|
||||||
|
return {
|
||||||
|
ok: true,
|
||||||
|
json: async () => ({
|
||||||
|
data: { vehicleCount: 1, recordCount: 1, sourceCount: 1, totalMileageKm: 18.8, averageMileagePerVin: 18.8 },
|
||||||
|
traceId: 'trace-test',
|
||||||
|
timestamp: 1783094400000
|
||||||
|
})
|
||||||
|
} as Response;
|
||||||
|
}
|
||||||
|
if (path.includes('/api/mileage/daily')) {
|
||||||
|
return {
|
||||||
|
ok: true,
|
||||||
|
json: async () => ({
|
||||||
|
data: {
|
||||||
|
items: [{
|
||||||
|
vin: 'VIN-MILEAGE-RAW',
|
||||||
|
plate: '粤ARAW核',
|
||||||
|
source: 'JT808',
|
||||||
|
date: '2026-07-03',
|
||||||
|
startMileageKm: 200,
|
||||||
|
endMileageKm: 218.8,
|
||||||
|
dailyMileageKm: 18.8,
|
||||||
|
anomalySeverity: 'warning'
|
||||||
|
}],
|
||||||
|
total: 1,
|
||||||
|
limit: 20,
|
||||||
|
offset: 0
|
||||||
|
},
|
||||||
|
traceId: 'trace-test',
|
||||||
|
timestamp: 1783094400000
|
||||||
|
})
|
||||||
|
} as Response;
|
||||||
|
}
|
||||||
|
if (path.includes('/api/history/locations') || path.includes('/api/history/raw-frames')) {
|
||||||
|
return {
|
||||||
|
ok: true,
|
||||||
|
json: async () => ({
|
||||||
|
data: { items: [], total: 0, limit: 20, offset: 0 },
|
||||||
|
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 />);
|
||||||
|
|
||||||
|
expect(await screen.findByText('VIN-MILEAGE-RAW')).toBeInTheDocument();
|
||||||
|
fireEvent.click(screen.getByRole('button', { name: '核对 RAW' }));
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(window.location.hash.startsWith('#/history?')).toBe(true);
|
||||||
|
});
|
||||||
|
const params = new URLSearchParams(window.location.hash.slice('#/history?'.length));
|
||||||
|
expect(params.get('keyword')).toBe('VIN-MILEAGE-RAW');
|
||||||
|
expect(params.get('protocol')).toBe('JT808');
|
||||||
|
expect(params.get('dateFrom')).toBe('2026-07-03');
|
||||||
|
expect(params.get('dateTo')).toBe('2026-07-04');
|
||||||
|
expect(params.get('tab')).toBe('raw');
|
||||||
|
expect(await screen.findByRole('heading', { name: '轨迹回放' })).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
test('shows mileage anomaly action guidance', async () => {
|
test('shows mileage anomaly action guidance', async () => {
|
||||||
window.history.replaceState(null, '', '/#/mileage?keyword=VIN-MILEAGE-ANOMALY&protocol=GB32960');
|
window.history.replaceState(null, '', '/#/mileage?keyword=VIN-MILEAGE-ANOMALY&protocol=GB32960');
|
||||||
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
|
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user