from sqlalchemy import ForeignKey, Integer, String, Text from sqlalchemy.orm import Mapped, mapped_column, relationship from app.core.base_model import ModelMixin, TenantMixin, UserMixin class EnergyReportTemplateModel(ModelMixin, TenantMixin, UserMixin): """能源报告模板模型。""" __tablename__: str = "energy_report_template" __table_args__: dict[str, str] = {"comment": "能源报告模板表"} __loader_options__: list[str] = [ "file", "created_by", "updated_by", "deleted_by", "tenant_by", ] template_name: Mapped[str] = mapped_column(String(128), nullable=False, comment="模板名称", index=True) report_type: Mapped[int] = mapped_column(Integer, default=1, nullable=False, comment="报告类型 1:能源报告 2:光伏报告", index=True) template_type: Mapped[str] = mapped_column(String(64), nullable=False, comment="模板类型", index=True) version: Mapped[str | None] = mapped_column(String(32), default=None, nullable=True, comment="模板版本") file_id: Mapped[int] = mapped_column( Integer, ForeignKey("common_file.id", ondelete="RESTRICT", onupdate="CASCADE"), nullable=False, index=True, comment="文件记录ID", ) status: Mapped[int] = mapped_column(Integer, default=0, nullable=False, comment="状态 0:启用 1:停用", index=True) order: Mapped[int] = mapped_column(Integer, default=999, nullable=False, comment="显示排序") description: Mapped[str | None] = mapped_column(Text, default=None, nullable=True, comment="描述") file = relationship("FileModel", lazy="selectin", foreign_keys=[file_id], uselist=False)