From d9dd7bf7e8df95ede912d0979f9e4d7bac4f4ddb Mon Sep 17 00:00:00 2001 From: Canglan Date: Thu, 26 Nov 2026 09:39:57 +0800 Subject: [PATCH] =?UTF-8?q?=E9=BB=98=E8=AE=A4=E5=87=BA=E5=8B=A4=E6=8C=89?= =?UTF-8?q?=E5=AD=A6=E6=A0=A1=E4=BD=9C=E6=81=AF=E7=94=9F=E6=88=90=EF=BC=9B?= =?UTF-8?q?=E6=96=B0=E5=A2=9E"=E8=AF=B7=E5=81=87(=E6=95=B4=E5=A4=A9)"?= =?UTF-8?q?=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 默认出勤:返校日仅生成晚修、放假前一天仅生成上午(中午离校,无下午/晚修)、其余上课日按所选时段;校历多取一天用于判断次日是否上课 2. 考勤页新增"请假(整天)":选中学生一键提交早/中/晚三条请假记录(各按请假扣分,配置1分时共3分/天) 3. 文档更新:请假(整天)用法与默认出勤作息规则 --- backend/services/attendance_service.py | 69 +++++++++++++++++++------ docs/teacher.md | 21 ++++++-- frontend/admin/attendance.php | 3 +- frontend/assets/js/attendance-manage.js | 60 +++++++++++++++++++++ 4 files changed, 130 insertions(+), 23 deletions(-) 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'; +
@@ -111,7 +112,7 @@ include __DIR__ . '/../includes/header.php'; 至
- 跳过周末与法定节假日(在线接口获取),调休补班与手动补课日照常;已有的考勤记录(含异常)不会被覆盖 + 按学校常规作息生成:返校日晚修、放假前一天仅上午(中午离校)、其余上课日按所选时段;跳过周末与法定节假日(调休补课日照常),已有记录不覆盖
diff --git a/frontend/assets/js/attendance-manage.js b/frontend/assets/js/attendance-manage.js index 833a25a..6a531e8 100644 --- a/frontend/assets/js/attendance-manage.js +++ b/frontend/assets/js/attendance-manage.js @@ -375,6 +375,65 @@ async function deleteCalendarDay(day) { } } +// ========== 请假(整天) ========== + +async function submitFullDayLeave() { + const selectedCells = document.querySelectorAll('.student-cell.selected'); + if (selectedCells.length === 0) { + showToast('请先选择请假的学生', 'warning'); + return; + } + const date = document.getElementById('attendanceDate').value; + if (!date) { + showToast('请选择日期', 'warning'); + return; + } + + // 整天请假 = 早/中/晚 三个时段,各按"请假"扣分 + const perDeduction = attendanceDeductionMap.leave || 0; + const totalPerStudent = perDeduction * 3; + const confirmText = perDeduction > 0 + ? '确定为选中的学生提交整天请假吗?(早/中/晚各扣' + perDeduction + '分,共' + totalPerStudent + '分/人)' + : '确定为选中的学生提交整天请假吗?(早/中/晚三个时段)'; + if (!confirm(confirmText)) return; + + const reason = document.getElementById('attendanceReason').value; + const slots = ['morning', 'afternoon', 'evening']; + const promises = []; + + selectedCells.forEach(cell => { + const studentId = parseInt(cell.dataset.id); + slots.forEach(slot => { + const payload = { + student_id: studentId, + date: date, + slot: slot, + status: 'leave', + reason: reason, + apply_deduction: true + }; + if (perDeduction > 0) { + payload.custom_deduction = perDeduction; + } + promises.push(apiPost('/api/admin/attendance', payload)); + }); + }); + + const results = await Promise.allSettled(promises); + const succeeded = results.filter(r => r.status === 'fulfilled' && r.value?.success).length; + const failed = results.length - succeeded; + + if (failed === 0) { + showToast(`整天请假提交成功(${succeeded}条` + (perDeduction > 0 ? `,${totalPerStudent}分/人` : '') + ')'); + } else { + showToast(`提交完成:成功${succeeded}条,失败${failed}条`, 'error'); + } + + deselectAllStudents(); + await loadExistingRecords(); + loadAttendanceRecords(); +} + // 页面初始化 initAttendanceButtons(); loadStudents(); @@ -389,6 +448,7 @@ window.submitAttendance = submitAttendance; window.loadAttendanceRecords = loadAttendanceRecords; window.openDefaultAttendanceModal = openDefaultAttendanceModal; window.submitDefaultAttendance = submitDefaultAttendance; +window.submitFullDayLeave = submitFullDayLeave; window.openCalendarModal = openCalendarModal; window.loadCalendar = loadCalendar; window.addCalendarDay = addCalendarDay;