feat: 增加学生信息管理功能,优化操行分历史记录展示并更新使用文档
This commit is contained in:
@@ -81,7 +81,8 @@ class ConductModel:
|
||||
limit: int = 100,
|
||||
offset: int = 0,
|
||||
start_date: str = None,
|
||||
end_date: str = None
|
||||
end_date: str = None,
|
||||
student_id: int = None
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""获取所有记录(班主任/班长专用)"""
|
||||
# 空字符串转为None
|
||||
@@ -99,7 +100,9 @@ class ConductModel:
|
||||
"""
|
||||
params = []
|
||||
|
||||
# 单班级系统,无需 class_id 过滤
|
||||
if student_id:
|
||||
sql += " AND cr.student_id = %s"
|
||||
params.append(student_id)
|
||||
|
||||
if start_date:
|
||||
sql += " AND DATE(cr.created_at) >= %s"
|
||||
@@ -114,6 +117,73 @@ class ConductModel:
|
||||
|
||||
return await execute_query(sql, tuple(params))
|
||||
|
||||
@staticmethod
|
||||
async def get_grouped_records(
|
||||
student_id: int = None,
|
||||
start_date: str = None,
|
||||
end_date: str = None,
|
||||
page: int = 1,
|
||||
page_size: int = 20
|
||||
) -> Dict[str, Any]:
|
||||
"""获取分组后的操行分记录(同批次合并)"""
|
||||
if start_date == "":
|
||||
start_date = None
|
||||
if end_date == "":
|
||||
end_date = None
|
||||
|
||||
conditions = ["cr.is_revoked = 0"]
|
||||
params = []
|
||||
|
||||
if student_id:
|
||||
conditions.append("cr.student_id = %s")
|
||||
params.append(student_id)
|
||||
if start_date:
|
||||
conditions.append("cr.created_at >= %s")
|
||||
params.append(start_date)
|
||||
if end_date:
|
||||
conditions.append("cr.created_at <= %s")
|
||||
params.append(end_date + ' 23:59:59')
|
||||
|
||||
where_clause = " AND ".join(conditions)
|
||||
|
||||
count_sql = f"""
|
||||
SELECT COUNT(DISTINCT CONCAT(cr.points_change, '|', cr.reason, '|', cr.recorder_id, '|', DATE_FORMAT(cr.created_at, '%Y-%m-%d %H:%i'))) as total
|
||||
FROM conduct_records cr
|
||||
WHERE {where_clause}
|
||||
"""
|
||||
|
||||
data_sql = f"""
|
||||
SELECT
|
||||
cr.points_change,
|
||||
cr.reason,
|
||||
cr.recorder_name,
|
||||
DATE_FORMAT(MIN(cr.created_at), '%Y-%m-%d %H:%i:%s') as created_at,
|
||||
GROUP_CONCAT(s.name ORDER BY s.student_id SEPARATOR ', ') as student_names,
|
||||
COUNT(*) as student_count
|
||||
FROM conduct_records cr
|
||||
JOIN students s ON cr.student_id = s.student_id
|
||||
WHERE {where_clause}
|
||||
GROUP BY cr.points_change, cr.reason, cr.recorder_id, DATE_FORMAT(cr.created_at, '%Y-%m-%d %H:%i')
|
||||
ORDER BY MIN(cr.created_at) DESC
|
||||
LIMIT %s OFFSET %s
|
||||
"""
|
||||
|
||||
params_for_count = list(params)
|
||||
params_for_data = list(params) + [page_size, (page - 1) * page_size]
|
||||
|
||||
total_result = await execute_one(count_sql, tuple(params_for_count))
|
||||
total = total_result['total'] if total_result else 0
|
||||
|
||||
records = await execute_query(data_sql, tuple(params_for_data))
|
||||
|
||||
return {
|
||||
"records": records,
|
||||
"total": total,
|
||||
"page": page,
|
||||
"page_size": page_size,
|
||||
"total_pages": (total + page_size - 1) // page_size
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
async def get_record_by_id(record_id: int) -> Optional[Dict[str, Any]]:
|
||||
"""根据ID获取记录"""
|
||||
|
||||
Reference in New Issue
Block a user