fix(stats): enforce latest source endpoint only for projected daily mileage

This commit is contained in:
lingniu
2026-07-08 14:41:53 +08:00
parent 5f79df3fe2
commit bc2071ef42
3 changed files with 22 additions and 2 deletions

View File

@@ -192,7 +192,7 @@ SELECT
s.latest_total_mileage_km,
s.source_key,
s.phone,
COALESCE(NULLIF(ds.latest_source_endpoint, ''), s.source_endpoint),
ds.latest_source_endpoint,
s.sample_count
FROM vehicle_daily_mileage_source s
LEFT JOIN vehicle_data_source ds

View File

@@ -104,12 +104,18 @@ func TestProjectDailyMileageSelectsCandidateAndMarksSource(t *testing.T) {
"ORDER BY COALESCE(ds.trust_priority, 100)",
"s.quality_status = '" + QualityOK + "'",
"s.daily_mileage_km BETWEEN 0 AND",
"COALESCE(NULLIF(ds.latest_source_endpoint, ''), s.source_endpoint)",
"ds.latest_source_endpoint",
} {
if !strings.Contains(projectFinal, want) {
t.Fatalf("project query missing %q: %s", want, projectFinal)
}
}
if strings.Contains(projectFinal, "COALESCE(NULLIF(ds.latest_source_endpoint, ''), s.source_endpoint)") {
t.Fatalf("project query should not fallback to source endpoint: %s", projectFinal)
}
if strings.Contains(projectFinal, ", s.source_endpoint") {
t.Fatalf("project query should only project latest_source_endpoint: %s", projectFinal)
}
if !strings.Contains(markSelected, "UPDATE vehicle_daily_mileage_source s") || !strings.Contains(markSelected, "SET s.is_selected = 1") {
t.Fatalf("mark query should flag the elected source: %s", markSelected)
}