feat(platform): add history evidence package
This commit is contained in:
@@ -6,6 +6,7 @@ import type { HistoryLocationRow, Page, RawFrameRow } from '../api/types';
|
||||
import { VehicleMap, type VehicleMapPoint } from '../components/VehicleMap';
|
||||
import { PageHeader } from '../components/PageHeader';
|
||||
import { isAMapConfigured } from '../config/appConfig';
|
||||
import { buildAppHash } from '../domain/appRoute';
|
||||
import { buildCsv, downloadCsv, type CsvColumn } from '../domain/csvExport';
|
||||
|
||||
type HistoryFilters = {
|
||||
@@ -281,6 +282,59 @@ function trajectorySummaryText({
|
||||
].join('\n');
|
||||
}
|
||||
|
||||
function appURL(hash: string) {
|
||||
return `${window.location.origin}${window.location.pathname}${hash}`;
|
||||
}
|
||||
|
||||
function historyEvidencePackageText({
|
||||
filters,
|
||||
locationCount,
|
||||
rawCount,
|
||||
fieldCount,
|
||||
validPointCount,
|
||||
mileageDelta,
|
||||
maxSpeed,
|
||||
firstLocation,
|
||||
lastLocation,
|
||||
anomalySummary
|
||||
}: {
|
||||
filters: HistoryFilters;
|
||||
locationCount: number;
|
||||
rawCount: number;
|
||||
fieldCount: number;
|
||||
validPointCount: number;
|
||||
mileageDelta?: number;
|
||||
maxSpeed?: number;
|
||||
firstLocation?: HistoryLocationRow;
|
||||
lastLocation?: HistoryLocationRow;
|
||||
anomalySummary: TrajectoryAnomalySummary;
|
||||
}) {
|
||||
const vehicle = filters.keyword?.trim() || '';
|
||||
const protocol = filters.protocol?.trim() || '';
|
||||
const evidenceFilters = {
|
||||
...(filters.dateFrom?.trim() ? { dateFrom: filters.dateFrom.trim() } : {}),
|
||||
...(filters.dateTo?.trim() ? { dateTo: filters.dateTo.trim() } : {})
|
||||
};
|
||||
return [
|
||||
'【历史证据包】',
|
||||
`车辆:${vehicle || '全部车辆'}`,
|
||||
`数据来源:${protocol || '全部来源'}`,
|
||||
`查询范围:${filters.dateFrom?.trim() || '-'} 至 ${filters.dateTo?.trim() || '-'}`,
|
||||
`位置记录:${locationCount.toLocaleString()},有效定位:${validPointCount.toLocaleString()}`,
|
||||
`RAW帧:${rawCount.toLocaleString()},解析字段:${fieldCount.toLocaleString()}`,
|
||||
`区间里程:${formatNumber(mileageDelta, ' km')},最高速度:${formatNumber(maxSpeed, ' km/h')}`,
|
||||
`起点:${firstLocation?.deviceTime || firstLocation?.serverTime || '-'}`,
|
||||
`终点:${lastLocation?.deviceTime || lastLocation?.serverTime || '-'}`,
|
||||
`异常:断点 ${anomalySummary.gapCount.toLocaleString()} / 里程回退 ${anomalySummary.mileageRollbackCount.toLocaleString()} / 超速 ${anomalySummary.overspeedCount.toLocaleString()}`,
|
||||
`轨迹回放:${appURL(buildAppHash({ page: 'history', keyword: vehicle, protocol, filters: evidenceFilters }))}`,
|
||||
`历史位置:${appURL(buildAppHash({ page: 'history-query', keyword: vehicle, protocol, filters: { ...evidenceFilters, tab: 'location' } }))}`,
|
||||
`RAW证据:${appURL(buildAppHash({ page: 'history-query', keyword: vehicle, protocol, filters: { ...evidenceFilters, tab: 'raw', includeFields: 'true' } }))}`,
|
||||
`解析字段:${appURL(buildAppHash({ page: 'history-query', keyword: vehicle, protocol, filters: { ...evidenceFilters, tab: 'fields', includeFields: 'true', ...(filters.fields?.trim() ? { fields: filters.fields.trim() } : {}) } }))}`,
|
||||
`里程复核:${appURL(buildAppHash({ page: 'mileage', keyword: vehicle, protocol, filters: evidenceFilters }))}`,
|
||||
`车辆服务:${appURL(buildAppHash({ page: 'detail', keyword: vehicle, protocol }))}`
|
||||
].join('\n');
|
||||
}
|
||||
|
||||
function amapLocationName(row: HistoryLocationRow, fallback: string) {
|
||||
return encodeURIComponent(row.plate || row.vin || fallback);
|
||||
}
|
||||
@@ -454,7 +508,8 @@ export function History({
|
||||
};
|
||||
|
||||
const rawFieldCount = useMemo(() => Object.keys(selectedRaw?.parsedFields ?? {}).length, [selectedRaw]);
|
||||
const rawFieldRows = useMemo<RawFieldRow[]>(() => rawFrames.items.flatMap((row) => {
|
||||
const rawItems = rawFrames.items ?? [];
|
||||
const rawFieldRows = useMemo<RawFieldRow[]>(() => rawItems.flatMap((row) => {
|
||||
const fields = flattenParsedFields(row.parsedFields ?? {});
|
||||
return fields.map((field, index) => ({
|
||||
id: `${row.id}-${field.path}-${index}`,
|
||||
@@ -468,8 +523,8 @@ export function History({
|
||||
fieldPath: field.path,
|
||||
fieldValue: field.value
|
||||
}));
|
||||
}), [rawFrames.items]);
|
||||
const locationItems = locations.items;
|
||||
}), [rawItems]);
|
||||
const locationItems = locations.items ?? [];
|
||||
const validLocations = locationItems.filter(hasValidCoordinate);
|
||||
const mileageValues = locationItems.map((item) => item.totalMileageKm).filter(isFiniteNumber);
|
||||
const mileageDelta = mileageValues.length > 1 ? Math.max(...mileageValues) - Math.min(...mileageValues) : undefined;
|
||||
@@ -556,6 +611,23 @@ export function History({
|
||||
'轨迹摘要'
|
||||
);
|
||||
};
|
||||
const copyHistoryEvidencePackage = () => {
|
||||
copyText(
|
||||
historyEvidencePackageText({
|
||||
filters,
|
||||
locationCount: locations.total ?? 0,
|
||||
rawCount: rawFrames.total ?? 0,
|
||||
fieldCount: rawFieldRows.length,
|
||||
validPointCount: validLocations.length,
|
||||
mileageDelta,
|
||||
maxSpeed,
|
||||
firstLocation,
|
||||
lastLocation,
|
||||
anomalySummary: trajectoryAnomalies
|
||||
}),
|
||||
'历史证据包'
|
||||
);
|
||||
};
|
||||
const openAmapTrajectory = () => {
|
||||
const url = amapTrajectoryURL(validLocations);
|
||||
if (!url) {
|
||||
@@ -643,9 +715,12 @@ export function History({
|
||||
title={pageTitle}
|
||||
description={pageDescription}
|
||||
actions={(
|
||||
<Button disabled={!currentVehicleKeyword} onClick={() => onOpenVehicle(currentVehicleKeyword, currentProtocol)}>
|
||||
当前车辆服务
|
||||
</Button>
|
||||
<Space>
|
||||
<Button icon={<IconCopy />} onClick={copyHistoryEvidencePackage}>复制历史证据包</Button>
|
||||
<Button disabled={!currentVehicleKeyword} onClick={() => onOpenVehicle(currentVehicleKeyword, currentProtocol)}>
|
||||
当前车辆服务
|
||||
</Button>
|
||||
</Space>
|
||||
)}
|
||||
/>
|
||||
<div className="vp-scope-bar">
|
||||
@@ -695,6 +770,7 @@ export function History({
|
||||
<Space>
|
||||
<span>轨迹回放作业台</span>
|
||||
<Button size="small" theme="light" icon={<IconCopy />} onClick={copyTrajectorySummary}>复制轨迹摘要</Button>
|
||||
<Button size="small" theme="light" icon={<IconCopy />} onClick={copyHistoryEvidencePackage}>复制历史证据包</Button>
|
||||
<Button size="small" theme="light" disabled={validLocations.length === 0} onClick={openAmapTrajectory}>高德线路</Button>
|
||||
</Space>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user