from sqlalchemy import BigInteger, Integer, String, Text from sqlalchemy.orm import Mapped, mapped_column from app.core.base_model import ModelMixin, TenantMixin, UserMixin class FileModel(ModelMixin, TenantMixin, UserMixin): """通用文件记录模型。""" __tablename__: str = "common_file" __table_args__: dict[str, str] = {"comment": "通用文件记录表"} __loader_options__: list[str] = [ "created_by", "updated_by", "deleted_by", "tenant_by", ] storage_type: Mapped[str] = mapped_column(String(20), nullable=False, default="local", comment="存储类型: local/minio", index=True) bucket_name: Mapped[str | None] = mapped_column(String(128), default=None, nullable=True, comment="MinIO存储桶") object_name: Mapped[str | None] = mapped_column(String(512), default=None, nullable=True, comment="MinIO对象名称") original_name: Mapped[str] = mapped_column(String(255), nullable=False, comment="原始文件名") file_name: Mapped[str] = mapped_column(String(255), nullable=False, comment="存储文件名") file_ext: Mapped[str | None] = mapped_column(String(32), default=None, nullable=True, comment="文件扩展名", index=True) content_type: Mapped[str | None] = mapped_column(String(128), default=None, nullable=True, comment="文件MIME类型") file_size: Mapped[int] = mapped_column(BigInteger, default=0, nullable=False, comment="文件大小,单位字节") file_path: Mapped[str | None] = mapped_column(String(512), default=None, nullable=True, comment="本地路径或对象路径") file_url: Mapped[str | None] = mapped_column(Text, default=None, nullable=True, comment="文件访问地址") upload_type: Mapped[str] = mapped_column(String(32), default="file", nullable=False, comment="上传类型", index=True) business_type: Mapped[str | None] = mapped_column(String(64), default=None, nullable=True, comment="业务类型", index=True) business_id: Mapped[int | None] = mapped_column(Integer, default=None, nullable=True, comment="业务ID", index=True)