From d7f1a9279fe266c38f2547f67a78e9b96b5de485 Mon Sep 17 00:00:00 2001 From: lingniu Date: Sat, 4 Jul 2026 16:44:55 +0800 Subject: [PATCH] feat(platform): add vehicle-first statistics overview --- .../apps/web/src/pages/Mileage.tsx | 45 +++++++++++++++ .../apps/web/src/test/App.test.tsx | 57 ++++++++++++++++++- vehicle-data-platform/docs/product-spec.md | 3 +- .../docs/vehicle-platform-blueprint.md | 1 + 4 files changed, 104 insertions(+), 2 deletions(-) diff --git a/vehicle-data-platform/apps/web/src/pages/Mileage.tsx b/vehicle-data-platform/apps/web/src/pages/Mileage.tsx index 518d9b32..13d246fe 100644 --- a/vehicle-data-platform/apps/web/src/pages/Mileage.tsx +++ b/vehicle-data-platform/apps/web/src/pages/Mileage.tsx @@ -210,6 +210,8 @@ export function Mileage({ const closurePassed = closureDeltaKm != null && Math.abs(closureDeltaKm) < 0.01; const confidenceStatus = anomalyRows.length > 0 || pageCoverageRate < 100 ? '需复核' : '可用于 BI'; const confidenceColor = confidenceStatus === '可用于 BI' ? 'green' as const : 'orange' as const; + const currentEvidenceText = `${summary.vehicleCount.toLocaleString()} 车 / ${summary.sourceCount.toLocaleString()} 来源 / ${rows.length.toLocaleString()} 条明细`; + const sourceConsistencyText = summary.sourceCount > 1 ? '可做跨来源核对' : summary.sourceCount === 1 ? '单来源车辆需关注' : '等待来源证据'; const maxDateMileage = Math.max(...dateSeries.map((item) => item.value), 0); const maxSourceMileage = Math.max(...sourceSeries.map((item) => item.value), 0); const filterSummary = [ @@ -318,6 +320,49 @@ export function Mileage({ 当前来源:{currentProtocol || '全部来源'} 里程统计按当前车辆与来源范围汇总。 + +
+ + 当前统计证据 + {currentEvidenceText} + 三类数据源最终汇总为一个车辆服务统计视图 + +
+
+ {[ + { + title: '里程统计', + value: `${formatKm(summary.totalMileageKm)} km`, + color: 'blue' as const, + detail: '每日里程、区间里程、异常差值和可审计证据。' + }, + { + title: '在线率与离线时长', + value: currentVehicleKeyword ? '车辆维度' : '车队维度', + color: 'green' as const, + detail: '后续接入在线区间聚合,按 VIN 统计在线率、离线时间和无更新时长。' + }, + { + title: '数据完整性', + value: confidenceStatus, + color: confidenceColor, + detail: '围绕位置、里程、SOC、速度和来源新鲜度判断统计可信度。' + }, + { + title: '来源一致性', + value: sourceConsistencyText, + color: summary.sourceCount > 1 ? 'green' as const : 'orange' as const, + detail: 'GB32960、JT808、Yutong MQTT 只作为同一车辆服务的来源证据。' + } + ].map((item) => ( +
+ {item.title} +
{item.value}
+ {item.detail} +
+ ))} +
+
{ const nextFilters = values as Record; diff --git a/vehicle-data-platform/apps/web/src/test/App.test.tsx b/vehicle-data-platform/apps/web/src/test/App.test.tsx index e7f5dc0d..6652f536 100644 --- a/vehicle-data-platform/apps/web/src/test/App.test.tsx +++ b/vehicle-data-platform/apps/web/src/test/App.test.tsx @@ -6490,7 +6490,7 @@ test('shows mileage statistics workspace with trend source and definition', asyn expect(screen.getAllByText('JT808').length).toBeGreaterThanOrEqual(1); expect(screen.getAllByText('GB32960').length).toBeGreaterThanOrEqual(1); expect(screen.getByText('当前页里程')).toBeInTheDocument(); - expect(screen.getByText('140 km')).toBeInTheDocument(); + expect(screen.getAllByText('140 km').length).toBeGreaterThanOrEqual(1); expect(screen.getByText('异常记录')).toBeInTheDocument(); expect(screen.getAllByText('1').length).toBeGreaterThanOrEqual(1); expect(screen.getByText('最大单日')).toBeInTheDocument(); @@ -6508,6 +6508,61 @@ test('shows mileage statistics workspace with trend source and definition', asyn expect(screen.getByText((content) => content.includes('区间总值应等于各日里程之和'))).toBeInTheDocument(); }); +test('shows vehicle-first statistics domains for one vehicle service', async () => { + window.history.replaceState(null, '', '/#/mileage?keyword=VIN-STATS-SERVICE&protocol=JT808'); + vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => { + const path = String(input); + if (path.includes('/api/mileage/summary')) { + return { + ok: true, + json: async () => ({ + data: { vehicleCount: 3, recordCount: 6, sourceCount: 2, totalMileageKm: 210, averageMileagePerVin: 70 }, + traceId: 'trace-test', + timestamp: 1783094400000 + }) + } as Response; + } + if (path.includes('/api/mileage/daily')) { + return { + ok: true, + json: async () => ({ + data: { + items: [ + { vin: 'VIN-STATS-SERVICE', plate: '粤A统计服务1', source: 'JT808', date: '2026-07-01', startMileageKm: 100, endMileageKm: 150, dailyMileageKm: 50, anomalySeverity: '' }, + { vin: 'VIN-STATS-SERVICE', plate: '粤A统计服务1', source: 'GB32960', date: '2026-07-01', startMileageKm: 200, endMileageKm: 240, dailyMileageKm: 40, anomalySeverity: '' }, + { vin: 'VIN-STATS-SERVICE-2', plate: '粤A统计服务2', source: 'JT808', date: '2026-07-02', startMileageKm: 300, endMileageKm: 380, dailyMileageKm: 80, anomalySeverity: 'warning' } + ], + total: 3, + 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(); + + expect(await screen.findByText('车辆统计服务总览')).toBeInTheDocument(); + expect(screen.getAllByText('里程统计').length).toBeGreaterThanOrEqual(1); + expect(screen.getByText('在线率与离线时长')).toBeInTheDocument(); + expect(screen.getByText('数据完整性')).toBeInTheDocument(); + expect(screen.getByText('来源一致性')).toBeInTheDocument(); + expect(screen.getByText('三类数据源最终汇总为一个车辆服务统计视图')).toBeInTheDocument(); + expect(screen.getByText('当前统计证据')).toBeInTheDocument(); + expect(screen.getByText('3 车 / 2 来源 / 3 条明细')).toBeInTheDocument(); +}); + test('copies mileage statistics summary for operations reporting', async () => { window.history.replaceState(null, '', '/#/mileage?keyword=VIN-MILEAGE-COPY&protocol=JT808&dateFrom=2026-07-01&dateTo=2026-07-03'); const writeText = vi.fn(() => Promise.resolve()); diff --git a/vehicle-data-platform/docs/product-spec.md b/vehicle-data-platform/docs/product-spec.md index df13d1d4..cc019c89 100644 --- a/vehicle-data-platform/docs/product-spec.md +++ b/vehicle-data-platform/docs/product-spec.md @@ -22,7 +22,7 @@ The platform navigation should use vehicle-service language rather than protocol 6. History Query: historical locations, raw frames, and flattened parsed fields with pagination and field trimming. 7. Alert Events: alert trigger records, affected vehicles, rule evidence, manual state, notification state, and escalation readiness. 8. Notification Rules: alert trigger rules, notification targets, channels, escalation windows, acceptance criteria, and copyable runbooks. -9. Statistics: daily/range mileage, online rate, offline duration, data completeness, and source consistency. +9. Statistics: one vehicle-service statistics workspace covering daily/range mileage, online rate, offline duration, data completeness, and source consistency. 10. Ops Quality: GB32960, JT808, Yutong MQTT, Kafka, NATS, Redis, TDengine, MySQL, AMap, gateway, and runtime health. See `docs/vehicle-platform-blueprint.md` for the detailed page-level blueprint and phased implementation plan. @@ -94,6 +94,7 @@ Statistics must stay vehicle-first and evidence-backed: - Online rate should be computed by vehicle and then broken down by source. - Data completeness should report missing location, mileage, SOC, speed, and source freshness. - Source consistency should compare GB32960, JT808, and Yutong MQTT only when the same VIN has multiple sources. +- The statistics page should show these four domains together, because all protocol data ultimately supports one vehicle service view. ## Interaction Rules diff --git a/vehicle-data-platform/docs/vehicle-platform-blueprint.md b/vehicle-data-platform/docs/vehicle-platform-blueprint.md index 50fb1595..e895aa22 100644 --- a/vehicle-data-platform/docs/vehicle-platform-blueprint.md +++ b/vehicle-data-platform/docs/vehicle-platform-blueprint.md @@ -192,6 +192,7 @@ Primary modules: - Online: online rate, offline duration, no update duration, source online distribution. - Completeness: location, mileage, SOC, speed, source freshness. - Consistency: cross-source time delta and mileage delta for multi-source vehicles. +- Statistics overview: show the four domains together so operations users understand that GB32960, JT808, and Yutong MQTT are evidence feeding one vehicle service. Rule: