diff --git a/backend/services/attendance_service.py b/backend/services/attendance_service.py index 4099047..a983438 100644 --- a/backend/services/attendance_service.py +++ b/backend/services/attendance_service.py @@ -75,10 +75,15 @@ class AttendanceService: points_change = -settings.DEDUCTION_ATTENDANCE_LATE else: points_change = -settings.DEDUCTION_ATTENDANCE_LEAVE - # 创建扣分记录 student = await StudentModel.get_by_id(student_id) if student: + # 检查分数是否会超出范围(防止溢出) + current_points = student.get("total_points", 0) + new_points = current_points + points_change + if new_points < 0: + return {"success": False, "message": f"分数不能为负(当前{current_points},扣{abs(points_change)})"} + # 获取操作人姓名 user = await UserModel.get_by_user_id(recorder_id) recorder_name = user.get("real_name", "班主任") if user else "班主任" @@ -99,6 +104,7 @@ class AttendanceService: # 标记已应用扣分 await AttendanceModel.mark_deduction_applied(attendance_id) + await AttendanceModel.mark_deduction_applied(attendance_id) logger.info(f"用户[{recorder_id}] 添加考勤记录[{attendance_id}] -> {status}") diff --git a/backend/services/conduct_service.py b/backend/services/conduct_service.py index 3fddf9d..2201d24 100644 --- a/backend/services/conduct_service.py +++ b/backend/services/conduct_service.py @@ -80,6 +80,18 @@ class ConductService: fail_count += 1 continue + # 检查分数是否会超出范围(防止溢出) + current_points = student.get("total_points", 0) + new_points = current_points + points_change + if new_points < 0: + details.append({"student_id": student_id, "error": f"分数不能为负(当前{current_points},操作{points_change})"}) + fail_count += 1 + continue + if new_points > 100: + details.append({"student_id": student_id, "error": f"分数不能超过100(当前{current_points},操作{points_change})"}) + fail_count += 1 + continue + # 创建记录 record_id = await ConductModel.create_record( student_id=student_id, @@ -102,7 +114,7 @@ class ConductService: fail_count += 1 return { - "success": True, + "success": fail_count == 0, "success_count": success_count, "fail_count": fail_count, "details": details diff --git a/frontend/admin/conduct.php b/frontend/admin/conduct.php index b257704..7c26be5 100644 --- a/frontend/admin/conduct.php +++ b/frontend/admin/conduct.php @@ -35,6 +35,9 @@ include __DIR__ . '/../includes/header.php';
+ + +
@@ -93,6 +96,55 @@ function showSinglePointsModal(studentId, studentName) { document.getElementById('batchPointsModal').style.display = 'flex'; } +// 导出操行分记录 +async function exportConductRecords() { + const startDate = prompt('请输入开始日期(格式:YYYY-MM-DD,留空则不限):', ''); + if (startDate === null) return; + const endDate = prompt('请输入结束日期(格式:YYYY-MM-DD,留空则不限):', ''); + if (endDate === null) return; + + showToast('正在导出...', 'info'); + + try { + const params = { page: 1, page_size: 10000 }; + if (startDate) params.start_date = startDate; + if (endDate) params.end_date = endDate; + + const res = await apiGet('/api/admin/conduct/history', params); + if (res && res.success && res.data.records) { + const records = res.data.records; + if (records.length === 0) { + showToast('没有找到记录', 'warning'); + return; + } + + // 构建CSV内容 + let csv = '\uFEFF'; // BOM for UTF-8 + csv += '时间,学号,姓名,分数变动,原因,操作人\n'; + records.forEach(r => { + csv += `${r.created_at || ''},${r.student_no || ''},${r.student_name || ''},${r.points_change > 0 ? '+' : ''}${r.points_change},${(r.reason || '').replace(/,/g, ';')},${r.recorder_name || ''}\n`; + }); + + // 下载文件 + const blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' }); + const url = URL.createObjectURL(blob); + const link = document.createElement('a'); + link.href = url; + link.download = `操行分记录_${new Date().toISOString().slice(0,10)}.csv`; + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + URL.revokeObjectURL(url); + + showToast(`导出成功,共${records.length}条记录`); + } else { + showToast('导出失败:' + (res?.message || '未知错误'), 'error'); + } + } catch (err) { + showToast('导出失败:' + err.message, 'error'); + } +} + loadStudents(); diff --git a/frontend/admin/dashboard.php b/frontend/admin/dashboard.php index ddd6ee7..ac62e7e 100644 --- a/frontend/admin/dashboard.php +++ b/frontend/admin/dashboard.php @@ -63,6 +63,7 @@ async function loadDashboard() { } if ('' === '班主任') { quickActions += ''; + quickActions += ''; } document.getElementById('quickActions').innerHTML = quickActions || '

暂无快捷操作

';