考勤记录扣分列显示实际扣分数

1. 新增/更新考勤扣分时记录关联的扣分记录ID(deduction_record_id)
2. 考勤记录查询关联扣分记录,返回扣分数与撤销状态;旧记录按考勤记录ID回查兜底
3. 前端扣分列显示"扣X分 / 扣X分(已撤销)",无扣分显示"-"
This commit is contained in:
canglan committed 2026-11-26 09:56:21 +08:00
1 parent 0ac933a3a5
commit a7304d151e
4 files changed
+38 -9

No files matched your search

+24 -4
View File
@@ -41,10 +41,21 @@ class AttendanceModel:
) -> List[Dict[str, Any]]:
sql = """
SELECT ar.*, s.name as student_name, s.student_no,
u.real_name as recorder_name
u.real_name as recorder_name,
COALESCE(cr.points_change, (
SELECT cr2.points_change FROM conduct_records cr2
WHERE cr2.related_type = 'attendance' AND cr2.related_id = ar.attendance_id
ORDER BY cr2.record_id DESC LIMIT 1
)) as deduction_points,
COALESCE(cr.is_revoked, (
SELECT cr3.is_revoked FROM conduct_records cr3
WHERE cr3.related_type = 'attendance' AND cr3.related_id = ar.attendance_id
ORDER BY cr3.record_id DESC LIMIT 1
)) as deduction_revoked
FROM attendance_records ar
JOIN students s ON ar.student_id = s.student_id
LEFT JOIN users u ON ar.recorder_id = u.user_id
LEFT JOIN conduct_records cr ON ar.deduction_record_id = cr.record_id
WHERE 1=1
"""
params = []
@@ -99,9 +110,18 @@ class AttendanceModel:
return await execute_insert(sql, (student_id, date, slot, status, reason, recorder_id, semester_id))
@staticmethod
async def mark_deduction_applied(attendance_id: int) -> bool:
sql = "UPDATE attendance_records SET deduction_applied = 1 WHERE attendance_id = %s"
result = await execute_update(sql, (attendance_id,))
async def mark_deduction_applied(attendance_id: int, deduction_record_id: int = None) -> bool:
"""标记考勤已扣分,并记录关联的扣分记录ID"""
if deduction_record_id:
sql = (
"UPDATE attendance_records "
"SET deduction_applied = 1, deduction_record_id = %s "
"WHERE attendance_id = %s"
)
result = await execute_update(sql, (deduction_record_id, attendance_id))
else:
sql = "UPDATE attendance_records SET deduction_applied = 1 WHERE attendance_id = %s"
result = await execute_update(sql, (attendance_id,))
return result > 0
@staticmethod
+3 -3
View File
@@ -127,7 +127,7 @@ class AttendanceService:
recorder_name = user.get("real_name", "班主任") if user else "班主任"
# 使用中文状态
status_text = ATTENDANCE_STATUS_MAP.get(status, status)
await ConductModel.create_record(
deduction_record_id = await ConductModel.create_record(
student_id=student_id,
points_change=points_change,
reason=f"考勤:{status_text}",
@@ -141,8 +141,8 @@ class AttendanceService:
# 更新学生总分
await StudentModel.update_total_points(student_id, points_change)
# 标记已应用扣分
await AttendanceModel.mark_deduction_applied(attendance_id)
# 标记已应用扣分(并记录扣分记录ID)
await AttendanceModel.mark_deduction_applied(attendance_id, deduction_record_id)
logger.info(f"用户[{recorder_id}] 添加考勤记录[{attendance_id}] -> {status}")
return {"success": True, "message": "考勤记录添加成功"}