v1.7版本更新
This commit is contained in:
@@ -42,18 +42,22 @@ class HomeworkModel:
|
||||
"""
|
||||
return await execute_query(sql, tuple(subject_ids))
|
||||
|
||||
@staticmethod
|
||||
@staticmethod
|
||||
async def get_student_homework(student_id: int) -> List[Dict[str, Any]]:
|
||||
sql = """
|
||||
SELECT a.assignment_id, a.title, a.description, a.deadline,
|
||||
s.subject_name, hs.status, hs.submit_time, hs.comments, hs.deduction_applied
|
||||
SELECT a.assignment_id, a.title, a.description, a.deadline, a.created_at,
|
||||
s.subject_name, hs.status, hs.submit_time, hs.comments, hs.deduction_applied,
|
||||
cr.points_change AS points
|
||||
FROM assignments a
|
||||
JOIN subjects s ON a.subject_id = s.subject_id
|
||||
LEFT JOIN homework_submissions hs ON a.assignment_id = hs.assignment_id AND hs.student_id = %s
|
||||
LEFT JOIN conduct_records cr ON cr.related_type = 'homework'
|
||||
AND cr.related_id = a.assignment_id AND cr.student_id = %s AND cr.is_revoked = 0
|
||||
GROUP BY a.assignment_id
|
||||
ORDER BY a.deadline ASC, a.created_at DESC
|
||||
"""
|
||||
return await execute_query(sql, (student_id,))
|
||||
|
||||
return await execute_query(sql, (student_id, student_id))
|
||||
@staticmethod
|
||||
async def get_submission(submission_id: int) -> Optional[Dict[str, Any]]:
|
||||
sql = """
|
||||
|
||||
@@ -44,8 +44,8 @@ class StudentModel:
|
||||
async def get_all(include_disabled: bool = False) -> List[Dict[str, Any]]:
|
||||
"""获取所有学生列表(单班级)"""
|
||||
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 1=1
|
||||
"""
|
||||
if not include_disabled:
|
||||
@@ -58,17 +58,18 @@ class StudentModel:
|
||||
student_no: str,
|
||||
name: str,
|
||||
parent_phone: str = None,
|
||||
dormitory_number: str = None,
|
||||
initial_points: int = 60
|
||||
) -> int:
|
||||
"""创建学生(初始操行分默认60分)"""
|
||||
sql = """
|
||||
INSERT INTO students (student_no, name, parent_phone, total_points)
|
||||
VALUES (%s, %s, %s, %s)
|
||||
INSERT INTO students (student_no, name, parent_phone, dormitory_number, total_points)
|
||||
VALUES (%s, %s, %s, %s, %s)
|
||||
"""
|
||||
return await execute_insert(sql, (student_no, name, parent_phone, initial_points))
|
||||
return await execute_insert(sql, (student_no, name, parent_phone, dormitory_number, initial_points))
|
||||
|
||||
@staticmethod
|
||||
async def update(student_id: int, name: str = None, parent_phone: str = None, status: int = None) -> bool:
|
||||
async def update(student_id: int, name: str = None, parent_phone: str = None, dormitory_number: str = None, status: int = None) -> bool:
|
||||
"""更新学生信息"""
|
||||
updates = []
|
||||
params = []
|
||||
@@ -79,6 +80,9 @@ class StudentModel:
|
||||
if parent_phone is not None:
|
||||
updates.append("parent_phone = %s")
|
||||
params.append(parent_phone)
|
||||
if dormitory_number is not None:
|
||||
updates.append("dormitory_number = %s")
|
||||
params.append(dormitory_number)
|
||||
if status is not None:
|
||||
updates.append("status = %s")
|
||||
params.append(status)
|
||||
@@ -101,7 +105,7 @@ class StudentModel:
|
||||
@staticmethod
|
||||
async def update_total_points(student_id: int, points_change: int) -> bool:
|
||||
"""更新学生总分"""
|
||||
sql = "UPDATE students SET total_points = total_points + %s WHERE student_id = %s"
|
||||
sql = "UPDATE students SET total_points = total_points + %s, points_updated_at = CURRENT_TIMESTAMP WHERE student_id = %s"
|
||||
result = await execute_update(sql, (points_change, student_id))
|
||||
return result > 0
|
||||
|
||||
@@ -109,10 +113,10 @@ class StudentModel:
|
||||
async def get_ranking(limit: int = 50) -> List[Dict[str, Any]]:
|
||||
"""获取学生排行(单班级)"""
|
||||
sql = """
|
||||
SELECT student_id, student_no, name, total_points
|
||||
SELECT student_id, student_no, name, total_points, points_updated_at
|
||||
FROM students
|
||||
WHERE status = 1
|
||||
ORDER BY total_points DESC
|
||||
ORDER BY total_points DESC, points_updated_at ASC
|
||||
LIMIT %s
|
||||
"""
|
||||
results = await execute_query(sql, (limit,))
|
||||
@@ -137,6 +141,7 @@ class StudentModel:
|
||||
student_no=student.get('student_no'),
|
||||
name=student.get('name'),
|
||||
parent_phone=student.get('parent_phone'),
|
||||
dormitory_number=student.get('dormitory_number'),
|
||||
initial_points=initial_points
|
||||
)
|
||||
results.append({
|
||||
|
||||
@@ -44,7 +44,7 @@ class UserModel:
|
||||
@staticmethod
|
||||
async def create_student(username: str, password: str, real_name: str, student_id: int) -> int:
|
||||
"""创建学生账号"""
|
||||
password_hash = security.sha1_md5_password(password)
|
||||
password_hash = security.bcrypt_password(password)
|
||||
sql = """
|
||||
INSERT INTO users (username, password_hash, real_name, user_type, student_id, need_change_password)
|
||||
VALUES (%s, %s, %s, 'student', %s, 1)
|
||||
@@ -54,7 +54,7 @@ class UserModel:
|
||||
@staticmethod
|
||||
async def create_parent(username: str, password: str, real_name: str, student_id: int) -> int:
|
||||
"""创建家长账号"""
|
||||
password_hash = security.sha1_md5_password(password)
|
||||
password_hash = security.bcrypt_password(password)
|
||||
sql = """
|
||||
INSERT INTO users (username, password_hash, real_name, user_type, student_id, need_change_password)
|
||||
VALUES (%s, %s, %s, 'parent', %s, 0)
|
||||
@@ -64,7 +64,7 @@ class UserModel:
|
||||
@staticmethod
|
||||
async def create_admin(username: str, password: str, real_name: str) -> int:
|
||||
"""创建管理员账号"""
|
||||
password_hash = security.sha1_md5_password(password)
|
||||
password_hash = security.bcrypt_password(password)
|
||||
sql = """
|
||||
INSERT INTO users (username, password_hash, real_name, user_type, need_change_password)
|
||||
VALUES (%s, %s, %s, 'admin', 1)
|
||||
@@ -74,9 +74,9 @@ class UserModel:
|
||||
@staticmethod
|
||||
async def update_password(user_id: int, new_password: str) -> bool:
|
||||
"""更新密码"""
|
||||
password_hash = security.sha1_md5_password(new_password)
|
||||
password_hash = security.bcrypt_password(new_password)
|
||||
sql = """
|
||||
UPDATE users
|
||||
UPDATE users
|
||||
SET password_hash = %s, need_change_password = 0
|
||||
WHERE user_id = %s
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user