from datetime import datetime from sqlalchemy import BigInteger, DateTime, Integer, String, ForeignKey from sqlalchemy.dialects.mysql import LONGTEXT from sqlalchemy.orm import Mapped, mapped_column from alien_database.base import Base, AuditMixin class ContractDocument(Base, AuditMixin): """合同文档""" __tablename__ = "contract_document" id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=True, comment="合同文档唯一标识") bundle_id: Mapped[int] = mapped_column(BigInteger, ForeignKey("contract_bundle.id"), index=True, comment="所属合同包ID") contract_type: Mapped[str] = mapped_column(String(50), comment="合同类型编码(store_agreement/alipay_auth等)") contract_name: Mapped[str] = mapped_column(String(100), comment="合同展示名称") is_primary: Mapped[int] = mapped_column(Integer, default=0, comment="是否主合同(1是/0否)") status: Mapped[int] = mapped_column(Integer, default=0, comment="签署状态(0未签署/1已签署)") sign_flow_id: Mapped[str] = mapped_column(String(64), unique=True, comment="e签宝签署流程ID") file_id: Mapped[str] = mapped_column(String(64), comment="e签宝文件ID") template_url: Mapped[str] = mapped_column(LONGTEXT, comment="合同模板预览URL") sign_url: Mapped[str] = mapped_column(LONGTEXT, comment="签署链接URL") download_url: Mapped[str] = mapped_column(LONGTEXT, comment="签署完成后的下载URL") signing_time: Mapped[datetime | None] = mapped_column(DateTime, nullable=True, comment="签署时间") effective_time: Mapped[datetime | None] = mapped_column(DateTime, nullable=True, comment="合同生效时间") expiry_time: Mapped[datetime | None] = mapped_column(DateTime, nullable=True, comment="合同到期时间")