"""AAR 系统化复盘模型。""" import uuid from datetime import datetime, timezone from sqlalchemy import DateTime, ForeignKey, String, Text from sqlalchemy.orm import Mapped, mapped_column from app.core.database import Base from app.core.types import JSONBType class AARRecord(Base): """AAR 复盘记录。""" __tablename__ = "aar_records" id: Mapped[str] = mapped_column(String(36), primary_key=True, default=lambda: str(uuid.uuid4())) company_id: Mapped[str] = mapped_column(String(36), ForeignKey("companies.id"), nullable=False, index=True) trigger_event: Mapped[str] = mapped_column(String(200), nullable=False, comment="触发事件") original_plan: Mapped[str | None] = mapped_column(Text, nullable=True, comment="原计划") actual_result: Mapped[str | None] = mapped_column(Text, nullable=True, comment="实际结果") gap_analysis: Mapped[str | None] = mapped_column(Text, nullable=True, comment="差异分析") lessons: Mapped[dict | None] = mapped_column(JSONBType, nullable=True, comment="五问复盘结论") improvements: Mapped[dict | None] = mapped_column(JSONBType, nullable=True, comment="改进措施 + 执行追踪") knowledge_graph_ref: Mapped[str | None] = mapped_column(String(36), nullable=True, comment="知识图谱节点 ID") created_at: Mapped[datetime] = mapped_column( DateTime(timezone=True), default=lambda: datetime.now(timezone.utc) )