```
feat(scheduler): 新增多种报表推送功能并重构调度器代码 - 新增考勤汇总、风险进度、工作日报、工作周报等报表推送功能 - 重构调度器中的报表推送逻辑,提取通用的 deliver_report 函数 - 添加新的定时任务配置项用于各种报表推送 - 实现飞书推送配置检查函数 _feishu_delivery_configured - 将重复的报表推送代码抽取为可复用的函数模式 ```
This commit is contained in:
@@ -96,6 +96,8 @@ from app.modules.reports.constants import (
|
||||
LifecycleSection,
|
||||
MetricKey,
|
||||
ReportPushStatus,
|
||||
ReportPushType,
|
||||
ReportResponseKey,
|
||||
ReportTitle,
|
||||
ReportType,
|
||||
)
|
||||
@@ -773,6 +775,72 @@ def test_new_ledgers_reports_and_risk_events() -> None:
|
||||
assert any(item["code"] == "TASK-RISK-001" for item in overdue_response.json()["items"])
|
||||
|
||||
|
||||
def test_independent_feishu_report_schedules_and_tasks_are_registered() -> None:
|
||||
from app.core.background.scheduler import create_scheduler
|
||||
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.tasks import celery_app
|
||||
|
||||
scheduler = create_scheduler()
|
||||
job_ids = {job.id for job in scheduler.get_jobs()}
|
||||
assert {
|
||||
"daily_brief_push",
|
||||
"project_weekly_push",
|
||||
"attendance_summary_push",
|
||||
"risk_progress_push",
|
||||
"work_daily_push",
|
||||
"work_weekly_push",
|
||||
} <= job_ids
|
||||
|
||||
task_names = {
|
||||
TASK_PUSH_DAILY_BRIEF,
|
||||
TASK_PUSH_PROJECT_WEEKLY,
|
||||
TASK_PUSH_ATTENDANCE_SUMMARY,
|
||||
TASK_PUSH_RISK_PROGRESS,
|
||||
TASK_PUSH_WORK_DAILY,
|
||||
TASK_PUSH_WORK_WEEKLY,
|
||||
}
|
||||
assert task_names <= set(celery_app.tasks)
|
||||
|
||||
|
||||
def test_independent_feishu_report_surfaces_are_available() -> None:
|
||||
from app.modules.reports.services import ReportService
|
||||
|
||||
route_paths = {route.path for route in app.routes}
|
||||
assert {
|
||||
"/api/v1/reports/attendance-summary/push",
|
||||
"/api/v1/reports/attendance-summary/enqueue",
|
||||
"/api/v1/reports/risk-progress/push",
|
||||
"/api/v1/reports/risk-progress/enqueue",
|
||||
"/api/v1/reports/work-daily/push",
|
||||
"/api/v1/reports/work-daily/enqueue",
|
||||
"/api/v1/reports/work-weekly/push",
|
||||
"/api/v1/reports/work-weekly/enqueue",
|
||||
} <= route_paths
|
||||
|
||||
risk_response = client.get("/api/v1/reports/risk-progress", headers=headers)
|
||||
assert risk_response.status_code == 200
|
||||
assert risk_response.json()["title"] == ReportTitle.RISK_PROGRESS
|
||||
assert risk_response.json()["report_type"] == ReportPushType.RISK_PROGRESS
|
||||
|
||||
db = SessionLocal()
|
||||
try:
|
||||
service = ReportService(db)
|
||||
work_daily = service.work_daily_report(reporter="pytest", actor="pytest")
|
||||
work_weekly = service.work_weekly_report(reporter="pytest", actor="pytest")
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
assert work_daily[ReportResponseKey.REPORT_TYPE] == ReportPushType.WORK_DAILY
|
||||
assert work_weekly[ReportResponseKey.REPORT_TYPE] == ReportPushType.WORK_WEEKLY
|
||||
|
||||
|
||||
def test_project_lifecycle_report_summarizes_progress_cost_and_risk() -> None:
|
||||
today = date.today()
|
||||
project_code = "P-LIFECYCLE-001"
|
||||
|
||||
Reference in New Issue
Block a user