feat(platform): surface overview consistency
This commit is contained in:
@@ -276,6 +276,9 @@ func TestHandlerVehicleServiceOverviewEndpoint(t *testing.T) {
|
|||||||
if body.Data.ServiceStatus == nil || body.Data.ServiceStatus.Status != "degraded" || body.Data.ServiceStatus.Title != "部分来源离线" {
|
if body.Data.ServiceStatus == nil || body.Data.ServiceStatus.Status != "degraded" || body.Data.ServiceStatus.Title != "部分来源离线" {
|
||||||
t.Fatalf("overview endpoint should expose canonical service status, got %+v", body.Data.ServiceStatus)
|
t.Fatalf("overview endpoint should expose canonical service status, got %+v", body.Data.ServiceStatus)
|
||||||
}
|
}
|
||||||
|
if body.Data.SourceConsistency == nil || body.Data.SourceConsistency.SourceCount != 2 || body.Data.SourceConsistency.OnlineSourceCount != 1 {
|
||||||
|
t.Fatalf("overview endpoint should expose source consistency, got %+v", body.Data.SourceConsistency)
|
||||||
|
}
|
||||||
if strings.Contains(rec.Body.String(), `"raw"`) || strings.Contains(rec.Body.String(), `"history"`) {
|
if strings.Contains(rec.Body.String(), `"raw"`) || strings.Contains(rec.Body.String(), `"history"`) {
|
||||||
t.Fatalf("overview endpoint should not return heavy detail pages: %s", rec.Body.String())
|
t.Fatalf("overview endpoint should not return heavy detail pages: %s", rec.Body.String())
|
||||||
}
|
}
|
||||||
@@ -330,6 +333,9 @@ func TestHandlerVehicleServiceOverviewsEndpoint(t *testing.T) {
|
|||||||
if body.Data.Items[0].ServiceStatus == nil || body.Data.Items[1].ServiceStatus == nil {
|
if body.Data.Items[0].ServiceStatus == nil || body.Data.Items[1].ServiceStatus == nil {
|
||||||
t.Fatalf("batch overview should include canonical status for every vehicle, got %+v", body.Data.Items)
|
t.Fatalf("batch overview should include canonical status for every vehicle, got %+v", body.Data.Items)
|
||||||
}
|
}
|
||||||
|
if body.Data.Items[0].SourceConsistency == nil || body.Data.Items[0].SourceConsistency.SourceCount != 2 {
|
||||||
|
t.Fatalf("batch overview should include source consistency, got %+v", body.Data.Items[0].SourceConsistency)
|
||||||
|
}
|
||||||
if strings.Contains(rec.Body.String(), `"raw"`) || strings.Contains(rec.Body.String(), `"history"`) {
|
if strings.Contains(rec.Body.String(), `"raw"`) || strings.Contains(rec.Body.String(), `"history"`) {
|
||||||
t.Fatalf("batch overview should not return heavy detail pages: %s", rec.Body.String())
|
t.Fatalf("batch overview should not return heavy detail pages: %s", rec.Body.String())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,8 +64,8 @@ type VehicleCoverageRow struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type VehicleCoverageSummary struct {
|
type VehicleCoverageSummary struct {
|
||||||
TotalVehicles int `json:"totalVehicles"`
|
TotalVehicles int `json:"totalVehicles"`
|
||||||
OnlineVehicles int `json:"onlineVehicles"`
|
OnlineVehicles int `json:"onlineVehicles"`
|
||||||
SingleSourceVehicles int `json:"singleSourceVehicles"`
|
SingleSourceVehicles int `json:"singleSourceVehicles"`
|
||||||
MultiSourceVehicles int `json:"multiSourceVehicles"`
|
MultiSourceVehicles int `json:"multiSourceVehicles"`
|
||||||
UnboundVehicles int `json:"unboundVehicles"`
|
UnboundVehicles int `json:"unboundVehicles"`
|
||||||
@@ -113,22 +113,23 @@ type VehicleSourceConsistency struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type VehicleServiceOverview struct {
|
type VehicleServiceOverview struct {
|
||||||
VIN string `json:"vin"`
|
VIN string `json:"vin"`
|
||||||
Plate string `json:"plate"`
|
Plate string `json:"plate"`
|
||||||
Phone string `json:"phone"`
|
Phone string `json:"phone"`
|
||||||
OEM string `json:"oem"`
|
OEM string `json:"oem"`
|
||||||
Protocols []string `json:"protocols"`
|
Protocols []string `json:"protocols"`
|
||||||
PrimaryProtocol string `json:"primaryProtocol"`
|
PrimaryProtocol string `json:"primaryProtocol"`
|
||||||
CoverageStatus string `json:"coverageStatus"`
|
CoverageStatus string `json:"coverageStatus"`
|
||||||
SourceCount int `json:"sourceCount"`
|
SourceCount int `json:"sourceCount"`
|
||||||
OnlineSourceCount int `json:"onlineSourceCount"`
|
OnlineSourceCount int `json:"onlineSourceCount"`
|
||||||
LastSeen string `json:"lastSeen"`
|
LastSeen string `json:"lastSeen"`
|
||||||
RealtimeCount int `json:"realtimeCount"`
|
RealtimeCount int `json:"realtimeCount"`
|
||||||
HistoryCount int `json:"historyCount"`
|
HistoryCount int `json:"historyCount"`
|
||||||
RawCount int `json:"rawCount"`
|
RawCount int `json:"rawCount"`
|
||||||
MileageCount int `json:"mileageCount"`
|
MileageCount int `json:"mileageCount"`
|
||||||
QualityIssueCount int `json:"qualityIssueCount"`
|
QualityIssueCount int `json:"qualityIssueCount"`
|
||||||
ServiceStatus *VehicleServiceStatus `json:"serviceStatus,omitempty"`
|
ServiceStatus *VehicleServiceStatus `json:"serviceStatus,omitempty"`
|
||||||
|
SourceConsistency *VehicleSourceConsistency `json:"sourceConsistency,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type VehicleServiceSummary struct {
|
type VehicleServiceSummary struct {
|
||||||
|
|||||||
@@ -332,8 +332,7 @@ func (s *ProductionStore) VehicleServiceOverviews(ctx context.Context, query Veh
|
|||||||
overview.PrimaryProtocol = overview.Protocols[0]
|
overview.PrimaryProtocol = overview.Protocols[0]
|
||||||
}
|
}
|
||||||
overview.RealtimeCount = overview.SourceCount
|
overview.RealtimeCount = overview.SourceCount
|
||||||
overview.CoverageStatus = coverageStatus(overview.SourceCount, overview.OnlineSourceCount)
|
applyVehicleServiceOverviewDerivedFields(&overview, strings.TrimSpace(overview.VIN) != "")
|
||||||
overview.ServiceStatus = buildVehicleServiceStatus(strings.TrimSpace(overview.VIN) != "", statusesForOverview(&overview))
|
|
||||||
overviews = append(overviews, overview)
|
overviews = append(overviews, overview)
|
||||||
current := &overviews[len(overviews)-1]
|
current := &overviews[len(overviews)-1]
|
||||||
for _, key := range []string{overview.VIN, overview.Plate, overview.Phone} {
|
for _, key := range []string{overview.VIN, overview.Plate, overview.Phone} {
|
||||||
|
|||||||
@@ -40,3 +40,24 @@ func TestVehicleServiceOverviewMatchesPartialKeyword(t *testing.T) {
|
|||||||
t.Fatalf("overview %+v should not match unrelated keyword", overview)
|
t.Fatalf("overview %+v should not match unrelated keyword", overview)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestVehicleServiceOverviewDerivedFieldsIncludeSourceConsistency(t *testing.T) {
|
||||||
|
overview := &VehicleServiceOverview{
|
||||||
|
VIN: "LB9A32A24R0LS1426",
|
||||||
|
Protocols: []string{"GB32960", "JT808"},
|
||||||
|
SourceCount: 2,
|
||||||
|
OnlineSourceCount: 1,
|
||||||
|
}
|
||||||
|
|
||||||
|
applyVehicleServiceOverviewDerivedFields(overview, true)
|
||||||
|
|
||||||
|
if overview.SourceConsistency == nil {
|
||||||
|
t.Fatalf("overview should include source consistency")
|
||||||
|
}
|
||||||
|
if overview.SourceConsistency.SourceCount != 2 || overview.SourceConsistency.OnlineSourceCount != 1 {
|
||||||
|
t.Fatalf("source consistency should mirror overview source coverage, got %+v", overview.SourceConsistency)
|
||||||
|
}
|
||||||
|
if overview.ServiceStatus == nil || overview.ServiceStatus.Status != "degraded" {
|
||||||
|
t.Fatalf("overview should keep canonical service status, got %+v", overview.ServiceStatus)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -462,10 +462,23 @@ func buildVehicleServiceOverview(vin string, lookupKey string, resolution *Vehic
|
|||||||
if !resolved && resolution != nil {
|
if !resolved && resolution != nil {
|
||||||
resolved = resolution.Resolved
|
resolved = resolution.Resolved
|
||||||
}
|
}
|
||||||
overview.ServiceStatus = buildVehicleServiceStatus(resolved, statusesForOverview(overview))
|
applyVehicleServiceOverviewDerivedFields(overview, resolved)
|
||||||
return overview
|
return overview
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func applyVehicleServiceOverviewDerivedFields(overview *VehicleServiceOverview, resolved bool) {
|
||||||
|
if overview == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
overview.CoverageStatus = coverageStatus(overview.SourceCount, overview.OnlineSourceCount)
|
||||||
|
overview.ServiceStatus = buildVehicleServiceStatus(resolved, statusesForOverview(overview))
|
||||||
|
overview.SourceConsistency = &VehicleSourceConsistency{
|
||||||
|
SourceCount: overview.SourceCount,
|
||||||
|
OnlineSourceCount: overview.OnlineSourceCount,
|
||||||
|
Scope: "all_sources",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func statusesForOverview(overview *VehicleServiceOverview) []VehicleSourceStatus {
|
func statusesForOverview(overview *VehicleServiceOverview) []VehicleSourceStatus {
|
||||||
statuses := make([]VehicleSourceStatus, 0, overview.SourceCount)
|
statuses := make([]VehicleSourceStatus, 0, overview.SourceCount)
|
||||||
for index, protocol := range overview.Protocols {
|
for index, protocol := range overview.Protocols {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { useCallback, useEffect, useState } from 'react';
|
import { useCallback, useEffect, useState } from 'react';
|
||||||
import { Toast } from '@douyinfe/semi-ui';
|
import { Toast } from '@douyinfe/semi-ui';
|
||||||
import { api } from './api/client';
|
import { api } from './api/client';
|
||||||
import type { VehicleServiceOverview, VehicleServiceStatus } from './api/types';
|
import type { VehicleSourceConsistency, VehicleServiceOverview, VehicleServiceStatus } from './api/types';
|
||||||
import { buildAppHash, parseAppHash } from './domain/appRoute';
|
import { buildAppHash, parseAppHash } from './domain/appRoute';
|
||||||
import { AppShell, type PageKey } from './layout/AppShell';
|
import { AppShell, type PageKey } from './layout/AppShell';
|
||||||
import { Dashboard } from './pages/Dashboard';
|
import { Dashboard } from './pages/Dashboard';
|
||||||
@@ -23,6 +23,7 @@ export default function App() {
|
|||||||
const [linkIssueCount, setLinkIssueCount] = useState<number | null>(null);
|
const [linkIssueCount, setLinkIssueCount] = useState<number | null>(null);
|
||||||
const [currentVehicleStatus, setCurrentVehicleStatus] = useState<VehicleServiceStatus | undefined>();
|
const [currentVehicleStatus, setCurrentVehicleStatus] = useState<VehicleServiceStatus | undefined>();
|
||||||
const [currentVehicleLabel, setCurrentVehicleLabel] = useState('');
|
const [currentVehicleLabel, setCurrentVehicleLabel] = useState('');
|
||||||
|
const [currentVehicleConsistency, setCurrentVehicleConsistency] = useState<VehicleSourceConsistency | undefined>();
|
||||||
|
|
||||||
const loadVehicleContext = useCallback(async (keyword: string) => {
|
const loadVehicleContext = useCallback(async (keyword: string) => {
|
||||||
const lookupKey = keyword.trim();
|
const lookupKey = keyword.trim();
|
||||||
@@ -34,6 +35,7 @@ export default function App() {
|
|||||||
const resolved = Boolean(overview.vin);
|
const resolved = Boolean(overview.vin);
|
||||||
setCurrentVehicleStatus(overview.serviceStatus ?? serviceStatusFromOverview(overview));
|
setCurrentVehicleStatus(overview.serviceStatus ?? serviceStatusFromOverview(overview));
|
||||||
setCurrentVehicleLabel(resolved ? [overview.plate, overview.vin || nextKey].filter(Boolean).join(' / ') : lookupKey);
|
setCurrentVehicleLabel(resolved ? [overview.plate, overview.vin || nextKey].filter(Boolean).join(' / ') : lookupKey);
|
||||||
|
setCurrentVehicleConsistency(overview.sourceConsistency);
|
||||||
return { resolved, nextKey, overview };
|
return { resolved, nextKey, overview };
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
@@ -190,7 +192,7 @@ export default function App() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AppShell activePage={activePage} linkIssueCount={linkIssueCount} currentVehicleStatus={currentVehicleStatus} currentVehicleLabel={currentVehicleLabel} onChange={navigatePage} onVehicleSearch={openVehicle}>
|
<AppShell activePage={activePage} linkIssueCount={linkIssueCount} currentVehicleStatus={currentVehicleStatus} currentVehicleLabel={currentVehicleLabel} currentVehicleConsistency={currentVehicleConsistency} onChange={navigatePage} onVehicleSearch={openVehicle}>
|
||||||
{pages[activePage]}
|
{pages[activePage]}
|
||||||
</AppShell>
|
</AppShell>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -126,6 +126,7 @@ export interface VehicleServiceOverview {
|
|||||||
mileageCount: number;
|
mileageCount: number;
|
||||||
qualityIssueCount: number;
|
qualityIssueCount: number;
|
||||||
serviceStatus?: VehicleServiceStatus;
|
serviceStatus?: VehicleServiceStatus;
|
||||||
|
sourceConsistency?: VehicleSourceConsistency;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface VehicleServiceSummary {
|
export interface VehicleServiceSummary {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import {
|
|||||||
} from '@douyinfe/semi-icons';
|
} from '@douyinfe/semi-icons';
|
||||||
import type { ReactNode } from 'react';
|
import type { ReactNode } from 'react';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import type { VehicleServiceStatus } from '../api/types';
|
import type { VehicleSourceConsistency, VehicleServiceStatus } from '../api/types';
|
||||||
|
|
||||||
export type PageKey = 'dashboard' | 'vehicles' | 'realtime' | 'detail' | 'history' | 'mileage' | 'quality';
|
export type PageKey = 'dashboard' | 'vehicles' | 'realtime' | 'detail' | 'history' | 'mileage' | 'quality';
|
||||||
|
|
||||||
@@ -37,6 +37,7 @@ export function AppShell({
|
|||||||
linkIssueCount,
|
linkIssueCount,
|
||||||
currentVehicleStatus,
|
currentVehicleStatus,
|
||||||
currentVehicleLabel,
|
currentVehicleLabel,
|
||||||
|
currentVehicleConsistency,
|
||||||
onChange,
|
onChange,
|
||||||
onVehicleSearch,
|
onVehicleSearch,
|
||||||
children
|
children
|
||||||
@@ -45,6 +46,7 @@ export function AppShell({
|
|||||||
linkIssueCount: number | null;
|
linkIssueCount: number | null;
|
||||||
currentVehicleStatus?: VehicleServiceStatus;
|
currentVehicleStatus?: VehicleServiceStatus;
|
||||||
currentVehicleLabel?: string;
|
currentVehicleLabel?: string;
|
||||||
|
currentVehicleConsistency?: VehicleSourceConsistency;
|
||||||
onChange: (page: PageKey) => void;
|
onChange: (page: PageKey) => void;
|
||||||
onVehicleSearch: (keyword: string) => void | Promise<void>;
|
onVehicleSearch: (keyword: string) => void | Promise<void>;
|
||||||
children: ReactNode;
|
children: ReactNode;
|
||||||
@@ -97,6 +99,11 @@ export function AppShell({
|
|||||||
当前车辆:{currentVehicleStatus.title}
|
当前车辆:{currentVehicleStatus.title}
|
||||||
</Tag>
|
</Tag>
|
||||||
) : null}
|
) : null}
|
||||||
|
{currentVehicleConsistency ? (
|
||||||
|
<Tag color={currentVehicleConsistency.onlineSourceCount === currentVehicleConsistency.sourceCount ? 'green' : 'orange'}>
|
||||||
|
一致性:{currentVehicleConsistency.onlineSourceCount}/{currentVehicleConsistency.sourceCount} 来源
|
||||||
|
</Tag>
|
||||||
|
) : null}
|
||||||
<Tag color="blue">生产环境</Tag>
|
<Tag color="blue">生产环境</Tag>
|
||||||
<Tag color="grey">多源接入 / 一个车辆服务</Tag>
|
<Tag color="grey">多源接入 / 一个车辆服务</Tag>
|
||||||
<Button size="small" className={linkHealthClassName(linkIssueCount)} onClick={() => onChange('quality')}>
|
<Button size="small" className={linkHealthClassName(linkIssueCount)} onClick={() => onChange('quality')}>
|
||||||
|
|||||||
@@ -379,6 +379,14 @@ test('shows resolved vehicle service status after topbar search', async () => {
|
|||||||
detail: '后端统一车辆服务状态',
|
detail: '后端统一车辆服务状态',
|
||||||
sourceCount: 2,
|
sourceCount: 2,
|
||||||
onlineSourceCount: 1
|
onlineSourceCount: 1
|
||||||
|
},
|
||||||
|
sourceConsistency: {
|
||||||
|
sourceCount: 2,
|
||||||
|
onlineSourceCount: 1,
|
||||||
|
locatedSourceCount: 2,
|
||||||
|
mileageDeltaKm: 0,
|
||||||
|
sourceTimeDeltaSeconds: 0,
|
||||||
|
scope: 'all_sources'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
traceId: 'trace-test',
|
traceId: 'trace-test',
|
||||||
@@ -424,6 +432,7 @@ test('shows resolved vehicle service status after topbar search', async () => {
|
|||||||
|
|
||||||
expect(await screen.findByText('当前车辆:后端判定部分离线')).toBeInTheDocument();
|
expect(await screen.findByText('当前车辆:后端判定部分离线')).toBeInTheDocument();
|
||||||
expect(screen.getByText('粤AG18312 / LB9A32A24R0LS1426')).toBeInTheDocument();
|
expect(screen.getByText('粤AG18312 / LB9A32A24R0LS1426')).toBeInTheDocument();
|
||||||
|
expect(screen.getByText('一致性:1/2 来源')).toBeInTheDocument();
|
||||||
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('/api/vehicle-service/overview?keyword=%E7%B2%A4AG18312'), undefined);
|
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('/api/vehicle-service/overview?keyword=%E7%B2%A4AG18312'), undefined);
|
||||||
expect(fetchMock).not.toHaveBeenCalledWith(expect.stringContaining('/api/vehicles/resolve'), undefined);
|
expect(fetchMock).not.toHaveBeenCalledWith(expect.stringContaining('/api/vehicles/resolve'), undefined);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user