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

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
+36 -7

No files matched your search

+22 -2
View File
@@ -41,10 +41,21 @@ class AttendanceModel:
) -> List[Dict[str, Any]]: ) -> List[Dict[str, Any]]:
sql = """ sql = """
SELECT ar.*, s.name as student_name, s.student_no, 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 FROM attendance_records ar
JOIN students s ON ar.student_id = s.student_id JOIN students s ON ar.student_id = s.student_id
LEFT JOIN users u ON ar.recorder_id = u.user_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 WHERE 1=1
""" """
params = [] params = []
@@ -99,7 +110,16 @@ class AttendanceModel:
return await execute_insert(sql, (student_id, date, slot, status, reason, recorder_id, semester_id)) return await execute_insert(sql, (student_id, date, slot, status, reason, recorder_id, semester_id))
@staticmethod @staticmethod
async def mark_deduction_applied(attendance_id: int) -> bool: 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" sql = "UPDATE attendance_records SET deduction_applied = 1 WHERE attendance_id = %s"
result = await execute_update(sql, (attendance_id,)) result = await execute_update(sql, (attendance_id,))
return result > 0 return result > 0
+3 -3
View File
@@ -127,7 +127,7 @@ class AttendanceService:
recorder_name = user.get("real_name", "班主任") if user else "班主任" recorder_name = user.get("real_name", "班主任") if user else "班主任"
# 使用中文状态 # 使用中文状态
status_text = ATTENDANCE_STATUS_MAP.get(status, status) status_text = ATTENDANCE_STATUS_MAP.get(status, status)
await ConductModel.create_record( deduction_record_id = await ConductModel.create_record(
student_id=student_id, student_id=student_id,
points_change=points_change, points_change=points_change,
reason=f"考勤:{status_text}", reason=f"考勤:{status_text}",
@@ -141,8 +141,8 @@ class AttendanceService:
# 更新学生总分 # 更新学生总分
await StudentModel.update_total_points(student_id, points_change) await StudentModel.update_total_points(student_id, points_change)
# 标记已应用扣分 # 标记已应用扣分(并记录扣分记录ID)
await AttendanceModel.mark_deduction_applied(attendance_id) await AttendanceModel.mark_deduction_applied(attendance_id, deduction_record_id)
logger.info(f"用户[{recorder_id}] 添加考勤记录[{attendance_id}] -> {status}") logger.info(f"用户[{recorder_id}] 添加考勤记录[{attendance_id}] -> {status}")
return {"success": True, "message": "考勤记录添加成功"} return {"success": True, "message": "考勤记录添加成功"}
+1 -1
View File
@@ -176,7 +176,7 @@
#### 查看考勤记录 #### 查看考勤记录
- 按日期筛选考勤记录 - 按日期筛选考勤记录
- 每条记录显示:学号、姓名、状态、原因、记录人、扣分情况 - 每条记录显示:学号、姓名、状态、原因、记录人、扣分金额(如"扣3分",已撤销的注明)
#### 默认出勤(批量补全) #### 默认出勤(批量补全)
用于给一段时间内没有异常的学生批量补"出勤"记录,让统计报表的出勤率有意义。 用于给一段时间内没有异常的学生批量补"出勤"记录,让统计报表的出勤率有意义。
+10 -1
View File
@@ -165,13 +165,22 @@ async function loadAttendanceRecords() {
let html = ''; let html = '';
const records = res.data.records || []; const records = res.data.records || [];
records.forEach(record => { records.forEach(record => {
let deductionText = '-';
if (record.deduction_points) {
deductionText = '扣' + Math.abs(record.deduction_points) + '分';
if (record.deduction_revoked) {
deductionText += '(已撤销)';
}
} else if (record.deduction_applied) {
deductionText = '已扣分';
}
html += `<tr> html += `<tr>
<td>${escapeHtml(record.student_no)}</td> <td>${escapeHtml(record.student_no)}</td>
<td>${escapeHtml(record.student_name)}</td> <td>${escapeHtml(record.student_name)}</td>
<td>${getStatusBadge(record.status, 'attendance')}</td> <td>${getStatusBadge(record.status, 'attendance')}</td>
<td>${escapeHtml(record.reason || '-')}</td> <td>${escapeHtml(record.reason || '-')}</td>
<td>${escapeHtml(record.recorder_name || '-')}</td> <td>${escapeHtml(record.recorder_name || '-')}</td>
<td>${record.deduction_applied ? '已扣分' : '-'}</td> <td>${deductionText}</td>
</tr>`; </tr>`;
}); });
if (records.length === 0) { if (records.length === 0) {