feat(platform): export vehicle service dossier
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
import { Banner, Button, Card, Descriptions, Form, Select, Space, Table, Tabs, Tag, Toast, Typography } from '@douyinfe/semi-ui';
|
||||
import { IconCopy, IconRefresh, IconSearch } from '@douyinfe/semi-icons';
|
||||
import { IconCopy, IconDownload, IconRefresh, IconSearch } from '@douyinfe/semi-icons';
|
||||
import { useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { api } from '../api/client';
|
||||
import type { QualityIssueRow, RealtimeLocationRow, VehicleDetail as VehicleDetailData, VehicleSourceStatus } from '../api/types';
|
||||
import { PageHeader } from '../components/PageHeader';
|
||||
import { SourceStatusTags } from '../components/SourceStatusTags';
|
||||
import { StatusTag } from '../components/StatusTag';
|
||||
import { buildCsv, downloadCsv, type CsvColumn } from '../domain/csvExport';
|
||||
import { isLikelyVIN } from '../domain/vehicleLookup';
|
||||
import { summarizeVehicleService } from '../domain/vehicleService';
|
||||
|
||||
@@ -70,6 +71,28 @@ type VehicleServiceAction = {
|
||||
onClick: () => void;
|
||||
};
|
||||
|
||||
type VehicleReportRow = {
|
||||
section: string;
|
||||
item: string;
|
||||
value: string;
|
||||
};
|
||||
|
||||
const vehicleReportColumns: CsvColumn<VehicleReportRow>[] = [
|
||||
{ title: '模块', value: (row) => row.section },
|
||||
{ title: '项目', value: (row) => row.item },
|
||||
{ title: '值', value: (row) => row.value }
|
||||
];
|
||||
|
||||
function reportText(value: unknown) {
|
||||
if (value == null || value === '') return '-';
|
||||
if (Array.isArray(value)) return value.length > 0 ? value.join('|') : '-';
|
||||
return String(value);
|
||||
}
|
||||
|
||||
function vehicleReportFileName(vin: string, protocol?: string) {
|
||||
return `vehicle-service-${vin || 'unknown'}-${protocol || 'all-source'}.csv`;
|
||||
}
|
||||
|
||||
async function copyVehicleServiceURL() {
|
||||
try {
|
||||
await navigator.clipboard.writeText(`${window.location.origin}${window.location.pathname}${window.location.hash}`);
|
||||
@@ -323,6 +346,43 @@ export function VehicleDetail({
|
||||
]}
|
||||
/>
|
||||
);
|
||||
const exportVehicleReport = () => {
|
||||
if (!detail) {
|
||||
Toast.warning('当前没有可导出的车辆档案');
|
||||
return;
|
||||
}
|
||||
const rows: VehicleReportRow[] = [
|
||||
{ section: '身份档案', item: '车辆主键', value: reportText(displayVIN) },
|
||||
{ section: '身份档案', item: '查询关键词', value: reportText(displayLookupKey) },
|
||||
{ section: '身份档案', item: '车牌', value: reportText(archivePlate) },
|
||||
{ section: '身份档案', item: '手机号', value: reportText(archivePhone) },
|
||||
{ section: '身份档案', item: 'OEM', value: reportText(archiveOEM) },
|
||||
{ section: '身份档案', item: '档案完整度', value: archiveCompleteness },
|
||||
{ section: '身份档案', item: '档案缺项', value: reportText(archiveMissingLabels) },
|
||||
{ section: '服务结论', item: '服务判断', value: serviceConclusion.status },
|
||||
{ section: '服务结论', item: '主要风险', value: serviceConclusion.risk },
|
||||
{ section: '服务结论', item: '下一步', value: serviceConclusion.nextStep },
|
||||
{ section: '证据链', item: '来源证据', value: evidenceSourceCount > 0 ? `${evidenceOnlineSourceCount}/${evidenceSourceCount} 来源在线` : '-' },
|
||||
{ section: '证据链', item: '定位证据', value: evidenceLocatedSourceCount > 0 ? `${evidenceLocatedSourceCount} 个来源有位置` : '暂无位置' },
|
||||
{ section: '证据链', item: '里程差异', value: formatCompactNumber(evidenceMileageDelta, ' km') },
|
||||
{ section: '证据链', item: '时间差异', value: formatSeconds(evidenceTimeDeltaSeconds) },
|
||||
{ section: '证据链', item: '一致性结论', value: consistencyTitle },
|
||||
{ section: '证据链', item: '一致性说明', value: consistencyDetail },
|
||||
{ section: '数据规模', item: '历史记录', value: String(overview?.historyCount ?? detail.history.total ?? 0) },
|
||||
{ section: '数据规模', item: 'RAW记录', value: String(overview?.rawCount ?? detail.raw.total ?? 0) },
|
||||
{ section: '数据规模', item: '里程记录', value: String(overview?.mileageCount ?? detail.mileage.total ?? 0) },
|
||||
{ section: '数据规模', item: '质量问题', value: String(qualityCount) }
|
||||
];
|
||||
for (const source of detail.sourceStatus ?? []) {
|
||||
rows.push(
|
||||
{ section: `来源 ${source.protocol}`, item: '在线', value: source.online ? '在线' : '离线' },
|
||||
{ section: `来源 ${source.protocol}`, item: '最后时间', value: reportText(source.lastSeen) },
|
||||
{ section: `来源 ${source.protocol}`, item: '能力', value: sourceCapabilities.filter((item) => source[item.key]).map((item) => item.label).join('|') || '-' }
|
||||
);
|
||||
}
|
||||
downloadCsv(vehicleReportFileName(displayVIN, activeProtocol), buildCsv(vehicleReportColumns, rows));
|
||||
Toast.success('已导出车辆服务档案');
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="vp-page">
|
||||
@@ -344,6 +404,7 @@ export function VehicleDetail({
|
||||
<Button icon={<IconSearch />} htmlType="submit" theme="solid" type="primary">查询车辆</Button>
|
||||
<Button icon={<IconRefresh />} onClick={() => load(query)} loading={loading}>刷新</Button>
|
||||
<Button icon={<IconCopy />} onClick={copyVehicleServiceURL}>复制服务链接</Button>
|
||||
<Button disabled={!detail} icon={<IconDownload />} onClick={exportVehicleReport}>导出档案 CSV</Button>
|
||||
<Button disabled={!hasResolvedVIN} onClick={() => onOpenRealtime(resolvedVIN, activeProtocol)}>查看实时</Button>
|
||||
<Button disabled={!hasResolvedVIN} onClick={() => onOpenHistory(resolvedVIN, activeProtocol)}>查看历史</Button>
|
||||
<Button disabled={!hasResolvedVIN} onClick={() => onOpenRaw(resolvedVIN, activeProtocol)}>查看 RAW</Button>
|
||||
|
||||
Reference in New Issue
Block a user