feat(platform): filter vehicles by archive status

This commit is contained in:
lingniu
2026-07-04 09:37:51 +08:00
parent 817e5324f6
commit 29f84099b2
6 changed files with 55 additions and 4 deletions

View File

@@ -102,6 +102,15 @@ func buildVehicleCoverageSQL(query url.Values) SQLQuery {
case "unbound":
having = append(having, "MAX(CASE WHEN b.vin IS NOT NULL AND b.vin <> '' THEN 1 ELSE 0 END) = 0")
}
switch strings.TrimSpace(query.Get("archiveStatus")) {
case "complete":
having = append(having, "v.vin IS NOT NULL AND v.vin <> ''")
having = append(having, "COALESCE(NULLIF(MAX(NULLIF(s.plate, '')), ''), NULLIF(MAX(NULLIF(b.plate, '')), '')) IS NOT NULL")
having = append(having, "NULLIF(MAX(NULLIF(b.phone, '')), '') IS NOT NULL")
having = append(having, "NULLIF(MAX(NULLIF(b.oem, '')), '') IS NOT NULL")
case "incomplete":
having = append(having, "(v.vin IS NULL OR v.vin = '' OR COALESCE(NULLIF(MAX(NULLIF(s.plate, '')), ''), NULLIF(MAX(NULLIF(b.plate, '')), '')) IS NULL OR NULLIF(MAX(NULLIF(b.phone, '')), '') IS NULL OR NULLIF(MAX(NULLIF(b.oem, '')), '') IS NULL)")
}
switch strings.TrimSpace(query.Get("serviceStatus")) {
case "identity_required":
having = append(having, "MAX(CASE WHEN b.vin IS NOT NULL AND b.vin <> '' THEN 1 ELSE 0 END) = 0")
@@ -191,6 +200,15 @@ func buildVehicleCoverageSummarySQL(query url.Values) SQLQuery {
case "unbound":
having = append(having, "MAX(CASE WHEN b.vin IS NOT NULL AND b.vin <> '' THEN 1 ELSE 0 END) = 0")
}
switch strings.TrimSpace(query.Get("archiveStatus")) {
case "complete":
having = append(having, "v.vin IS NOT NULL AND v.vin <> ''")
having = append(having, "COALESCE(NULLIF(MAX(NULLIF(s.plate, '')), ''), NULLIF(MAX(NULLIF(b.plate, '')), '')) IS NOT NULL")
having = append(having, "NULLIF(MAX(NULLIF(b.phone, '')), '') IS NOT NULL")
having = append(having, "NULLIF(MAX(NULLIF(b.oem, '')), '') IS NOT NULL")
case "incomplete":
having = append(having, "(v.vin IS NULL OR v.vin = '' OR COALESCE(NULLIF(MAX(NULLIF(s.plate, '')), ''), NULLIF(MAX(NULLIF(b.plate, '')), '')) IS NULL OR NULLIF(MAX(NULLIF(b.phone, '')), '') IS NULL OR NULLIF(MAX(NULLIF(b.oem, '')), '') IS NULL)")
}
switch strings.TrimSpace(query.Get("serviceStatus")) {
case "identity_required":
having = append(having, "MAX(CASE WHEN b.vin IS NOT NULL AND b.vin <> '' THEN 1 ELSE 0 END) = 0")

View File

@@ -117,6 +117,22 @@ func TestBuildVehicleCoverageSQLFiltersMissingProtocol(t *testing.T) {
}
}
func TestBuildVehicleCoverageSQLFiltersArchiveStatus(t *testing.T) {
query := url.Values{"archiveStatus": {"incomplete"}, "limit": {"8"}}
built := buildVehicleCoverageSQL(query)
for _, want := range []string{
"HAVING",
"COALESCE(NULLIF(MAX(NULLIF(s.plate, '')), ''), NULLIF(MAX(NULLIF(b.plate, '')), '')) IS NULL",
"NULLIF(MAX(NULLIF(b.phone, '')), '') IS NULL",
"NULLIF(MAX(NULLIF(b.oem, '')), '') IS NULL",
"vehicle_coverage_count",
} {
if !strings.Contains(built.Text+built.CountText, want) {
t.Fatalf("archive status SQL missing %q: %s / %s", want, built.Text, built.CountText)
}
}
}
func TestBuildVehicleCoverageSummarySQL(t *testing.T) {
query := url.Values{"keyword": {"粤A"}, "coverage": {"multi"}, "online": {"online"}, "bindingStatus": {"bound"}, "serviceStatus": {"healthy"}}
built := buildVehicleCoverageSummarySQL(query)