v2.2更新
This commit is contained in:
@@ -14,9 +14,9 @@ from datetime import datetime, timedelta
|
||||
|
||||
from models.student import StudentModel
|
||||
from models.conduct import ConductModel
|
||||
from models.homework import HomeworkModel
|
||||
from models.attendance import AttendanceModel
|
||||
from middleware.permission import PermissionChecker
|
||||
from utils.database import execute_query
|
||||
from utils.logger import get_logger
|
||||
|
||||
logger = get_logger(__name__)
|
||||
@@ -57,29 +57,33 @@ class StudentService:
|
||||
|
||||
@staticmethod
|
||||
async def get_homework_status(student_id: int) -> Dict[str, Any]:
|
||||
"""获取学生作业情况"""
|
||||
"""获取学生作业扣分记录"""
|
||||
student = await StudentModel.get_by_id(student_id)
|
||||
if not student:
|
||||
return {"error": "学生不存在"}
|
||||
|
||||
homework = await HomeworkModel.get_student_homework(student_id)
|
||||
# 查询作业相关的操行分记录
|
||||
sql = """
|
||||
SELECT cr.record_id, cr.points_change, cr.reason, cr.created_at,
|
||||
cr.related_type, cr.recorder_name
|
||||
FROM conduct_records cr
|
||||
WHERE cr.student_id = %s AND cr.related_type = 'homework' AND cr.is_revoked = 0
|
||||
ORDER BY cr.created_at DESC
|
||||
"""
|
||||
records = await execute_query(sql, (student_id,))
|
||||
|
||||
# 统计
|
||||
total = len(homework)
|
||||
submitted = sum(1 for h in homework if h["status"] == "submitted")
|
||||
not_submitted = sum(1 for h in homework if h["status"] == "not_submitted")
|
||||
late = sum(1 for h in homework if h["status"] == "late")
|
||||
total = len(records)
|
||||
deductions = sum(1 for r in records if r["points_change"] < 0)
|
||||
|
||||
return {
|
||||
"student_id": student_id,
|
||||
"student_name": student["name"],
|
||||
"statistics": {
|
||||
"total": total,
|
||||
"submitted": submitted,
|
||||
"not_submitted": not_submitted,
|
||||
"late": late
|
||||
"deductions": deductions
|
||||
},
|
||||
"homework": homework
|
||||
"homework": records
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
|
||||
Reference in New Issue
Block a user