You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

110 lines
4.1 KiB
Python

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 EnergyReportGenerationModel(ModelMixin, TenantMixin, UserMixin):
"""能源报告生成任务模型。"""
__tablename__: str = "energy_report_generation"
__table_args__: dict[str, str] = {"comment": "能源报告生成任务表"}
__loader_options__: list[str] = [
"template",
"file",
"attachment_file",
"generator",
"created_by",
"updated_by",
"deleted_by",
"tenant_by",
]
generation_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_id: Mapped[int] = mapped_column(
Integer,
ForeignKey("energy_report_template.id", ondelete="RESTRICT", onupdate="CASCADE"),
nullable=False,
index=True,
comment="能源报告模板ID",
)
file_id: Mapped[int | None] = mapped_column(
Integer,
ForeignKey("common_file.id", ondelete="SET NULL", onupdate="CASCADE"),
nullable=True,
index=True,
comment="生成源文档文件ID",
)
attachment_file_id: Mapped[int | None] = mapped_column(
Integer,
ForeignKey("common_file.id", ondelete="SET NULL", onupdate="CASCADE"),
nullable=True,
index=True,
comment="附件文件ID",
)
attachment_url: Mapped[str | None] = mapped_column(
String(512),
default=None,
nullable=True,
comment="附件下载地址",
)
status: Mapped[int] = mapped_column(
Integer,
default=0,
nullable=False,
comment="状态 0:待生成 1:生成中 2:已生成 3:生成失败",
index=True,
)
generator_id: Mapped[int | None] = mapped_column(
Integer,
ForeignKey("sys_user.id", ondelete="SET NULL", onupdate="CASCADE"),
nullable=True,
index=True,
comment="生成人ID",
)
description: Mapped[str | None] = mapped_column(Text, default=None, nullable=True, comment="描述")
template = relationship("EnergyReportTemplateModel", lazy="selectin", foreign_keys=[template_id], uselist=False)
file = relationship("FileModel", lazy="selectin", foreign_keys=[file_id], uselist=False)
attachment_file = relationship(
"FileModel",
lazy="selectin",
foreign_keys=[attachment_file_id],
uselist=False,
)
generator = relationship("UserModel", lazy="selectin", foreign_keys=[generator_id], uselist=False)
class EnergyReportGenerationLogModel(ModelMixin, TenantMixin, UserMixin):
"""能源报告生成操作记录模型。"""
__tablename__: str = "energy_report_generation_log"
__table_args__: dict[str, str] = {"comment": "能源报告生成操作记录表"}
__loader_options__: list[str] = [
"generation",
"created_by",
"updated_by",
"deleted_by",
"tenant_by",
]
report_generation_id: Mapped[int] = mapped_column(
Integer,
ForeignKey("energy_report_generation.id", ondelete="CASCADE", onupdate="CASCADE"),
nullable=False,
index=True,
comment="能源报告生成任务ID",
)
generation_name: Mapped[str] = mapped_column(String(128), nullable=False, comment="任务名称快照", index=True)
action_type: Mapped[str] = mapped_column(
String(32),
nullable=False,
index=True,
comment="操作类型:create_task/start_generation/generation_success/generation_failed",
)
action_name: Mapped[str] = mapped_column(String(64), nullable=False, comment="操作名称")
description: Mapped[str | None] = mapped_column(Text, default=None, nullable=True, comment="操作描述")
generation = relationship("EnergyReportGenerationModel", lazy="selectin", foreign_keys=[report_generation_id], uselist=False)