feat(platform): share vehicle service verdict logic
This commit is contained in:
@@ -7,6 +7,7 @@ import { PageHeader } from '../components/PageHeader';
|
||||
import { SourceStatusTags } from '../components/SourceStatusTags';
|
||||
import { StatusTag } from '../components/StatusTag';
|
||||
import { isLikelyVIN } from '../domain/vehicleLookup';
|
||||
import { summarizeVehicleService } from '../domain/vehicleService';
|
||||
|
||||
type VehicleQuery = {
|
||||
keyword: string;
|
||||
@@ -69,13 +70,6 @@ type VehicleServiceAction = {
|
||||
onClick: () => void;
|
||||
};
|
||||
|
||||
type VehicleServiceConclusion = {
|
||||
status: string;
|
||||
color: 'green' | 'orange' | 'red';
|
||||
risk: string;
|
||||
nextStep: string;
|
||||
};
|
||||
|
||||
async function copyVehicleServiceURL() {
|
||||
try {
|
||||
await navigator.clipboard.writeText(`${window.location.origin}${window.location.pathname}${window.location.hash}`);
|
||||
@@ -237,62 +231,14 @@ export function VehicleDetail({
|
||||
onQueryChange?.(nextQuery.keyword, nextQuery.protocol);
|
||||
load(nextQuery);
|
||||
};
|
||||
const serviceConclusion = useMemo<VehicleServiceConclusion>(() => {
|
||||
if (!hasResolvedVIN) {
|
||||
return {
|
||||
status: '不可服务',
|
||||
color: 'red',
|
||||
risk: '身份未归并到 VIN',
|
||||
nextStep: '先维护车辆身份绑定,再使用实时、历史和里程服务。'
|
||||
};
|
||||
}
|
||||
if (sourceCount <= 0) {
|
||||
return {
|
||||
status: '不可服务',
|
||||
color: 'red',
|
||||
risk: '没有任何来源证据',
|
||||
nextStep: '优先确认平台转发、端口、订阅和绑定配置。'
|
||||
};
|
||||
}
|
||||
if (onlineSourceCount <= 0) {
|
||||
return {
|
||||
status: '不可服务',
|
||||
color: 'red',
|
||||
risk: '全部来源离线',
|
||||
nextStep: '先恢复至少一个实时来源,再判断车辆状态。'
|
||||
};
|
||||
}
|
||||
if (qualityCount > 0) {
|
||||
return {
|
||||
status: '降级可服务',
|
||||
color: 'orange',
|
||||
risk: `${qualityCount} 项质量问题影响可信度`,
|
||||
nextStep: '先处理质量问题,再将该车用于 BI、告警或对外查询。'
|
||||
};
|
||||
}
|
||||
if (missingProtocols.length > 0) {
|
||||
return {
|
||||
status: '降级可服务',
|
||||
color: 'orange',
|
||||
risk: `缺少 ${missingProtocols.join('、')} 来源`,
|
||||
nextStep: '车辆仍可查询,但需要补齐缺失来源后再做跨来源校验。'
|
||||
};
|
||||
}
|
||||
if (isFiniteNumber(consistencyMileageDelta) && consistencyMileageDelta > 1) {
|
||||
return {
|
||||
status: '降级可服务',
|
||||
color: 'orange',
|
||||
risk: `跨来源里程差异 ${formatCompactNumber(consistencyMileageDelta, ' km')}`,
|
||||
nextStep: '核对各来源总里程口径,确认统计使用的主来源。'
|
||||
};
|
||||
}
|
||||
return {
|
||||
status: '可服务',
|
||||
color: 'green',
|
||||
risk: '身份、来源和核心实时证据可用',
|
||||
nextStep: '可进入实时、历史、RAW 和里程查询继续分析。'
|
||||
};
|
||||
}, [consistencyMileageDelta, hasResolvedVIN, missingProtocols, onlineSourceCount, qualityCount, sourceCount]);
|
||||
const serviceConclusion = useMemo(() => summarizeVehicleService({
|
||||
resolved: hasResolvedVIN,
|
||||
sourceCount,
|
||||
onlineSourceCount,
|
||||
qualityIssueCount: qualityCount,
|
||||
missingProtocols,
|
||||
mileageDeltaKm: consistencyMileageDelta
|
||||
}), [consistencyMileageDelta, hasResolvedVIN, missingProtocols, onlineSourceCount, qualityCount, sourceCount]);
|
||||
const qualityFiltersForCurrentVehicle = () => ({
|
||||
keyword: resolvedVIN,
|
||||
...(activeProtocol ? { protocol: activeProtocol } : {})
|
||||
|
||||
Reference in New Issue
Block a user