feat: 工作计划状态自动流转

- 抽取 auto_complete_work_plans() 可复用函数到 visits service
- POST/PUT 拜访均触发自动完成(更新场景解决补录问题)
- Excel 导入旧周报时也触发自动完成
- 逾期计划自动取消:plan_date < today 且无匹配拜访→已取消
- edit_log 记录区分三种来源:拜访自动完成/拜访更新自动完成/旧周报导入自动完成/逾期自动取消

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2026-07-12 16:21:38 +08:00
parent c38a9e74ad
commit efc200b6de
4 changed files with 84 additions and 10 deletions
+24
View File
@@ -168,9 +168,33 @@ async def check_overdue_plans(db: AsyncSession) -> dict:
await wecom_client.send_text_message([user.wecom_userid], content)
# ── Auto-cancel overdue plans that have no matching visit ──
from app.utils.edit_log import append_entry as append_edit_log
auto_cancelled = 0
for plan in overdue:
has_visit = await db.execute(
select(Visit).where(
Visit.customer_id == plan.customer_id,
Visit.visit_date >= plan.plan_date,
)
)
if not has_visit.scalar():
plan.status = "已取消"
append_edit_log(plan, "系统", [{
"field": "status",
"from": "计划中",
"to": "已取消",
"reason": "逾期自动取消",
}])
auto_cancelled += 1
if auto_cancelled:
await db.commit()
return {
"status": "ok",
"date": str(today),
"overdue": len(overdue),
"auto_cancelled": auto_cancelled,
"managers_affected": len(by_manager),
}