35 lines
1.6 KiB
Python
35 lines
1.6 KiB
Python
"""方案模板模型。"""
|
|
from sqlalchemy import Column, Integer, String, Text, Boolean, TIMESTAMP, func
|
|
from insurance.db.compat import db
|
|
|
|
|
|
class ProposalTemplate(db.Model):
|
|
"""方案模板表。"""
|
|
__tablename__ = "insurance_proposal_templates"
|
|
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
name = Column(String(128), nullable=False, comment="模板名称")
|
|
description = Column(String(256), default="", comment="模板描述")
|
|
insurance_type = Column(String(64), nullable=False, comment="险种类型")
|
|
file_path = Column(String(512), default="", comment="模板文件路径")
|
|
file_type = Column(String(32), default="pdf", comment="文件类型(pdf/docx)")
|
|
placeholders = Column(Text, default="[]", comment="占位符配置JSON")
|
|
is_default = Column(Boolean, default=False, 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": f"template-{self.id}",
|
|
"name": self.name,
|
|
"description": self.description,
|
|
"insurance_type": self.insurance_type,
|
|
"file_path": self.file_path,
|
|
"file_type": self.file_type,
|
|
"placeholders": json.loads(self.placeholders) if self.placeholders else [],
|
|
"is_default": self.is_default,
|
|
"created_at": str(self.created_at) if self.created_at else None,
|
|
"updated_at": str(self.updated_at) if self.updated_at else None,
|
|
}
|