修复加减分失败但计入记录和添加导出功能
This commit is contained in:
@@ -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}")
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user