feat(platform): paginate quality issues

This commit is contained in:
lingniu
2026-07-03 22:27:40 +08:00
parent 39e2788e26
commit 28d1a68823
2 changed files with 41 additions and 13 deletions

View File

@@ -313,12 +313,17 @@ func (s *ProductionStore) QualityIssues(ctx context.Context, query url.Values) (
like := "%" + keyword + "%"
args = append(args, like, like, like)
}
countArgs := append([]any(nil), args...)
args = append(args, limit, offset)
fromSQL := `FROM jt808_registration r LEFT JOIN vehicle_identity_binding b ON b.phone = r.phone WHERE ` + strings.Join(where, " AND ")
total := 0
if err := s.db.QueryRowContext(ctx, `SELECT COUNT(*) `+fromSQL, countArgs...).Scan(&total); err != nil {
return Page[QualityIssueRow]{}, err
}
rows, err := s.db.QueryContext(ctx, `SELECT COALESCE(b.vin, 'unknown') AS vin, COALESCE(b.plate, '') AS plate, r.phone, COALESCE(r.source_endpoint, ''), COALESCE(DATE_FORMAT(r.latest_seen_at, '%Y-%m-%d %H:%i:%s'), '') `+
`FROM jt808_registration r LEFT JOIN vehicle_identity_binding b ON b.phone = r.phone `+
`WHERE `+strings.Join(where, " AND ")+` ORDER BY r.latest_seen_at DESC LIMIT ? OFFSET ?`, args...)
fromSQL+` ORDER BY r.latest_seen_at DESC, r.phone ASC LIMIT ? OFFSET ?`, args...)
if err != nil {
return Page[QualityIssueRow]{}, nil
return Page[QualityIssueRow]{}, err
}
defer rows.Close()
items := make([]QualityIssueRow, 0)
@@ -337,7 +342,7 @@ func (s *ProductionStore) QualityIssues(ctx context.Context, query url.Values) (
Detail: fmt.Sprintf("phone %s 未命中 binding 表,来源 %s", phone, source),
})
}
return Page[QualityIssueRow]{Items: items, Total: len(items), Limit: limit, Offset: offset}, rows.Err()
return Page[QualityIssueRow]{Items: items, Total: total, Limit: limit, Offset: offset}, rows.Err()
}
func (s *ProductionStore) OpsHealth(ctx context.Context) (OpsHealth, error) {