v1.6版本更新
This commit is contained in:
@@ -41,18 +41,50 @@ class ConductModel:
|
||||
))
|
||||
|
||||
@staticmethod
|
||||
async def count_student_records(student_id: int, include_revoked: bool = False) -> int:
|
||||
async def count_student_records(
|
||||
student_id: int,
|
||||
include_revoked: bool = False,
|
||||
start_date: str = None,
|
||||
end_date: str = None,
|
||||
recorder_id: int = None
|
||||
) -> int:
|
||||
"""统计学生操行分记录总数"""
|
||||
revoked_condition = "" if include_revoked else " AND is_revoked = 0"
|
||||
sql = f"SELECT COUNT(*) as total FROM conduct_records WHERE student_id = %s{revoked_condition}"
|
||||
result = await execute_one(sql, (student_id,))
|
||||
conditions = ["student_id = %s"]
|
||||
params = [student_id]
|
||||
if not include_revoked:
|
||||
conditions.append("is_revoked = 0")
|
||||
if start_date:
|
||||
conditions.append("DATE(created_at) >= %s")
|
||||
params.append(start_date)
|
||||
if end_date:
|
||||
conditions.append("DATE(created_at) <= %s")
|
||||
params.append(end_date)
|
||||
if recorder_id:
|
||||
conditions.append("recorder_id = %s")
|
||||
params.append(recorder_id)
|
||||
where = " AND ".join(conditions)
|
||||
sql = f"SELECT COUNT(*) as total FROM conduct_records WHERE {where}"
|
||||
result = await execute_one(sql, tuple(params))
|
||||
return result["total"] if result else 0
|
||||
|
||||
@staticmethod
|
||||
async def count_records_by_recorder(recorder_id: int) -> int:
|
||||
async def count_records_by_recorder(
|
||||
recorder_id: int,
|
||||
start_date: str = None,
|
||||
end_date: str = None
|
||||
) -> int:
|
||||
"""统计记录人提交的操行分记录总数"""
|
||||
sql = "SELECT COUNT(*) as total FROM conduct_records WHERE recorder_id = %s"
|
||||
result = await execute_one(sql, (recorder_id,))
|
||||
conditions = ["recorder_id = %s"]
|
||||
params = [recorder_id]
|
||||
if start_date:
|
||||
conditions.append("DATE(created_at) >= %s")
|
||||
params.append(start_date)
|
||||
if end_date:
|
||||
conditions.append("DATE(created_at) <= %s")
|
||||
params.append(end_date)
|
||||
where = " AND ".join(conditions)
|
||||
sql = f"SELECT COUNT(*) as total FROM conduct_records WHERE {where}"
|
||||
result = await execute_one(sql, tuple(params))
|
||||
return result["total"] if result else 0
|
||||
|
||||
@staticmethod
|
||||
@@ -60,36 +92,65 @@ class ConductModel:
|
||||
student_id: int,
|
||||
limit: int = 50,
|
||||
offset: int = 0,
|
||||
include_revoked: bool = False
|
||||
include_revoked: bool = False,
|
||||
start_date: str = None,
|
||||
end_date: str = None,
|
||||
recorder_id: int = None
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""获取学生操行分记录"""
|
||||
sql = """
|
||||
conditions = ["cr.student_id = %s"]
|
||||
params = [student_id]
|
||||
if not include_revoked:
|
||||
conditions.append("cr.is_revoked = 0")
|
||||
if start_date:
|
||||
conditions.append("DATE(cr.created_at) >= %s")
|
||||
params.append(start_date)
|
||||
if end_date:
|
||||
conditions.append("DATE(cr.created_at) <= %s")
|
||||
params.append(end_date)
|
||||
if recorder_id:
|
||||
conditions.append("cr.recorder_id = %s")
|
||||
params.append(recorder_id)
|
||||
where = " AND ".join(conditions)
|
||||
sql = f"""
|
||||
SELECT cr.*, u.real_name as recorder_name
|
||||
FROM conduct_records cr
|
||||
LEFT JOIN users u ON cr.recorder_id = u.user_id
|
||||
WHERE cr.student_id = %s
|
||||
WHERE {where}
|
||||
ORDER BY cr.created_at DESC
|
||||
LIMIT %s OFFSET %s
|
||||
"""
|
||||
if not include_revoked:
|
||||
sql += " AND cr.is_revoked = 0"
|
||||
sql += " ORDER BY cr.created_at DESC LIMIT %s OFFSET %s"
|
||||
return await execute_query(sql, (student_id, limit, offset))
|
||||
params.extend([limit, offset])
|
||||
return await execute_query(sql, tuple(params))
|
||||
|
||||
@staticmethod
|
||||
async def get_records_by_recorder(
|
||||
recorder_id: int,
|
||||
limit: int = 50,
|
||||
offset: int = 0
|
||||
offset: int = 0,
|
||||
start_date: str = None,
|
||||
end_date: str = None
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""获取操作人提交的记录"""
|
||||
sql = """
|
||||
conditions = ["cr.recorder_id = %s", "cr.is_revoked = 0"]
|
||||
params = [recorder_id]
|
||||
if start_date:
|
||||
conditions.append("DATE(cr.created_at) >= %s")
|
||||
params.append(start_date)
|
||||
if end_date:
|
||||
conditions.append("DATE(cr.created_at) <= %s")
|
||||
params.append(end_date)
|
||||
where = " AND ".join(conditions)
|
||||
sql = f"""
|
||||
SELECT cr.*, s.name as student_name
|
||||
FROM conduct_records cr
|
||||
JOIN students s ON cr.student_id = s.student_id
|
||||
WHERE cr.recorder_id = %s AND cr.is_revoked = 0
|
||||
WHERE {where}
|
||||
ORDER BY cr.created_at DESC
|
||||
LIMIT %s OFFSET %s
|
||||
"""
|
||||
return await execute_query(sql, (recorder_id, limit, offset))
|
||||
params.extend([limit, offset])
|
||||
return await execute_query(sql, tuple(params))
|
||||
|
||||
@staticmethod
|
||||
async def get_all_records(
|
||||
|
||||
Reference in New Issue
Block a user