默认出勤按学校作息生成;新增"请假(整天)"按钮
1. 默认出勤:返校日仅生成晚修、放假前一天仅生成上午(中午离校,无下午/晚修)、其余上课日按所选时段;校历多取一天用于判断次日是否上课 2. 考勤页新增"请假(整天)":选中学生一键提交早/中/晚三条请假记录(各按请假扣分,配置1分时共3分/天) 3. 文档更新:请假(整天)用法与默认出勤作息规则
This commit is contained in:
1 parent
928c86bd5a
commit
d9dd7bf7e8
4 files changed
+128
-21
No files matched your search
@@ -269,20 +269,49 @@ class AttendanceService:
|
|||||||
if not students:
|
if not students:
|
||||||
return {"success": False, "message": "暂无在读学生"}
|
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
|
rest_days = 0
|
||||||
cursor_day = start
|
cursor_day = start
|
||||||
while cursor_day <= end:
|
while cursor_day <= end:
|
||||||
if AttendanceService._is_school_day(cursor_day, calendar_info):
|
next_day = cursor_day + timedelta(days=1)
|
||||||
school_days.append(cursor_day)
|
school_today = AttendanceService._is_school_day(cursor_day, calendar_info)
|
||||||
|
school_next = AttendanceService._is_school_day(next_day, calendar_info)
|
||||||
|
|
||||||
|
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:
|
else:
|
||||||
rest_days += 1
|
rest_days += 1
|
||||||
cursor_day += timedelta(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 school_days:
|
if not day_slots:
|
||||||
return {"success": False, "message": "所选范围内没有上课日(全部为周末/节假日)"}
|
return {"success": False, "message": "所选范围内没有需要默认出勤的时段(均为休息日或未选对应时段)"}
|
||||||
|
|
||||||
from models.semester import SemesterModel
|
from models.semester import SemesterModel
|
||||||
active_semester = await SemesterModel.get_active()
|
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}
|
existing_set = {(r['student_id'], r['date'], r['slot']) for r in existing}
|
||||||
|
|
||||||
rows = []
|
rows = []
|
||||||
for school_day in school_days:
|
total_combos = 0
|
||||||
day_iso = school_day.isoformat()
|
for day, slots_today in day_slots:
|
||||||
|
day_iso = day.isoformat()
|
||||||
for student_id in student_ids:
|
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:
|
if (student_id, day_iso, slot) not in existing_set:
|
||||||
rows.append((student_id, day_iso, slot, recorder_id, semester_id))
|
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)
|
created = await AttendanceModel.bulk_create_present(rows)
|
||||||
skipped_existing = total_combos - len(rows)
|
skipped_existing = total_combos - len(rows)
|
||||||
|
|
||||||
|
summary = (
|
||||||
|
f"上课日{full_days + half_days}天(其中节前半日{half_days}天)、"
|
||||||
|
f"返校晚修{return_evenings}天,新增{created}条,跳过已有{skipped_existing}条"
|
||||||
|
)
|
||||||
logger.info(
|
logger.info(
|
||||||
f"用户[{recorder_id}] 批量默认出勤 {start_date}~{end_date} 时段{','.join(selected_slots)}: "
|
f"用户[{recorder_id}] 批量默认出勤 {start_date}~{end_date} 时段{','.join(selected_slots)}: {summary}"
|
||||||
f"上课日{len(school_days)}天,新增{created}条,跳过已有{skipped_existing}条"
|
|
||||||
)
|
)
|
||||||
return {
|
return {
|
||||||
"success": True,
|
"success": True,
|
||||||
"message": f"默认出勤完成:{len(school_days)}个上课日,新增{created}条,跳过已有{skipped_existing}条",
|
"message": f"默认出勤完成:{summary}",
|
||||||
"data": {
|
"data": {
|
||||||
"days": len(school_days),
|
"days": full_days + half_days,
|
||||||
|
"half_days": half_days,
|
||||||
|
"return_evenings": return_evenings,
|
||||||
"rest_days": rest_days,
|
"rest_days": rest_days,
|
||||||
"created": created,
|
"created": created,
|
||||||
"skipped_existing": skipped_existing,
|
"skipped_existing": skipped_existing,
|
||||||
|
|||||||
+16
-5
@@ -162,6 +162,15 @@
|
|||||||
6. 点击"全选"可快速选中所有未记录的学生
|
6. 点击"全选"可快速选中所有未记录的学生
|
||||||
7. 点击"提交考勤"批量提交
|
7. 点击"提交考勤"批量提交
|
||||||
|
|
||||||
|
#### 请假(整天)
|
||||||
|
用于"请一整天假"的常见情况,一键标记三个时段:
|
||||||
|
|
||||||
|
1. 在学生方格中**点击选择**请假的学生
|
||||||
|
2. 点击工具栏"请假(整天)"按钮
|
||||||
|
3. 确认后系统按 **早上 / 中午 / 晚修** 各提交一条请假记录(每个时段按"请假"扣分,若请假扣1分则一天共3分)
|
||||||
|
|
||||||
|
> 已有的对应时段记录会被更新为请假;如需只标记某个时段,仍用普通"请假"按钮 + 时段选择。
|
||||||
|
|
||||||
#### 查看考勤记录
|
#### 查看考勤记录
|
||||||
- 按日期筛选考勤记录
|
- 按日期筛选考勤记录
|
||||||
- 每条记录显示:学号、姓名、状态、原因、记录人、扣分情况
|
- 每条记录显示:学号、姓名、状态、原因、记录人、扣分情况
|
||||||
@@ -171,12 +180,14 @@
|
|||||||
|
|
||||||
1. 点击工具栏"默认出勤"按钮
|
1. 点击工具栏"默认出勤"按钮
|
||||||
2. 选择**日期范围**(默认本月1日至今)与**时段**(默认全选早/中/晚)
|
2. 选择**日期范围**(默认本月1日至今)与**时段**(默认全选早/中/晚)
|
||||||
3. 点击"开始补全",完成后提示:上课日数量、新增条数、跳过已有条数
|
3. 点击"开始补全",完成后提示:上课日/节前半日/返校晚修数量、新增条数、跳过已有条数
|
||||||
|
|
||||||
规则说明:
|
作息规则(常规情况):
|
||||||
|
- **返校日**(非上课日、次日上课,如周日)→ 仅生成**晚修**出勤
|
||||||
|
- **上课日且次日仍上课** → 按所选时段生成(早/中/晚)
|
||||||
|
- **放假前一天**(上课日、次日不上课)→ 仅生成**上午**出勤(中午离校,无下午/晚修)
|
||||||
- **跳过周末与法定节假日**(节假日/调休补班来自国内在线接口,失败时自动切换备用接口)
|
- **跳过周末与法定节假日**(节假日/调休补班来自国内在线接口,失败时自动切换备用接口)
|
||||||
- **调休补班日照常**(接口中的补班日按上课处理)
|
- **调休补班日照常**(接口中的补班日按上课处理);**手动补课日照常**、手动放假日跳过
|
||||||
- **手动补课日照常**;手动放假日跳过
|
|
||||||
- 已有的考勤记录(含缺勤/迟到/请假)**不会被覆盖**
|
- 已有的考勤记录(含缺勤/迟到/请假)**不会被覆盖**
|
||||||
- 单次最长支持 180 天;接口暂时不可用时会提示,本次仅按周末与手动设置判断
|
- 单次最长支持 180 天;接口暂时不可用时会提示,本次仅按周末与手动设置判断
|
||||||
|
|
||||||
@@ -193,7 +204,7 @@
|
|||||||
|---------|---------|
|
|---------|---------|
|
||||||
| 缺勤 | 3分 |
|
| 缺勤 | 3分 |
|
||||||
| 迟到 | 1分 |
|
| 迟到 | 1分 |
|
||||||
| 请假 | 0分 |
|
| 请假 | 按系统配置(如配置为1分,整天请假=3分) |
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ include __DIR__ . '/../includes/header.php';
|
|||||||
<?php if (has_perm('manage_calendar')): ?>
|
<?php if (has_perm('manage_calendar')): ?>
|
||||||
<button class="btn btn-ghost" onclick="openCalendarModal()">节假日/补课</button>
|
<button class="btn btn-ghost" onclick="openCalendarModal()">节假日/补课</button>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
<button class="btn btn-secondary" onclick="submitFullDayLeave()">请假(整天)</button>
|
||||||
<button class="btn btn-danger" onclick="submitAttendance()">提交考勤</button>
|
<button class="btn btn-danger" onclick="submitAttendance()">提交考勤</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="attendance-toolbar">
|
<div class="attendance-toolbar">
|
||||||
@@ -111,7 +112,7 @@ include __DIR__ . '/../includes/header.php';
|
|||||||
<span style="color:#999;">至</span>
|
<span style="color:#999;">至</span>
|
||||||
<input type="date" id="defaultEndDate" style="width:auto;">
|
<input type="date" id="defaultEndDate" style="width:auto;">
|
||||||
</div>
|
</div>
|
||||||
<small>跳过周末与法定节假日(在线接口获取),调休补班与手动补课日照常;已有的考勤记录(含异常)不会被覆盖</small>
|
<small>按学校常规作息生成:返校日晚修、放假前一天仅上午(中午离校)、其余上课日按所选时段;跳过周末与法定节假日(调休补课日照常),已有记录不覆盖</small>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label>时段</label>
|
<label>时段</label>
|
||||||
|
|||||||
@@ -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();
|
initAttendanceButtons();
|
||||||
loadStudents();
|
loadStudents();
|
||||||
@@ -389,6 +448,7 @@ window.submitAttendance = submitAttendance;
|
|||||||
window.loadAttendanceRecords = loadAttendanceRecords;
|
window.loadAttendanceRecords = loadAttendanceRecords;
|
||||||
window.openDefaultAttendanceModal = openDefaultAttendanceModal;
|
window.openDefaultAttendanceModal = openDefaultAttendanceModal;
|
||||||
window.submitDefaultAttendance = submitDefaultAttendance;
|
window.submitDefaultAttendance = submitDefaultAttendance;
|
||||||
|
window.submitFullDayLeave = submitFullDayLeave;
|
||||||
window.openCalendarModal = openCalendarModal;
|
window.openCalendarModal = openCalendarModal;
|
||||||
window.loadCalendar = loadCalendar;
|
window.loadCalendar = loadCalendar;
|
||||||
window.addCalendarDay = addCalendarDay;
|
window.addCalendarDay = addCalendarDay;
|
||||||
|
|||||||
Reference in new issue
Block a user