64 lines
4.1 KiB
Python
64 lines
4.1 KiB
Python
from __future__ import annotations
|
|
|
|
from decimal import Decimal
|
|
|
|
from datetime import datetime
|
|
|
|
from sqlalchemy import BigInteger, Boolean, DateTime, Index, Integer, Numeric, String, Text
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from app.enums.home_material import HomeMaterialAssetStatus, HomeMaterialMediaType
|
|
from app.models.base import Base, SoftDeleteMixin, TimestampMixin
|
|
|
|
|
|
class HomeMaterialAsset(Base, TimestampMixin, SoftDeleteMixin):
|
|
"""首页素材资产。"""
|
|
|
|
__tablename__ = "home_material_assets"
|
|
__table_args__ = (
|
|
Index("idx_home_material_assets_admin_list", "deleted_at", "category_id", "media_type", "status", "is_active", "sort_order", "created_at"),
|
|
Index("idx_home_material_assets_category_sort", "category_id", "sort_order", "created_at"),
|
|
Index("idx_home_material_assets_status", "status"),
|
|
)
|
|
|
|
id: Mapped[str] = mapped_column(String(32), primary_key=True)
|
|
category_id: Mapped[str] = mapped_column(String(32), nullable=False, index=True, comment="行业类别ID")
|
|
title: Mapped[str | None] = mapped_column(String(128), nullable=True, index=True, comment="素材标题")
|
|
media_type: Mapped[str] = mapped_column(
|
|
String(16),
|
|
default=HomeMaterialMediaType.IMAGE.value,
|
|
server_default=HomeMaterialMediaType.IMAGE.value,
|
|
nullable=False,
|
|
index=True,
|
|
comment="素材类型:image图片,video视频",
|
|
)
|
|
original_url: Mapped[str] = mapped_column(Text, nullable=False, comment="原始素材URL")
|
|
original_storage_path: Mapped[str] = mapped_column(Text, nullable=False, comment="原始素材本地路径")
|
|
watermarked_url: Mapped[str | None] = mapped_column(Text, nullable=True, comment="水印素材URL")
|
|
watermarked_storage_path: Mapped[str | None] = mapped_column(Text, nullable=True, comment="水印素材本地路径")
|
|
cover_url: Mapped[str | None] = mapped_column(Text, nullable=True, comment="视频封面URL")
|
|
cover_storage_path: Mapped[str | None] = mapped_column(Text, nullable=True, comment="视频封面本地路径")
|
|
watermark_id: Mapped[str | None] = mapped_column(String(32), nullable=True, index=True, comment="水印图片ID")
|
|
watermark_config_json: Mapped[str | None] = mapped_column(Text, nullable=True, comment="水印配置快照JSON")
|
|
generation_prompt: Mapped[str | None] = mapped_column(Text, nullable=True, comment="生成提词")
|
|
media_references_json: Mapped[str | None] = mapped_column(Text, nullable=True, comment="附件/参考素材JSON字符串")
|
|
status: Mapped[str] = mapped_column(
|
|
String(32),
|
|
default=HomeMaterialAssetStatus.DRAFT.value,
|
|
server_default=HomeMaterialAssetStatus.DRAFT.value,
|
|
nullable=False,
|
|
index=True,
|
|
comment="处理状态:draft/processing/success/failed",
|
|
)
|
|
error_message: Mapped[str | None] = mapped_column(Text, nullable=True, comment="处理失败原因")
|
|
width: Mapped[int | None] = mapped_column(Integer, nullable=True, comment="素材宽度")
|
|
height: Mapped[int | None] = mapped_column(Integer, nullable=True, comment="素材高度")
|
|
duration_seconds: Mapped[Decimal | None] = mapped_column(Numeric(10, 3), nullable=True, comment="视频时长,图片为空")
|
|
file_size_bytes: Mapped[int] = mapped_column(BigInteger, default=0, server_default="0", nullable=False, comment="原始文件大小")
|
|
watermarked_file_size_bytes: Mapped[int | None] = mapped_column(BigInteger, nullable=True, comment="水印后文件大小")
|
|
is_active: Mapped[bool] = mapped_column(Boolean, default=True, server_default="true", nullable=False, index=True, comment="是否前台展示")
|
|
sort_order: Mapped[int] = mapped_column(Integer, default=0, server_default="0", nullable=False, index=True, comment="排序,越小越靠前")
|
|
processed_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True, index=True, comment="处理完成时间")
|
|
created_by: Mapped[str | None] = mapped_column(String(32), nullable=True, index=True, comment="创建管理员ID")
|
|
updated_by: Mapped[str | None] = mapped_column(String(32), nullable=True, index=True, comment="更新管理员ID")
|