Merge branch 'main' into develop
# Conflicts: # backend/app/api/key_visits.py # backend/app/api/mini_business.py # backend/app/api/visits.py # backend/app/api/work_plans.py # backend/app/main.py # backend/app/models/__init__.py # backend/app/schemas/key_visit.py # backend/app/schemas/mini_business.py # backend/app/schemas/work_plan.py # backend/app/services/light_board.py # frontend/src/components/DesktopLayout.vue # frontend/src/stores/theme.ts # frontend/src/views/desktop/ManagerWorkspace.vue # frontend/src/views/desktop/WorkPlans.vue # frontend/src/views/mobile/KeyVisitForm.vue # frontend/src/views/mobile/LeaveForm.vue # frontend/src/views/mobile/PlansList.vue # frontend/src/views/mobile/VisitForm.vue # frontend/src/views/mobile/WorkPlanForm.vue
This commit is contained in:
@@ -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),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user