同步招生就业服务队新版值班表
This commit is contained in:
+15
-3
@@ -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")
|
||||
|
||||
+2
-1
@@ -1542,7 +1542,8 @@ async def remind_duty(payload: DutyRemindIn, viewer: dict = Depends(current_user
|
||||
email = next(iter(recipients))
|
||||
start = datetime.fromtimestamp(shift["start_at"] / 1000, BEIJING)
|
||||
try:
|
||||
sent = await duty_receipts.send_notice(_duty_state(), start.date().isoformat(), {payload.name: [shift["slot"]]}, email, shift["end_at"] / 1000, _send_email, "值班提醒", f"日期:{start:%Y-%m-%d},{start:%H:%M} 开始(北京时间)", _site_base_url())
|
||||
duty_title = data.get("title", "值班提醒")
|
||||
sent = await duty_receipts.send_notice(_duty_state(), start.date().isoformat(), {payload.name: [shift["slot"]]}, email, shift["end_at"] / 1000, _send_email, f"{duty_title}|邮件提醒", f"机构:{data.get('organization', '招生就业服务队')}\n日期:{start:%Y-%m-%d},{start:%H:%M} 开始(北京时间)", _site_base_url())
|
||||
except HTTPException:
|
||||
raise
|
||||
if not sent:
|
||||
|
||||
Reference in New Issue
Block a user