海报确认、文案生成、海报生成增加服务端失败关闭门禁,绑定文件哈希、解析快照哈希和确认数据哈希,并返回 422 业务错误。[validators.py (line 65)](D:/work/code/python/coding/baodanagent/api/insurance/plan_data/validators.py:65) 缺失金额不再转换为 0;删除错误字段兜底和“年缴×年期=合同总保费”事实推导;里程碑冲突会阻断确认。[normalizer.py (line 14)](D:/work/code/python/coding/baodanagent/api/insurance/ppt/normalizer.py:14) PPT 渲染器支持可空金额和实际币种,缺失值显示“待确认”,避免 float(None)、空值除法等异常。 模板必须覆盖全部输入保司和产品;自动选择排序确定化,同优先级歧义时阻断。[template_selection.py (line 4)](D:/work/code/python/coding/baodanagent/api/insurance/ppt/template_selection.py:4) 场景判定写入 scenarioOverrideTrace,记录请求、模板、服务端及 Worker 最终判定。[routes.py (line 555)](D:/work/code/python/coding/baodanagent/api/insurance/ppt/routes.py:555) 前端增加哈希提交、人工调整原因、模板歧义提示及真实能力说明。 冻结三份核心 Schema,并建立 Goldens manifest、说明和评估脚本。 验证结果: 后端目标回归:111 passed, 1 skipped PPT 运行时回归:81 passed 前端生产构建和 vue-tsc:通过 Python compileall:通过 三份 Schema JSON:解析通过 git diff --check:通过,仅有换行符提示
90 lines
4.3 KiB
Python
90 lines
4.3 KiB
Python
"""海报计划书上传模型。"""
|
|
from sqlalchemy import Column, String, Text, BigInteger, Integer, TIMESTAMP, func
|
|
from insurance.db.compat import db
|
|
|
|
|
|
class PosterCaseUpload(db.Model):
|
|
"""海报计划书上传记录表。"""
|
|
__tablename__ = "poster_case_uploads"
|
|
|
|
id = Column(BigInteger, primary_key=True, autoincrement=True)
|
|
user_id = Column(String(50), nullable=False, comment="用户 ID")
|
|
product_id = Column(String(50), nullable=False, 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")
|
|
source_file_url = Column(String(500), nullable=False, comment="源文件地址")
|
|
parse_status = Column(
|
|
String(20),
|
|
default="pending",
|
|
comment="解析状态: pending/queued/parsing/parsed/partial/failed",
|
|
)
|
|
parse_progress = Column(Integer, nullable=False, default=0, comment="解析进度 0-100")
|
|
parse_message = Column(String(500), nullable=False, default="", comment="解析进度说明")
|
|
parse_error = Column(Text, nullable=True, comment="解析失败原因")
|
|
parse_task_id = Column(String(200), nullable=True, comment="Celery 任务 ID")
|
|
parse_started_at = Column(TIMESTAMP, nullable=True)
|
|
parse_heartbeat_at = Column(TIMESTAMP, nullable=True)
|
|
parse_finished_at = Column(TIMESTAMP, nullable=True)
|
|
file_hash = Column(String(64), nullable=True, index=True, comment="源文件 SHA-256")
|
|
parsed_data = Column(Text, nullable=True, comment="系统解析结果 JSON")
|
|
confirmed_data = Column(Text, nullable=True, comment="人工核对后最终结果 JSON")
|
|
confirmed_by = Column(String(50), nullable=True, comment="核对人")
|
|
confirmed_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
|
|
|
|
def _safe_error(value):
|
|
if not value:
|
|
return ""
|
|
message = str(value).strip()
|
|
unsafe_markers = (
|
|
"traceback", "file \"", "\\", "/app/", "/api/",
|
|
"http://", "https://", "api_key", "token=",
|
|
)
|
|
if "\n" in message or any(marker in message.lower() for marker in unsafe_markers):
|
|
return "解析失败,请重试;如多次失败请联系管理员"
|
|
return message[:300]
|
|
|
|
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),
|
|
"sourceFileUrl": self.source_file_url,
|
|
"fileHash": self.file_hash,
|
|
"parseSnapshotHash": self._parse_snapshot_hash(),
|
|
"parseStatus": self.parse_status,
|
|
"parseProgress": self.parse_progress or 0,
|
|
"parseMessage": self.parse_message or "",
|
|
"parseError": _safe_error(self.parse_error),
|
|
"parseTaskId": self.parse_task_id,
|
|
"parseStartedAt": self.parse_started_at.isoformat() if self.parse_started_at else None,
|
|
"parseHeartbeatAt": self.parse_heartbeat_at.isoformat() if self.parse_heartbeat_at else None,
|
|
"parseFinishedAt": self.parse_finished_at.isoformat() if self.parse_finished_at else None,
|
|
"parsedData": _safe_json(self.parsed_data),
|
|
"confirmedData": _safe_json(self.confirmed_data),
|
|
"confirmedBy": self.confirmed_by,
|
|
"confirmedAt": self.confirmed_at.isoformat() if self.confirmed_at else None,
|
|
"createdAt": self.created_at.isoformat() if self.created_at else None,
|
|
}
|
|
|
|
def _parse_snapshot_hash(self):
|
|
from insurance.plan_data.validators import parse_snapshot_hash
|
|
|
|
return parse_snapshot_hash(self)
|