52 lines
2.9 KiB
Python
52 lines
2.9 KiB
Python
"""PPT 生成会话模型。"""
|
|
from sqlalchemy import Column, String, Text, Integer, TIMESTAMP, func
|
|
from insurance.db.compat import db
|
|
|
|
|
|
class PptSession(db.Model):
|
|
"""PPT 生成会话表。"""
|
|
__tablename__ = "insurance_ppt_sessions"
|
|
|
|
id = Column(String(36), primary_key=True, comment="UUID")
|
|
user_id = Column(String(64), nullable=False, comment="用户 ID")
|
|
status = Column(String(20), default="created", nullable=False,
|
|
comment="状态: created/parsing/parsed/generating/done/error")
|
|
files_json = Column(Text, nullable=True, comment="上传文件列表 JSON")
|
|
extractions_json = Column(Text, nullable=True, comment="提取结果 JSON")
|
|
parse_progress = Column(Integer, default=0, nullable=False, comment="解析进度 0-100")
|
|
parse_message = Column(Text, nullable=True, comment="解析进度说明")
|
|
parse_error = Column(Text, nullable=True, comment="解析任务错误")
|
|
parse_started_at = Column(TIMESTAMP, nullable=True, comment="解析开始时间")
|
|
parse_finished_at = Column(TIMESTAMP, nullable=True, comment="解析完成时间")
|
|
chat_history_json = Column(Text, nullable=True, comment="对话历史 JSON")
|
|
ppt_path = Column(String(500), nullable=True, comment="生成的 PPT 路径")
|
|
markdown_path = Column(String(500), nullable=True, comment="Markdown 路径")
|
|
preview_paths_json = Column(Text, nullable=True, comment="预览图路径 JSON")
|
|
preview_pdf_path = Column(String(500), nullable=True, comment="预览 PDF 路径")
|
|
slide_count = Column(Integer, nullable=True, comment="幻灯片数量")
|
|
created_at = Column(TIMESTAMP, server_default=func.now())
|
|
updated_at = Column(TIMESTAMP, server_default=func.now(), onupdate=func.now())
|
|
|
|
def to_dict(self):
|
|
import json
|
|
return {
|
|
"id": self.id,
|
|
"user_id": self.user_id,
|
|
"status": self.status,
|
|
"files": json.loads(self.files_json) if self.files_json else [],
|
|
"extractions": json.loads(self.extractions_json) if self.extractions_json else [],
|
|
"parse_progress": self.parse_progress or 0,
|
|
"parse_message": self.parse_message,
|
|
"parse_error": self.parse_error,
|
|
"parse_started_at": str(self.parse_started_at) if self.parse_started_at else None,
|
|
"parse_finished_at": str(self.parse_finished_at) if self.parse_finished_at else None,
|
|
"chat_history": json.loads(self.chat_history_json) if self.chat_history_json else [],
|
|
"ppt_path": self.ppt_path,
|
|
"markdown_path": self.markdown_path,
|
|
"preview_paths": json.loads(self.preview_paths_json) if self.preview_paths_json else [],
|
|
"preview_pdf_path": self.preview_pdf_path,
|
|
"slide_count": self.slide_count,
|
|
"created_at": str(self.created_at) if self.created_at else None,
|
|
"updated_at": str(self.updated_at) if self.updated_at else None,
|
|
}
|