v2.2更新
This commit is contained in:
@@ -27,14 +27,15 @@ class AdminService:
|
||||
async def get_students(
|
||||
page: int = 1,
|
||||
page_size: int = 20,
|
||||
search: str = None
|
||||
search: str = None,
|
||||
dormitory_number: str = None
|
||||
) -> Dict[str, Any]:
|
||||
"""获取所有学生列表"""
|
||||
offset = (page - 1) * page_size
|
||||
|
||||
sql = """
|
||||
SELECT student_id, student_no, name, total_points, parent_phone, status
|
||||
FROM students
|
||||
SELECT student_id, student_no, name, total_points, parent_phone, dormitory_number, status
|
||||
FROM students
|
||||
WHERE status = 1
|
||||
"""
|
||||
params = []
|
||||
@@ -43,6 +44,10 @@ class AdminService:
|
||||
sql += " AND (student_no LIKE %s OR name LIKE %s)"
|
||||
params.extend([f"%{search}%", f"%{search}%"])
|
||||
|
||||
if dormitory_number:
|
||||
sql += " AND dormitory_number = %s"
|
||||
params.append(dormitory_number)
|
||||
|
||||
sql += " ORDER BY student_no LIMIT %s OFFSET %s"
|
||||
params.extend([page_size, offset])
|
||||
|
||||
@@ -50,12 +55,17 @@ class AdminService:
|
||||
|
||||
# 获取总数
|
||||
count_sql = "SELECT COUNT(*) as total FROM students WHERE status = 1"
|
||||
count_params = []
|
||||
if search:
|
||||
count_sql += " AND (student_no LIKE %s OR name LIKE %s)"
|
||||
total_result = await execute_one(count_sql, (f"%{search}%", f"%{search}%"))
|
||||
count_params.extend([f"%{search}%", f"%{search}%"])
|
||||
if dormitory_number:
|
||||
count_sql += " AND dormitory_number = %s"
|
||||
count_params.append(dormitory_number)
|
||||
if count_params:
|
||||
total_result = await execute_one(count_sql, tuple(count_params))
|
||||
else:
|
||||
total_result = await execute_one(count_sql)
|
||||
|
||||
total = total_result["total"] if total_result else 0
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user