默认出勤按学校作息生成;新增"请假(整天)"按钮

1. 默认出勤:返校日仅生成晚修、放假前一天仅生成上午(中午离校,无下午/晚修)、其余上课日按所选时段;校历多取一天用于判断次日是否上课
2. 考勤页新增"请假(整天)":选中学生一键提交早/中/晚三条请假记录(各按请假扣分,配置1分时共3分/天)
3. 文档更新:请假(整天)用法与默认出勤作息规则
This commit is contained in:
canglan committed 2026-11-26 09:39:57 +08:00
1 parent 928c86bd5a
commit d9dd7bf7e8
4 files changed
+130 -23

No files matched your search

+52 -17
View File
@@ -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,