chore(prep): shared groundwork for batch-4 (report pipeline)
第四批(T15 编排/T16 视觉诊断/T17 文案校验)协调提交: - 迁移 0006:rp_report(result JSONB 按阶段键承载中间态)/rp_input (derived_features 视觉中间态)/rp_share(V1 只建结构) - ORM 三模型;错误码 40420/40920(文案无价格字样) - 配置:report_pipeline_stages(dotted path 动态装配)+ vision/tier - packages/report/pipeline.py:Stage Protocol + ReportContext(三任务共同契约, 动态 import 的动机与代价写在 docstring) - 路由桩 reports.py 已注册
This commit is contained in:
@@ -479,3 +479,65 @@ class KbGap(Base):
|
||||
)
|
||||
|
||||
__table_args__ = (Index("ix_kb_gap_query", "query_text"),)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# report 域(美学报告,架构文档 §6.2 / §7.1)
|
||||
# ---------------------------------------------------------------------------
|
||||
class RpReport(Base):
|
||||
"""报告主表。result JSONB 同时承载流水线中间态与最终产物(按 stage 键)——
|
||||
阶段逐段落库是 T-P3-09「失败不需重新上传」的结构基础。"""
|
||||
|
||||
__tablename__ = "rp_report"
|
||||
|
||||
report_id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=False)
|
||||
user_id: Mapped[int] = mapped_column(BigInteger, nullable=False)
|
||||
tier: Mapped[str] = mapped_column(String(8), nullable=False, default="basic")
|
||||
status: Mapped[str] = mapped_column(String(16), nullable=False, default="pending")
|
||||
version: Mapped[int] = mapped_column(Integer, nullable=False, default=1)
|
||||
result: Mapped[dict[str, Any]] = mapped_column(JSONB, nullable=False, default=dict)
|
||||
model_info: Mapped[dict[str, Any]] = mapped_column(JSONB, nullable=False, default=dict)
|
||||
content_code: Mapped[str | None] = mapped_column(String(32))
|
||||
rendered_asset_key: Mapped[str | None] = mapped_column(String(255))
|
||||
cost_cents: Mapped[Decimal] = mapped_column(
|
||||
Numeric(14, 6), nullable=False, default=Decimal("0")
|
||||
)
|
||||
created_at: Mapped[datetime] = mapped_column(
|
||||
DateTime(timezone=True), nullable=False, server_default=func.now()
|
||||
)
|
||||
completed_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True))
|
||||
|
||||
__table_args__ = (Index("ix_rp_report_user_created", "user_id", "created_at"),)
|
||||
|
||||
|
||||
class RpInput(Base):
|
||||
"""报告输入。derived_features 是视觉分析的中间态:重试/重新生成时
|
||||
已存在则跳过视觉阶段(T-P3-09)。只存派生特征与元信息,不存原图(CR-02)。"""
|
||||
|
||||
__tablename__ = "rp_input"
|
||||
|
||||
input_id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=False)
|
||||
report_id: Mapped[int] = mapped_column(BigInteger, nullable=False)
|
||||
questionnaire: Mapped[dict[str, Any]] = mapped_column(JSONB, nullable=False, default=dict)
|
||||
photo_meta: Mapped[dict[str, Any]] = mapped_column(JSONB, nullable=False, default=dict)
|
||||
derived_features: Mapped[dict[str, Any]] = mapped_column(JSONB, nullable=False, default=dict)
|
||||
|
||||
__table_args__ = (UniqueConstraint("report_id", name="uq_rp_input_report"),)
|
||||
|
||||
|
||||
class RpShare(Base):
|
||||
"""分享链接:可失效、可撤回(V1 只建结构,路由后续任务)。"""
|
||||
|
||||
__tablename__ = "rp_share"
|
||||
|
||||
share_id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=False)
|
||||
report_id: Mapped[int] = mapped_column(BigInteger, nullable=False)
|
||||
share_token: Mapped[str] = mapped_column(String(64), nullable=False)
|
||||
expire_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), nullable=False)
|
||||
view_count: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
|
||||
revoked: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False)
|
||||
created_at: Mapped[datetime] = mapped_column(
|
||||
DateTime(timezone=True), nullable=False, server_default=func.now()
|
||||
)
|
||||
|
||||
__table_args__ = (UniqueConstraint("share_token", name="uq_rp_share_token"),)
|
||||
|
||||
Reference in New Issue
Block a user