feat: scheduler skips on-leave managers; AI summary includes leave data

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2026-07-12 13:10:36 +08:00
parent 56adc625c0
commit eb05a0420e
2 changed files with 48 additions and 4 deletions
+27 -3
View File
@@ -1,9 +1,10 @@
from datetime import date, datetime
from sqlalchemy import select, func
from sqlalchemy import select, func, and_
from sqlalchemy.ext.asyncio import AsyncSession
from app.models.visit import Visit
from app.models.daily_note import DailyNote
from app.models.user import User
from app.models.leave import Leave
from app.models.work_plan import WorkPlan
from app.models.customer import Customer
from app.services.wecom import wecom_client
@@ -23,6 +24,15 @@ async def check_daily_reporting(db: AsyncSession) -> dict:
)
managers = result.scalars().all()
# ── Exclude managers on leave today ──
leaves_today = await db.execute(
select(Leave.manager_id).where(and_(
Leave.start_date <= today,
Leave.end_date >= today,
))
)
on_leave_ids = {str(uid) for uid, in leaves_today.all()}
# Get managers who have reported today
reported_visits = await db.execute(
select(Visit.manager_id).where(Visit.visit_date == today)
@@ -36,7 +46,11 @@ async def check_daily_reporting(db: AsyncSession) -> dict:
not_reported = []
reported_names = []
on_leave_names = []
for m in managers:
if str(m.id) in on_leave_ids:
on_leave_names.append(m.name)
continue # skip — exempt from reporting
if str(m.id) in reported_map:
reported_names.append(m.name)
else:
@@ -68,12 +82,22 @@ async def check_daily_reporting(db: AsyncSession) -> dict:
)
for d in directors.scalars().all():
if managers:
pct = len(reported_map) / len(managers) * 100
effective_total = len(managers) - len(on_leave_names)
if effective_total > 0:
pct = len(reported_map) / effective_total * 100
else:
pct = 100.0
leave_note = ""
if on_leave_names:
leave_note = f"\n> 请假中(已豁免):{len(on_leave_names)}\n"
leave_note += "".join(f"- {n} (请假)\n" for n in on_leave_names)
summary = (
f"## 📊 今日填报汇总\n\n"
f"> 日期:{today}\n"
f"> 填报率:**{pct:.0f}%** ({len(reported_map)}/{len(managers)})\n\n"
f"> 填报率:**{pct:.0f}%** ({len(reported_map)}/{effective_total})\n"
)
if leave_note:
summary += leave_note + "\n"
if not_reported:
summary += "**未填报:**\n" + "".join(f"- {m.name}\n" for m in not_reported)
else: