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