Răsfoiți Sursa

评级报告历史分页

AnlaAnla 1 săptămână în urmă
părinte
comite
5e679794e5
1 a modificat fișierele cu 17 adăugiri și 3 ștergeri
  1. 17 3
      app/api/rating_report.py

+ 17 - 3
app/api/rating_report.py

@@ -345,22 +345,36 @@ def generate_rating_report(
 @router.get("/history", status_code=200, summary="根据 cardNo 查询评级报告历史列表")
 def get_rating_report_history_list(
         cardNo: str,
+        skip: int = Query(0, ge=0),
+        page_num: int = Query(None, ge=1),
         limit: int = Query(100, ge=1, le=1000),
         db_conn: PooledMySQLConnection = Depends(get_db_connection)
 ):
     if not cardNo or not cardNo.strip():
         raise HTTPException(status_code=400, detail="cardNo 不能为空")
 
+    if page_num is not None:
+        skip = (page_num - 1) * limit
+
     try:
         with db_conn.cursor(dictionary=True) as cursor:
+            count_sql = (
+                f"SELECT COUNT(*) AS total "
+                f"FROM {settings.RATING_REPORT_HISTORY_TABLE_NAME} "
+                "WHERE cardNo = %s"
+            )
+            cursor.execute(count_sql, (cardNo,))
+            count_row = cursor.fetchone() or {}
+            total_count = int(count_row.get("total") or 0)
+
             query_sql = (
                 f"SELECT rating_id, card_id, cardNo, report_name, created_at "
                 f"FROM {settings.RATING_REPORT_HISTORY_TABLE_NAME} "
                 "WHERE cardNo = %s "
                 "ORDER BY rating_id DESC "
-                "LIMIT %s"
+                "LIMIT %s OFFSET %s"
             )
-            cursor.execute(query_sql, (cardNo, limit))
+            cursor.execute(query_sql, (cardNo, limit, skip))
             rows = cursor.fetchall()
     except Exception as e:
         logger.error(f"查询评级报告历史列表失败: {e}")
@@ -379,7 +393,7 @@ def get_rating_report_history_list(
     return {
         "cardNo": cardNo,
         "data": {
-            "total": len(history_list),
+            "total": total_count,
             "list": history_list
         }
     }