feat(platform): add vehicle command center

This commit is contained in:
lingniu
2026-07-04 11:15:56 +08:00
parent 688cf0a155
commit e94d0e348f
3 changed files with 228 additions and 4 deletions

View File

@@ -6,6 +6,8 @@ import type { DashboardSummary, LinkHealth, ProtocolStat, QualityIssueRow, Servi
import { PageHeader } from '../components/PageHeader';
import { SourceStatusTags } from '../components/SourceStatusTags';
import { StatusTag } from '../components/StatusTag';
import { VehicleMap, type VehicleMapPoint } from '../components/VehicleMap';
import { isAMapConfigured } from '../config/appConfig';
import { qualityIssueVehicleLookup } from '../domain/vehicleLookup';
const statusColor: Record<string, 'green' | 'orange' | 'red' | 'grey'> = {
@@ -80,6 +82,10 @@ function sourceEvidenceText(row: { onlineSourceCount: number; sourceCount: numbe
return `${row.onlineSourceCount}/${row.sourceCount} 来源在线`;
}
function hasValidCoordinate(row: VehicleRealtimeRow) {
return Number.isFinite(row.longitude) && Number.isFinite(row.latitude) && row.longitude !== 0 && row.latitude !== 0;
}
function sourceConsistencyAction(row: VehicleCoverageRow, onFilter: (filters: Record<string, string>) => void) {
const consistency = row.sourceConsistency;
if (!consistency) {
@@ -102,7 +108,17 @@ function sourceConsistencyAction(row: VehicleCoverageRow, onFilter: (filters: Re
return <Tag color={color}>{label}</Tag>;
}
export function Dashboard({ onOpenVehicle, onOpenQuality, onOpenVehicles }: { onOpenVehicle: (vin: string, protocol?: string) => void; onOpenQuality: () => void; onOpenVehicles: (filters?: Record<string, string>) => void }) {
export function Dashboard({
onOpenVehicle,
onOpenQuality,
onOpenRealtime,
onOpenVehicles
}: {
onOpenVehicle: (vin: string, protocol?: string) => void;
onOpenQuality: (filters?: Record<string, string>) => void;
onOpenRealtime: (filters?: Record<string, string>) => void;
onOpenVehicles: (filters?: Record<string, string>) => void;
}) {
const [summary, setSummary] = useState<DashboardSummary | null>(null);
const [serviceSummary, setServiceSummary] = useState<VehicleServiceSummary | null>(null);
const [coverage, setCoverage] = useState<VehicleCoverageRow[]>([]);
@@ -112,6 +128,7 @@ export function Dashboard({ onOpenVehicle, onOpenQuality, onOpenVehicles }: { on
const [coverageLoading, setCoverageLoading] = useState(false);
const [coverageServiceStatusTitle, setCoverageServiceStatusTitle] = useState('');
const [coverageFilters, setCoverageFilters] = useState<Record<string, string>>({});
const amapConfigured = isAMapConfigured();
const loadCoverage = (values?: Record<string, string>) => {
const nextValues = values ?? {};
@@ -210,6 +227,18 @@ export function Dashboard({ onOpenVehicle, onOpenQuality, onOpenVehicles }: { on
}
return items;
}, [serviceSummary]);
const commandOnlineCount = locations.filter((row) => row.online).length;
const commandLocatedCount = locations.filter(hasValidCoordinate).length;
const commandDegradedCount = locations.filter((row) => row.onlineSourceCount <= 0 || row.onlineSourceCount < row.sourceCount).length;
const highPriorityIssue = qualityIssues.find((item) => item.severity === 'error') ?? qualityIssues[0];
const commandMapPoints: VehicleMapPoint[] = locations.map((row, index) => ({
id: row.vin || `${row.primaryProtocol || 'source'}-${index}`,
label: row.plate || row.vin || 'unknown',
longitude: row.longitude,
latitude: row.latitude,
online: row.online,
title: `${row.plate || row.vin || '-'} ${row.primaryProtocol || ''} ${row.lastSeen || ''}`
}));
return (
<div className="vp-page">
@@ -234,10 +263,59 @@ export function Dashboard({ onOpenVehicle, onOpenQuality, onOpenVehicles }: { on
<Tag color={(summary?.issueVehicles ?? 0) > 0 ? 'orange' : 'green'}>
{formatCount(summary?.issueVehicles)}
</Tag>
<Button size="small" theme="light" type={(summary?.issueVehicles ?? 0) > 0 ? 'warning' : 'tertiary'} onClick={onOpenQuality}></Button>
<Button size="small" theme="light" type={(summary?.issueVehicles ?? 0) > 0 ? 'warning' : 'tertiary'} onClick={() => onOpenQuality()}></Button>
<Tag color={(summary?.kafkaLag ?? 0) > 0 ? 'orange' : 'green'}>Kafka Lag {formatLag(summary?.kafkaLag)}</Tag>
</Space>
</Card>
<Card
bordered
title="车辆态势指挥台"
style={{ marginBottom: 16 }}
>
<div className="vp-monitor-layout">
<div className="vp-monitor-map">
<div className="vp-monitor-map-header">
<Space wrap>
<Tag color={amapConfigured ? 'green' : 'orange'}>
{amapConfigured ? '高德地图配置就绪' : '高德地图待配置'}
</Tag>
<Tag color="green">线 {commandOnlineCount.toLocaleString()} / {locations.length.toLocaleString()}</Tag>
<Tag color="blue"> {commandLocatedCount.toLocaleString()}</Tag>
<Tag color={commandDegradedCount > 0 ? 'orange' : 'green'}>/线 {commandDegradedCount.toLocaleString()}</Tag>
</Space>
</div>
<VehicleMap
points={commandMapPoints}
maxFallbackPoints={80}
fallbackLabel="高德地图未配置,显示车辆态势坐标预览"
/>
</div>
<div className="vp-monitor-side">
<div className="vp-monitor-metric">
<Tag color="green"></Tag>
<div className="vp-monitor-metric-value">{commandOnlineCount.toLocaleString()}</div>
<Typography.Text type="secondary">线</Typography.Text>
</div>
<div className="vp-monitor-metric">
<Tag color={commandDegradedCount > 0 ? 'orange' : 'green'}></Tag>
<div className="vp-monitor-metric-value">{commandDegradedCount.toLocaleString()}</div>
<Typography.Text type="secondary">线</Typography.Text>
</div>
<Space vertical align="start">
<Button theme="solid" type="primary" onClick={() => onOpenRealtime({ online: 'online' })}></Button>
<Button
disabled={!highPriorityIssue?.issueType}
theme="light"
type="warning"
onClick={() => onOpenQuality(highPriorityIssue?.issueType ? { issueType: highPriorityIssue.issueType } : {})}
>
</Button>
<Button theme="light" onClick={() => onOpenVehicles({ serviceStatus: 'degraded' })}></Button>
</Space>
</div>
</div>
</Card>
{serviceActionQueue.length > 0 ? (
<Card bordered title="车辆服务处置队列" style={{ marginBottom: 16 }}>
<div className="vp-action-grid">
@@ -339,7 +417,7 @@ export function Dashboard({ onOpenVehicle, onOpenQuality, onOpenVehicles }: { on
<Typography.Text>Kafka {formatLag(summary?.kafkaLag)}</Typography.Text>
</Card>
<Card
title={<Space><span></span><Button size="small" onClick={onOpenQuality}></Button></Space>}
title={<Space><span></span><Button size="small" onClick={() => onOpenQuality()}></Button></Space>}
bordered
style={{ marginTop: 16 }}
>