Files
company-ai-platform/app/tasks/reports.py
JiuContinent db751f03b4 ```
refactor(Dockerfile): 使用requirements.txt替代硬编码依赖

将Dockerfile中的硬编码pip包列表替换为通过requirements.txt文件安装,
提高依赖管理的灵活性和可维护性。

feat(scheduling): 移除内置APScheduler,采用独立调度系统

移除app/core/background/scheduler.py中原来的APScheduler实现,
改为使用新的应用级调度系统app.application.scheduling。

refactor(task_queue): 调整任务队列模块结构和导入路径

将任务队列相关常量从app.core.background.task_queue.constants迁移至
app.tasks.constants,并更新所有相关导入路径和引用。

refactor(events): 将事件服务重构为独立的应用层组件

将事件分发逻辑从核心层迁移到应用层,使用app.application.events.EventDispatchService
替代原有的app.modules.events.services.EventService。

feat(ai_memory): 增强AI记忆自动写入的安全策略

新增ai_memory_blocked_content_terms配置项用于阻止敏感内容,
添加TTL过期机制控制自动写入条目的生命周期。

fix(security): 强化生产环境安全验证机制

增加model_validator确保生产环境中数据库连接、API密钥、CORS设置等
关键安全配置符合要求。

feat(risks): 优化风险事件操作动作的外键约束

为RiskEventAction模型的风险事件ID字段添加外键约束,
防止孤立记录并增强数据完整性。

refactor(audit): 优化审计服务方法命名和事务处理

将AuditService的log方法重命名为record以反映其阶段行为,
并调整事务提交时机以提高性能。

feat(events): 增强领域事件并发处理和响应模型

添加事件锁定机制防止重复处理,更新API响应模型以提供
更准确的数据类型定义。
```
2026-07-15 16:36:42 +08:00

137 lines
4.0 KiB
Python

from collections.abc import Callable
from typing import Any
from app.tasks.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=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]:
return _push_report(_build_daily_brief, receive_id, receive_id_type, actor, push_run_code)
@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.application.delivery import ReportDeliveryService
from app.modules.reports.services import ReportService
db = SessionLocal()
try:
service = ReportService(db)
report = build_report(service, actor)
return ReportDeliveryService(db).push_report(
report,
receive_id,
receive_id_type,
actor,
push_run_code=push_run_code,
)
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)