Files
wecom_it_smart_desk/backend/app/models/software_download.py
T

126 lines
3.8 KiB
Python
Raw Normal View History

# =============================================================================
# 企微IT智能服务台 — 软件下载入口模型
# =============================================================================
# 说明:对应数据库 software_downloads 表,存储软件下载链接
# 分类:办公/开发/安全/工具
# 在H5用户端右侧AI助手面板中展示,方便员工下载常用软件
# =============================================================================
import uuid
from datetime import datetime
from sqlalchemy import DateTime, Index, Integer, String, Text
from sqlalchemy.orm import Mapped, mapped_column
from app.database import Base
class SoftwareDownload(Base):
"""软件下载入口模型 — 对应 software_downloads 表。
存储公司常用软件的下载链接,
在H5用户端AI助手面板中按分类展示。
Attributes:
id: 下载入口唯一标识(UUID,数据库自动生成)
category: 分类(办公/开发/安全/工具)
name: 软件名称
version: 版本号
platform: 平台(Windows/Mac/Linux/全平台)
download_url: 下载链接
sort_order: 排序权重
created_at: 创建时间
updated_at: 更新时间
"""
# 表名(必须和架构文档 DDL 一致)
__tablename__ = "software_downloads"
# --------------------------------------------------------------------------
# 字段定义
# --------------------------------------------------------------------------
# 主键:UUIDPython端生成(兼容PostgreSQL和SQLite
id: Mapped[str] = mapped_column(
String(36),
primary_key=True,
default=lambda: str(uuid.uuid4()),
)
# 分类(按用途分类,方便在H5面板中折叠展示)
category: Mapped[str] = mapped_column(
String(64),
nullable=False,
comment="分类:办公/开发/安全/工具",
)
# 软件名称
name: Mapped[str] = mapped_column(
String(128),
nullable=False,
comment="软件名称",
)
# 版本号(如 "12.1"、"最新版"
version: Mapped[str] = mapped_column(
String(32),
nullable=False,
default="",
comment="版本号",
)
# 支持平台(如 "Windows/Mac"、"全平台"
platform: Mapped[str] = mapped_column(
String(32),
nullable=False,
default="",
comment="平台: Windows/Mac/Linux/全平台",
)
# 下载链接
download_url: Mapped[str] = mapped_column(
Text,
nullable=False,
comment="下载链接",
)
# 排序权重(同一分类内排序,数值越小越靠前)
sort_order: Mapped[int] = mapped_column(
Integer,
nullable=False,
default=0,
comment="排序权重",
)
# 创建时间
created_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True),
nullable=False,
default=datetime.now,
comment="创建时间",
)
# 更新时间
updated_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True),
nullable=False,
default=datetime.now,
onupdate=datetime.now,
comment="更新时间",
)
# --------------------------------------------------------------------------
# 索引定义(和架构文档 DDL 严格一致)
# --------------------------------------------------------------------------
__table_args__ = (
# 按分类查询(如获取所有"办公"分类的软件)
Index("idx_sd_category", "category"),
)
def __repr__(self) -> str:
"""下载入口对象的字符串表示,方便调试。"""
return (
f"<SoftwareDownload(id={self.id}, category={self.category}, "
f"name={self.name}, version={self.version})>"
)