feat(platform): expose missing source diagnosis
This commit is contained in:
@@ -333,6 +333,9 @@ func buildVehicleSourceConsistency(statuses []VehicleSourceStatus, realtime []Re
|
||||
if status.Online {
|
||||
consistency.OnlineSourceCount++
|
||||
}
|
||||
if vehicleSourceEvidenceMissing(status) {
|
||||
consistency.MissingProtocols = append(consistency.MissingProtocols, status.Protocol)
|
||||
}
|
||||
}
|
||||
var minMileage, maxMileage float64
|
||||
hasMileage := false
|
||||
@@ -393,6 +396,16 @@ func buildVehicleSourceConsistency(statuses []VehicleSourceStatus, realtime []Re
|
||||
return consistency
|
||||
}
|
||||
|
||||
func vehicleSourceEvidenceMissing(status VehicleSourceStatus) bool {
|
||||
return strings.TrimSpace(status.Protocol) != "" &&
|
||||
!status.Online &&
|
||||
strings.TrimSpace(status.LastSeen) == "" &&
|
||||
!status.HasRealtime &&
|
||||
!status.HasHistory &&
|
||||
!status.HasRaw &&
|
||||
!status.HasMileage
|
||||
}
|
||||
|
||||
func applyVehicleSourceConsistencyDiagnosis(consistency *VehicleSourceConsistency) {
|
||||
if consistency == nil {
|
||||
return
|
||||
@@ -413,6 +426,11 @@ func applyVehicleSourceConsistencyDiagnosis(consistency *VehicleSourceConsistenc
|
||||
consistency.Severity = "error"
|
||||
consistency.Title = "全部来源离线"
|
||||
consistency.Detail = sourceCoverageDetail(consistency.SourceCount, consistency.OnlineSourceCount, "无法判断实时一致性。")
|
||||
case len(consistency.MissingProtocols) > 0:
|
||||
consistency.Status = "degraded"
|
||||
consistency.Severity = "warning"
|
||||
consistency.Title = "来源不完整"
|
||||
consistency.Detail = sourceCoverageDetail(consistency.SourceCount, consistency.OnlineSourceCount, "车辆服务可用但缺少 "+strings.Join(consistency.MissingProtocols, "、")+" 来源。")
|
||||
case consistency.OnlineSourceCount < consistency.SourceCount:
|
||||
consistency.Status = "degraded"
|
||||
consistency.Severity = "warning"
|
||||
@@ -520,6 +538,8 @@ func buildVehicleServiceOverview(vin string, lookupKey string, resolution *Vehic
|
||||
resolved = resolution.Resolved
|
||||
}
|
||||
applyVehicleServiceOverviewDerivedFields(overview, resolved)
|
||||
overview.SourceConsistency.MissingProtocols = missingProtocolsFromStatuses(statuses)
|
||||
applyVehicleSourceConsistencyDiagnosis(overview.SourceConsistency)
|
||||
return overview
|
||||
}
|
||||
|
||||
@@ -532,6 +552,7 @@ func applyVehicleServiceOverviewDerivedFields(overview *VehicleServiceOverview,
|
||||
overview.SourceConsistency = &VehicleSourceConsistency{
|
||||
SourceCount: overview.SourceCount,
|
||||
OnlineSourceCount: overview.OnlineSourceCount,
|
||||
MissingProtocols: missingCanonicalProtocols(overview.Protocols),
|
||||
Scope: "all_sources",
|
||||
}
|
||||
applyVehicleSourceConsistencyDiagnosis(overview.SourceConsistency)
|
||||
@@ -899,7 +920,8 @@ func buildVehicleServiceStatus(resolved bool, statuses []VehicleSourceStatus) *V
|
||||
onlineSourceCount++
|
||||
}
|
||||
}
|
||||
if sourceCount == 0 {
|
||||
missingProtocols := missingProtocolsFromStatuses(statuses)
|
||||
if sourceCount == 0 || sourceCount == len(missingProtocols) {
|
||||
return &VehicleServiceStatus{
|
||||
Status: "no_data",
|
||||
Severity: "warning",
|
||||
@@ -919,6 +941,16 @@ func buildVehicleServiceStatus(resolved bool, statuses []VehicleSourceStatus) *V
|
||||
OnlineSourceCount: onlineSourceCount,
|
||||
}
|
||||
}
|
||||
if len(missingProtocols) > 0 {
|
||||
return &VehicleServiceStatus{
|
||||
Status: "degraded",
|
||||
Severity: "warning",
|
||||
Title: "来源不完整",
|
||||
Detail: sourceCoverageDetail(sourceCount, onlineSourceCount, "车辆服务可用但缺少 "+strings.Join(missingProtocols, "、")+" 来源。"),
|
||||
SourceCount: sourceCount,
|
||||
OnlineSourceCount: onlineSourceCount,
|
||||
}
|
||||
}
|
||||
if onlineSourceCount < sourceCount {
|
||||
return &VehicleServiceStatus{
|
||||
Status: "degraded",
|
||||
@@ -939,6 +971,16 @@ func buildVehicleServiceStatus(resolved bool, statuses []VehicleSourceStatus) *V
|
||||
}
|
||||
}
|
||||
|
||||
func missingProtocolsFromStatuses(statuses []VehicleSourceStatus) []string {
|
||||
missing := make([]string, 0, len(statuses))
|
||||
for _, status := range statuses {
|
||||
if vehicleSourceEvidenceMissing(status) {
|
||||
missing = append(missing, status.Protocol)
|
||||
}
|
||||
}
|
||||
return missing
|
||||
}
|
||||
|
||||
func buildVehicleCoverageServiceStatus(row VehicleCoverageRow) *VehicleServiceStatus {
|
||||
if row.BindingStatus != "bound" {
|
||||
return &VehicleServiceStatus{
|
||||
|
||||
Reference in New Issue
Block a user