v1.1更新家长端可查看历史记录
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
# 版权所有 © Sea Network Technology Studio
|
||||
# ===========================================
|
||||
|
||||
from typing import Dict, Any, Optional
|
||||
from typing import Dict, Any, Optional, List
|
||||
|
||||
from models.user import UserModel
|
||||
from models.student import StudentModel
|
||||
@@ -61,7 +61,6 @@ class ParentService:
|
||||
"student_name": student["name"],
|
||||
"homework": homework
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
async def get_child_attendance(parent_id: int) -> Dict[str, Any]:
|
||||
"""获取子女考勤记录"""
|
||||
@@ -79,4 +78,67 @@ class ParentService:
|
||||
"student_id": student["student_id"],
|
||||
"student_name": student["name"],
|
||||
"records": records
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
async def get_child_ranking(parent_id: int) -> Dict[str, Any]:
|
||||
"""获取子女排名信息"""
|
||||
user = await UserModel.get_by_user_id(parent_id)
|
||||
if not user or not user["student_id"]:
|
||||
return {"error": "未关联学生"}
|
||||
|
||||
student = await StudentModel.get_by_id(user["student_id"])
|
||||
if not student:
|
||||
return {"error": "学生不存在"}
|
||||
|
||||
# 获取全班排名
|
||||
ranking = await StudentModel.get_ranking(limit=1000)
|
||||
|
||||
# 查找当前学生排名
|
||||
student_rank = None
|
||||
total_students = 0
|
||||
for r in ranking:
|
||||
total_students += 1
|
||||
if r["student_id"] == user["student_id"]:
|
||||
student_rank = r["rank"]
|
||||
|
||||
return {
|
||||
"student_id": student["student_id"],
|
||||
"student_name": student["name"],
|
||||
"student_no": student["student_no"],
|
||||
"total_points": student["total_points"],
|
||||
"rank": student_rank,
|
||||
"total_students": total_students
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
async def get_child_history(parent_id: int, page: int = 1, page_size: int = 20) -> Dict[str, Any]:
|
||||
"""获取子女操行分历史记录"""
|
||||
user = await UserModel.get_by_user_id(parent_id)
|
||||
if not user or not user["student_id"]:
|
||||
return {"error": "未关联学生"}
|
||||
|
||||
student = await StudentModel.get_by_id(user["student_id"])
|
||||
if not student:
|
||||
return {"error": "学生不存在"}
|
||||
|
||||
offset = (page - 1) * page_size
|
||||
records = await ConductModel.get_student_records(
|
||||
student_id=user["student_id"],
|
||||
limit=page_size,
|
||||
offset=offset
|
||||
)
|
||||
|
||||
# 获取总数
|
||||
all_records = await ConductModel.get_student_records(user["student_id"], limit=10000)
|
||||
total = len(all_records)
|
||||
|
||||
return {
|
||||
"student_id": student["student_id"],
|
||||
"student_name": student["name"],
|
||||
"total_points": student["total_points"],
|
||||
"records": records,
|
||||
"total": total,
|
||||
"page": page,
|
||||
"page_size": page_size
|
||||
}
|
||||
Reference in New Issue
Block a user