"""PPT 历史记录模型。""" from sqlalchemy import Column, String, Text, Integer, BigInteger, TIMESTAMP, func from insurance.db.compat import db class PptHistory(db.Model): """PPT 生成历史记录表。""" __tablename__ = "insurance_ppt_history" id = Column(BigInteger, primary_key=True, autoincrement=True) user_id = Column(String(50), nullable=False, comment="用户 ID") session_id = Column(String(50), nullable=True, comment="关联 PptSession") action_type = Column(String(20), nullable=False, comment="操作类型: create/edit/preview/export/download") company_id = Column(String(50), nullable=True, comment="保司 ID") product_id = Column(String(50), nullable=True, comment="产品 ID") template_id = Column(String(50), nullable=True, comment="模板 ID") content_snapshot = Column(Text, nullable=True, comment="内容快照 JSON") file_url = Column(String(500), nullable=True, comment="文件地址") ip = Column(String(50), nullable=True, comment="IP 地址") user_agent = Column(String(500), nullable=True, comment="User-Agent") created_at = Column(TIMESTAMP, server_default=func.now()) def to_dict(self): import json return { "id": self.id, "userId": self.user_id, "sessionId": self.session_id, "actionType": self.action_type, "companyId": self.company_id, "productId": self.product_id, "templateId": self.template_id, "contentSnapshot": json.loads(self.content_snapshot) if self.content_snapshot else None, "fileUrl": self.file_url, "ip": self.ip, "userAgent": self.user_agent, "createdAt": self.created_at.isoformat() if self.created_at else None, }