Files
FastapiAdmin/backend/app/api/v1/module_system/tenant/model.py
T
zhangtao 329dd791d2 refactor(tenant): 移除租户工具模块并优化相关代码
重构租户模块,删除不再使用的工具类文件,包括查询、写入、缓存键等功能
优化模型字段格式和CRUD方法顺序,调整前端暗黑模式颜色变量
简化租户服务逻辑,移除平台租户管理校验,改进初始管理员创建流程
2026-04-08 00:06:20 +08:00

40 lines
1.5 KiB
Python

from datetime import datetime
from sqlalchemy import DateTime, String
from sqlalchemy.orm import Mapped, mapped_column, validates
from app.common.enums import PermissionFilterStrategy
from app.core.base_model import ModelMixin
class TenantModel(ModelMixin):
"""
租户模型
- 系统租户(id=1):平台管理,由超级管理员维护
- 普通租户(id>1):独立组织数据,通过业务表的 tenant_id 隔离
"""
__tablename__: str = "sys_tenant"
__table_args__: dict[str, str] = {"comment": "租户表"}
__permission_strategy__: PermissionFilterStrategy = PermissionFilterStrategy.DATA_SCOPE
name: Mapped[str] = mapped_column(String(100), nullable=False, unique=True, comment="租户名称")
code: Mapped[str] = mapped_column(String(100), nullable=False, unique=True, comment="租户编码")
start_time: Mapped[datetime | None] = mapped_column(DateTime, nullable=True, default=None, comment="开始时间")
end_time: Mapped[datetime | None] = mapped_column(DateTime, nullable=True, default=None, comment="结束时间")
@validates("name")
def validate_name(self, key: str, name: str) -> str:
if not name or not name.strip():
raise ValueError("名称不能为空")
return name
@validates("code")
def validate_code(self, key: str, code: str) -> str:
if not code or not code.strip():
raise ValueError("编码不能为空")
if not code.isalnum():
raise ValueError("编码只能包含字母和数字")
return code