```
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响应模型以提供 更准确的数据类型定义。 ```
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import JSON, DateTime, Integer, String
|
||||
from sqlalchemy import JSON, DateTime, ForeignKey, Integer, String, UniqueConstraint
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from app.core.constants import ActorValue
|
||||
@@ -11,6 +11,14 @@ from app.modules.workflows.constants import WorkflowStatus
|
||||
|
||||
class WorkflowInstance(Base):
|
||||
__tablename__ = "workflow_instances"
|
||||
__table_args__ = (
|
||||
UniqueConstraint(
|
||||
"workflow_type",
|
||||
"aggregate_type",
|
||||
"aggregate_id",
|
||||
name="uq_workflow_aggregate",
|
||||
),
|
||||
)
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
||||
code: Mapped[str] = mapped_column(String(64), unique=True, index=True)
|
||||
@@ -35,7 +43,10 @@ class WorkflowAction(Base):
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
||||
code: Mapped[str] = mapped_column(String(64), unique=True, index=True)
|
||||
workflow_code: Mapped[str] = mapped_column(String(64), index=True)
|
||||
workflow_code: Mapped[str] = mapped_column(
|
||||
ForeignKey("workflow_instances.code", ondelete="RESTRICT"),
|
||||
index=True,
|
||||
)
|
||||
action: Mapped[str] = mapped_column(String(128), index=True)
|
||||
actor: Mapped[str] = mapped_column(String(128), default=ActorValue.SYSTEM, index=True)
|
||||
from_status: Mapped[str | None] = mapped_column(String(32), nullable=True)
|
||||
|
||||
@@ -4,12 +4,13 @@ from sqlalchemy.orm import Session
|
||||
from app.core.database import get_db
|
||||
from app.core.security import require_api_key
|
||||
from app.modules.workflows.constants import WorkflowResponseKey
|
||||
from app.modules.workflows.schemas import WorkflowListRead, WorkflowRead
|
||||
from app.modules.workflows.service import WorkflowService
|
||||
|
||||
router = APIRouter(dependencies=[Depends(require_api_key)])
|
||||
|
||||
|
||||
@router.get("")
|
||||
@router.get("", response_model=WorkflowListRead)
|
||||
def list_workflows(
|
||||
status: str | None = None,
|
||||
workflow_type: str | None = None,
|
||||
@@ -25,7 +26,7 @@ def list_workflows(
|
||||
}
|
||||
|
||||
|
||||
@router.get("/{code}")
|
||||
@router.get("/{code}", response_model=dict[str, WorkflowRead])
|
||||
def get_workflow(
|
||||
code: str,
|
||||
db: Session = Depends(get_db),
|
||||
|
||||
@@ -15,7 +15,8 @@ class WorkflowRead(BaseModel):
|
||||
created_at: str
|
||||
updated_at: str
|
||||
completed_at: str | None
|
||||
actions: list[dict[str, Any]] | None = None
|
||||
|
||||
|
||||
class WorkflowListRead(BaseModel):
|
||||
items: list[dict[str, Any]]
|
||||
items: list[WorkflowRead]
|
||||
|
||||
@@ -33,6 +33,7 @@ class WorkflowService:
|
||||
action: str,
|
||||
actor: str = ActorValue.SYSTEM,
|
||||
payload: dict[str, Any] | None = None,
|
||||
commit: bool = True,
|
||||
) -> WorkflowInstance:
|
||||
aggregate_id_text = str(aggregate_id) if aggregate_id is not None else None
|
||||
record = self.db.execute(
|
||||
@@ -92,8 +93,11 @@ class WorkflowService:
|
||||
payload=payload or {},
|
||||
)
|
||||
)
|
||||
self.db.commit()
|
||||
self.db.refresh(record)
|
||||
if commit:
|
||||
self.db.commit()
|
||||
self.db.refresh(record)
|
||||
else:
|
||||
self.db.flush()
|
||||
return record
|
||||
|
||||
def list_workflows(
|
||||
|
||||
Reference in New Issue
Block a user