同步招生就业服务队新版值班表

This commit is contained in:
2026-11-19 09:39:40 +08:00
parent 215718e597
commit 7520949b3b
13 changed files with 163 additions and 147 deletions
+15 -3
View File
@@ -21,6 +21,9 @@ def load_schedule(path):
data = json.loads(Path(path).read_text(encoding="utf-8-sig"))
if data.get("version") != 1 or type(data.get("enabled")) is not bool:
raise ValueError("值班表版本或开关无效")
for key in ("title", "organization"):
if key in data and (not isinstance(data[key], str) or not data[key].strip()):
raise ValueError(f"{key} 不能为空")
date.fromisoformat(data["anchor_date"])
if data["anchor_week"] not in ("odd", "even"):
raise ValueError("anchor_week 必须为 odd 或 even")
@@ -94,7 +97,14 @@ def resolve_recipients(assignments, accounts, overrides=None):
def duty_status(schedule, now):
"""活动墙只返回排班姓名和时间,不暴露邮箱等联系方式。"""
now = now.astimezone(BEIJING)
result = {"server_now": int(now.timestamp() * 1000), "enabled": schedule["enabled"], "current": None, "next": None}
result = {
"server_now": int(now.timestamp() * 1000),
"enabled": schedule["enabled"],
"title": schedule.get("title", "值班安排"),
"organization": schedule.get("organization", ""),
"current": None,
"next": None,
}
if not schedule["enabled"]:
return result
anchor = date.fromisoformat(schedule["anchor_date"])
@@ -183,9 +193,11 @@ async def send_due(schedule, now, accounts, send_email, state_path, overrides=No
clocks = schedule.get("slot_times", {})
slots = {slot for items in names.values() for slot in items}
ends = [datetime.combine(target, datetime.strptime(clocks[slot], "%H:%M").time(), BEIJING) + timedelta(minutes=schedule.get("duration_minutes", 105)) for slot in slots]
body = f"日期:{target.isoformat()}(周{'一二三四五六日'[target.weekday()]},{'单' if week == 'odd' else '双'}周)\n" + "、".join(f"{slot} {clocks[slot]} 开始" for slot in sorted(slots)) + "\n以上时间均为北京时间。请准时值班。"
organization = schedule.get("organization", "招生就业服务队")
body = f"机构:{organization}\n日期:{target.isoformat()}(周{'一二三四五六日'[target.weekday()]},{'单' if week == 'odd' else '双'}周)\n" + "、".join(f"{slot} {clocks[slot]} 开始" for slot in sorted(slots)) + "\n以上时间均为北京时间。请准时值班。"
subject = f"{schedule.get('title', organization + '值班')}|{label}|{target.isoformat()}"
try:
sent = await send_notice(state_path, target.isoformat(), names, email, max(ends).timestamp(), send_email, f"{label}|{target.isoformat()}", body, base_url, now.timestamp())
sent = await send_notice(state_path, target.isoformat(), names, email, max(ends).timestamp(), send_email, subject, body, base_url, now.timestamp())
except Exception:
result["failed"] += 1
await asyncio.to_thread(finish, state_path, key, email, "failed")