阶段 当前状态 说明 Phase 0~3 基本完成 Document IR、证据链、人工确认、不可变 PlanData Snapshot、海报/PPT 投影已实现 Phase 4 代码完成 场景、策略、模板版本,校验/发布门禁,确定性 resolver 和严格槽位合并已实现 Phase 5 代码完成 输入冻结、PPTX/海报对账、失败关闭、幂等、心跳、重试和冻结输入重放已实现 Phase 6 基础完成 质量看板、结构化告警、Golden 审批、留存清理、孤儿检查和灰度开关已实现 正式上线 未完成 缺真实样本、生产模板、业务规则签字和灰度观察 目前验证基线: PPT/海报专项测试:107 passed, 1 skipped Vue TypeScript 检查:通过 前端生产构建:通过 代码变更仍在工作区,尚未提交 仓库全量测试仍有既有失败/挂起项,暂时不能宣称全仓测试完全绿色 仍未完成的代码任务主要有: 影子解析差异流水线 目前有灰度开关,但还没有完整的“新旧解析同时运行、字段差异入库、按保司/profile 聚合”的影子比较任务。 自动视觉回归 目前实现的是 DOM 模块、溢出、尺寸、文本和数值检查;还缺基于真实模板和标准图片的像素差异、字体缺失、遮挡和裁切回归。 告警通道接入 后台已经能产生结构化质量告警,但尚未自动推送到邮件、企微或其他通知通道。 留存任务生产化 dry-run、实删服务和失败审计已经具备,但尚未接入周期性 Celery/定时任务,也没有自动重试失败清理批次。 旧链路最终下线 旧 PPT 解析器和海报紧凑解析仍保留为回滚路径。需要全量灰度稳定后才能删除或彻底关闭写入口。 全仓测试收口 需要处理现有无关失败和挂起测试,建立真正全绿的 CI 基线。 仍需外部输入和生产环境完成的事项: 至少 30 份脱敏 Golden PDF,并完成双人标注和精确率验收。 业务专家确认派生公式、缺失值、可比较性和结论策略。 上传并标注真实生产 PPTX 的语义 shape、页面类型和容量。 安装生产字体并建立视觉基准图片。 实际执行数据库迁移 038~040。 完成留存 dry-run、实删演练以及 10% → 30% → 100% 灰度。 观察期通过后开启 SCENARIO_ENGINE_V2,目前它仍默认关闭;真实清理开关也默认关闭。 完整状态记录在 [PPT与海报Phase4至6补充实施记录](D:/work/code/python/coding/baodanagent/docs/PPT与海报Phase4至6补充实施记录_20260802.md)。
106 lines
6.0 KiB
Python
106 lines
6.0 KiB
Python
"""海报生成记录模型。"""
|
||
from sqlalchemy import Column, String, Text, BigInteger, Integer, TIMESTAMP, func
|
||
from insurance.db.compat import db
|
||
|
||
|
||
class PosterRecord(db.Model):
|
||
"""海报生成记录表。"""
|
||
__tablename__ = "poster_records"
|
||
|
||
id = Column(BigInteger, primary_key=True, autoincrement=True)
|
||
user_id = Column(String(50), nullable=False, comment="用户 ID")
|
||
product_id = Column(String(50), nullable=True, comment="产品 ID")
|
||
product_source_type = Column(String(20), nullable=True, comment="library_product/user_material")
|
||
product_source_id = Column(String(64), nullable=True, comment="产品来源 ID")
|
||
product_snapshot_json = Column(Text, nullable=True, comment="提交生成时的产品快照 JSON")
|
||
case_upload_id = Column(BigInteger, nullable=True, comment="关联计划书上传 ID")
|
||
template_id = Column(BigInteger, nullable=True, comment="海报模板 ID")
|
||
copy_mode = Column(String(20), nullable=True, comment="文案模式: template/ai")
|
||
copy_content = Column(Text, nullable=True, comment="最终文案 JSON")
|
||
ai_raw_content = Column(Text, nullable=True, comment="AI 原始文案 JSON(合规留痕)")
|
||
export_url = Column(String(500), nullable=True, comment="导出文件地址")
|
||
export_format = Column(String(10), nullable=True, comment="导出格式: png/jpg")
|
||
export_size = Column(String(20), nullable=True, comment="导出尺寸")
|
||
reference_image_used = Column(String(500), nullable=True, comment="使用的参考图(合规留痕)")
|
||
prompt_used = Column(Text, nullable=True, comment="完整 prompt(合规留痕)")
|
||
generation_mode = Column(String(20), nullable=True, comment="生成方式: ai/fallback")
|
||
image_provider = Column(String(50), nullable=True, comment="图片供应商")
|
||
image_model = Column(String(100), nullable=True, comment="图片模型名称")
|
||
task_status = Column(String(20), default="pending", comment="任务状态: pending/queued/generating/background_ready/done/failed")
|
||
task_progress = Column(db.Integer, default=0, comment="任务进度 0-100")
|
||
task_error = Column(Text, nullable=True, comment="任务错误信息")
|
||
extra_data = Column(Text, nullable=True, comment="扩展数据 JSON(如品牌策略、输出模式)")
|
||
document_json = Column(Text, nullable=True, comment="可编辑海报文档 JSON")
|
||
document_revision = Column(Integer, default=1, comment="海报文档版本")
|
||
background_file_url = Column(String(500), nullable=True, comment="AI 背景图文件地址")
|
||
compliance_json = Column(Text, nullable=True, comment="服务端合规检查结果 JSON")
|
||
compliance_revision = Column(String(64), nullable=True, comment="合规文案哈希")
|
||
# 工作区字段(migrate_022)
|
||
title = Column(String(200), default="", comment="工作区名称")
|
||
workflow_step = Column(String(20), default="product", comment="当前业务步骤")
|
||
draft_status = Column(String(20), default="active", comment="active/archived")
|
||
draft_revision = Column(Integer, default=1, comment="当前草稿版本")
|
||
generated_revision = Column(Integer, default=0, comment="最新成品版本")
|
||
latest_task_id = Column(String(36), nullable=True, comment="最近任务 ID")
|
||
archived_at = Column(TIMESTAMP, nullable=True, comment="归档时间")
|
||
started_at = Column(TIMESTAMP, nullable=True, comment="任务开始时间")
|
||
finished_at = Column(TIMESTAMP, nullable=True, comment="任务完成时间")
|
||
created_at = Column(TIMESTAMP, server_default=func.now())
|
||
|
||
def to_dict(self):
|
||
import json
|
||
|
||
def _safe_json(text):
|
||
if not text:
|
||
return None
|
||
try:
|
||
return json.loads(text)
|
||
except (json.JSONDecodeError, TypeError):
|
||
return None
|
||
|
||
return {
|
||
"id": self.id,
|
||
"userId": self.user_id,
|
||
"productId": self.product_id,
|
||
"productSource": {
|
||
"type": self.product_source_type or "library_product",
|
||
"id": self.product_source_id or self.product_id,
|
||
},
|
||
"productSnapshot": _safe_json(self.product_snapshot_json),
|
||
"caseUploadId": self.case_upload_id,
|
||
"templateId": self.template_id,
|
||
"copyMode": self.copy_mode,
|
||
"copyContent": _safe_json(self.copy_content),
|
||
"aiRawContent": _safe_json(self.ai_raw_content),
|
||
"exportUrl": f"/insurance/poster/download/{self.id}" if self.export_url else None,
|
||
"exportFormat": self.export_format,
|
||
"exportSize": self.export_size,
|
||
"referenceImageUsed": bool(self.reference_image_used),
|
||
"promptUsed": self.prompt_used,
|
||
"generationMode": self.generation_mode,
|
||
"imageProvider": self.image_provider,
|
||
"imageModel": self.image_model,
|
||
"taskStatus": self.task_status,
|
||
"taskProgress": self.task_progress,
|
||
"taskError": self.task_error,
|
||
"extraData": _safe_json(self.extra_data),
|
||
"document": _safe_json(self.document_json),
|
||
"documentRevision": self.document_revision or 1,
|
||
"backgroundUrl": (
|
||
f"/insurance/poster/records/{self.id}/background"
|
||
if self.background_file_url else None
|
||
),
|
||
"compliance": _safe_json(self.compliance_json),
|
||
"complianceRevision": self.compliance_revision or "",
|
||
"title": self.title or "",
|
||
"workflowStep": self.workflow_step or "product",
|
||
"draftStatus": self.draft_status or "active",
|
||
"draftRevision": self.draft_revision or 1,
|
||
"generatedRevision": self.generated_revision or 0,
|
||
"latestTaskId": self.latest_task_id,
|
||
"archivedAt": self.archived_at.isoformat() if self.archived_at else None,
|
||
"startedAt": self.started_at.isoformat() if self.started_at else None,
|
||
"finishedAt": self.finished_at.isoformat() if self.finished_at else None,
|
||
"createdAt": self.created_at.isoformat() if self.created_at else None,
|
||
}
|