feat(scheduler): 新增多种报表推送功能并重构调度器代码

- 新增考勤汇总、风险进度、工作日报、工作周报等报表推送功能
- 重构调度器中的报表推送逻辑,提取通用的 deliver_report 函数
- 添加新的定时任务配置项用于各种报表推送
- 实现飞书推送配置检查函数 _feishu_delivery_configured
- 将重复的报表推送代码抽取为可复用的函数模式
```
This commit is contained in:
2026-07-13 09:47:29 +08:00
parent f8020cab56
commit 267b01b9f4
12 changed files with 722 additions and 191 deletions

View File

@@ -1,46 +1,102 @@
from collections.abc import Callable
from typing import Any
from app.core.background.task_queue.constants import (
TASK_PUSH_ATTENDANCE_SUMMARY,
TASK_PUSH_DAILY_BRIEF,
TASK_PUSH_PROJECT_WEEKLY,
TASK_PUSH_RISK_PROGRESS,
TASK_PUSH_WORK_DAILY,
TASK_PUSH_WORK_WEEKLY,
)
from app.core.constants import ActorValue
from app.core.database import SessionLocal
from app.modules.feishu.constants import FeishuReceiveIdType
from app.tasks.app import celery_app
ReportBuilder = Callable[[Any, str], dict[str, Any]]
@celery_app.task(name="reports.push_daily_brief")
@celery_app.task(name=TASK_PUSH_DAILY_BRIEF)
def push_daily_brief(
receive_id: str | None = None,
receive_id_type: str = FeishuReceiveIdType.CHAT_ID,
actor: str = ActorValue.SCHEDULER,
push_run_code: str | None = None,
) -> dict[str, Any]:
from app.modules.reports.services import ReportService
return _push_report(_build_daily_brief, receive_id, receive_id_type, actor, push_run_code)
db = SessionLocal()
try:
report = ReportService(db).daily_brief()
return ReportService(db).push_report(
report,
receive_id,
receive_id_type,
actor,
push_run_code=push_run_code,
)
finally:
db.close()
@celery_app.task(name="reports.push_project_weekly")
@celery_app.task(name=TASK_PUSH_PROJECT_WEEKLY)
def push_project_weekly(
receive_id: str | None = None,
receive_id_type: str = FeishuReceiveIdType.CHAT_ID,
actor: str = ActorValue.SCHEDULER,
push_run_code: str | None = None,
) -> dict[str, Any]:
return _push_report(_build_project_weekly, receive_id, receive_id_type, actor, push_run_code)
@celery_app.task(name=TASK_PUSH_ATTENDANCE_SUMMARY)
def push_attendance_summary(
receive_id: str | None = None,
receive_id_type: str = FeishuReceiveIdType.CHAT_ID,
actor: str = ActorValue.SCHEDULER,
push_run_code: str | None = None,
) -> dict[str, Any]:
return _push_report(
_build_attendance_summary,
receive_id,
receive_id_type,
actor,
push_run_code,
)
@celery_app.task(name=TASK_PUSH_RISK_PROGRESS)
def push_risk_progress(
receive_id: str | None = None,
receive_id_type: str = FeishuReceiveIdType.CHAT_ID,
actor: str = ActorValue.SCHEDULER,
push_run_code: str | None = None,
) -> dict[str, Any]:
return _push_report(_build_risk_progress, receive_id, receive_id_type, actor, push_run_code)
@celery_app.task(name=TASK_PUSH_WORK_DAILY)
def push_work_daily(
receive_id: str | None = None,
receive_id_type: str = FeishuReceiveIdType.CHAT_ID,
actor: str = ActorValue.SCHEDULER,
push_run_code: str | None = None,
) -> dict[str, Any]:
return _push_report(_build_work_daily, receive_id, receive_id_type, actor, push_run_code)
@celery_app.task(name=TASK_PUSH_WORK_WEEKLY)
def push_work_weekly(
receive_id: str | None = None,
receive_id_type: str = FeishuReceiveIdType.CHAT_ID,
actor: str = ActorValue.SCHEDULER,
push_run_code: str | None = None,
) -> dict[str, Any]:
return _push_report(_build_work_weekly, receive_id, receive_id_type, actor, push_run_code)
def _push_report(
build_report: ReportBuilder,
receive_id: str | None,
receive_id_type: str,
actor: str,
push_run_code: str | None,
) -> dict[str, Any]:
from app.modules.reports.services import ReportService
db = SessionLocal()
try:
report = ReportService(db).project_weekly()
return ReportService(db).push_report(
service = ReportService(db)
report = build_report(service, actor)
return service.push_report(
report,
receive_id,
receive_id_type,
@@ -49,3 +105,31 @@ def push_project_weekly(
)
finally:
db.close()
def _build_daily_brief(service: Any, actor: str) -> dict[str, Any]:
_ = actor
return service.daily_brief()
def _build_project_weekly(service: Any, actor: str) -> dict[str, Any]:
_ = actor
return service.project_weekly()
def _build_attendance_summary(service: Any, actor: str) -> dict[str, Any]:
_ = actor
return service.attendance_summary()
def _build_risk_progress(service: Any, actor: str) -> dict[str, Any]:
_ = actor
return service.risk_progress()
def _build_work_daily(service: Any, actor: str) -> dict[str, Any]:
return service.work_daily_report(reporter=actor, actor=actor)
def _build_work_weekly(service: Any, actor: str) -> dict[str, Any]:
return service.work_weekly_report(reporter=actor, actor=actor)