diff --git a/backend/services/attendance_service.py b/backend/services/attendance_service.py index ea54aa9..26efd8b 100644 --- a/backend/services/attendance_service.py +++ b/backend/services/attendance_service.py @@ -269,20 +269,49 @@ class AttendanceService: if not students: return {"success": False, "message": "暂无在读学生"} - calendar_info = await AttendanceService.get_calendar(start_date, end_date) + # 校历多取一天,用于判断"次日是否上课"(决定节前半日/返校晚修) + calendar_info = await AttendanceService.get_calendar( + start_date, (end + timedelta(days=1)).isoformat() + ) - school_days = [] + # 常规作息: + # 返校日(非上课日、次日上课)→ 仅晚修 + # 上课日且次日仍上课 → 按所选时段(早/中/晚) + # 上课日且次日不上课(放假前一天)→ 仅上午(中午走人,无下午/晚修) + day_slots = [] + full_days = 0 + half_days = 0 + return_evenings = 0 rest_days = 0 cursor_day = start while cursor_day <= end: - if AttendanceService._is_school_day(cursor_day, calendar_info): - school_days.append(cursor_day) - else: - rest_days += 1 - cursor_day += timedelta(days=1) + next_day = cursor_day + timedelta(days=1) + school_today = AttendanceService._is_school_day(cursor_day, calendar_info) + school_next = AttendanceService._is_school_day(next_day, calendar_info) - if not school_days: - return {"success": False, "message": "所选范围内没有上课日(全部为周末/节假日)"} + if school_today: + if school_next: + slots_today = list(selected_slots) + full_days += 1 + else: + slots_today = [s for s in selected_slots if s == 'morning'] + if slots_today: + half_days += 1 + else: + rest_days += 1 + if slots_today: + day_slots.append((cursor_day, slots_today)) + else: + slots_today = [s for s in selected_slots if s == 'evening'] if school_next else [] + if slots_today: + return_evenings += 1 + day_slots.append((cursor_day, slots_today)) + else: + rest_days += 1 + cursor_day = next_day + + if not day_slots: + return {"success": False, "message": "所选范围内没有需要默认出勤的时段(均为休息日或未选对应时段)"} from models.semester import SemesterModel active_semester = await SemesterModel.get_active() @@ -293,26 +322,32 @@ class AttendanceService: existing_set = {(r['student_id'], r['date'], r['slot']) for r in existing} rows = [] - for school_day in school_days: - day_iso = school_day.isoformat() + total_combos = 0 + for day, slots_today in day_slots: + day_iso = day.isoformat() for student_id in student_ids: - for slot in selected_slots: + total_combos += len(slots_today) + for slot in slots_today: if (student_id, day_iso, slot) not in existing_set: rows.append((student_id, day_iso, slot, recorder_id, semester_id)) - total_combos = len(student_ids) * len(school_days) * len(selected_slots) created = await AttendanceModel.bulk_create_present(rows) skipped_existing = total_combos - len(rows) + summary = ( + f"上课日{full_days + half_days}天(其中节前半日{half_days}天)、" + f"返校晚修{return_evenings}天,新增{created}条,跳过已有{skipped_existing}条" + ) logger.info( - f"用户[{recorder_id}] 批量默认出勤 {start_date}~{end_date} 时段{','.join(selected_slots)}: " - f"上课日{len(school_days)}天,新增{created}条,跳过已有{skipped_existing}条" + f"用户[{recorder_id}] 批量默认出勤 {start_date}~{end_date} 时段{','.join(selected_slots)}: {summary}" ) return { "success": True, - "message": f"默认出勤完成:{len(school_days)}个上课日,新增{created}条,跳过已有{skipped_existing}条", + "message": f"默认出勤完成:{summary}", "data": { - "days": len(school_days), + "days": full_days + half_days, + "half_days": half_days, + "return_evenings": return_evenings, "rest_days": rest_days, "created": created, "skipped_existing": skipped_existing, diff --git a/docs/teacher.md b/docs/teacher.md index ccf4cc6..26884e4 100644 --- a/docs/teacher.md +++ b/docs/teacher.md @@ -162,6 +162,15 @@ 6. 点击"全选"可快速选中所有未记录的学生 7. 点击"提交考勤"批量提交 +#### 请假(整天) +用于"请一整天假"的常见情况,一键标记三个时段: + +1. 在学生方格中**点击选择**请假的学生 +2. 点击工具栏"请假(整天)"按钮 +3. 确认后系统按 **早上 / 中午 / 晚修** 各提交一条请假记录(每个时段按"请假"扣分,若请假扣1分则一天共3分) + +> 已有的对应时段记录会被更新为请假;如需只标记某个时段,仍用普通"请假"按钮 + 时段选择。 + #### 查看考勤记录 - 按日期筛选考勤记录 - 每条记录显示:学号、姓名、状态、原因、记录人、扣分情况 @@ -171,12 +180,14 @@ 1. 点击工具栏"默认出勤"按钮 2. 选择**日期范围**(默认本月1日至今)与**时段**(默认全选早/中/晚) -3. 点击"开始补全",完成后提示:上课日数量、新增条数、跳过已有条数 +3. 点击"开始补全",完成后提示:上课日/节前半日/返校晚修数量、新增条数、跳过已有条数 -规则说明: +作息规则(常规情况): +- **返校日**(非上课日、次日上课,如周日)→ 仅生成**晚修**出勤 +- **上课日且次日仍上课** → 按所选时段生成(早/中/晚) +- **放假前一天**(上课日、次日不上课)→ 仅生成**上午**出勤(中午离校,无下午/晚修) - **跳过周末与法定节假日**(节假日/调休补班来自国内在线接口,失败时自动切换备用接口) -- **调休补班日照常**(接口中的补班日按上课处理) -- **手动补课日照常**;手动放假日跳过 +- **调休补班日照常**(接口中的补班日按上课处理);**手动补课日照常**、手动放假日跳过 - 已有的考勤记录(含缺勤/迟到/请假)**不会被覆盖** - 单次最长支持 180 天;接口暂时不可用时会提示,本次仅按周末与手动设置判断 @@ -193,7 +204,7 @@ |---------|---------| | 缺勤 | 3分 | | 迟到 | 1分 | -| 请假 | 0分 | +| 请假 | 按系统配置(如配置为1分,整天请假=3分) | --- diff --git a/frontend/admin/attendance.php b/frontend/admin/attendance.php index 9ff1ba1..31d38db 100644 --- a/frontend/admin/attendance.php +++ b/frontend/admin/attendance.php @@ -53,6 +53,7 @@ include __DIR__ . '/../includes/header.php'; +
- 跳过周末与法定节假日(在线接口获取),调休补班与手动补课日照常;已有的考勤记录(含异常)不会被覆盖 + 按学校常规作息生成:返校日晚修、放假前一天仅上午(中午离校)、其余上课日按所选时段;跳过周末与法定节假日(调休补课日照常),已有记录不覆盖