refactor: 统一将creator_id重命名为created_id并优化模型关系

feat: 新增系统租户和用户初始化数据

style: 优化代码注释和格式

fix: 修复数据权限检查逻辑中的created_id字段判断

perf: 移除不必要的模型关系以提升性能

docs: 更新初始化数据的描述信息

chore: 清理废弃文件和冗余代码
This commit is contained in:
zhangtao
2025-11-24 01:02:27 +08:00
parent 9a39a64faf
commit c0d32a7eec
59 changed files with 581 additions and 867 deletions
@@ -11,8 +11,6 @@ if TYPE_CHECKING:
from app.api.v1.module_system.dept.model import DeptModel
from app.api.v1.module_system.position.model import PositionModel
from app.api.v1.module_system.role.model import RoleModel
from app.api.v1.module_system.tenant.model import TenantModel
from app.api.v1.module_system.customer.model import CustomerModel
class UserRolesModel(MappedBase):
@@ -120,7 +118,6 @@ class UserModel(ModelMixin, UserMixin, TenantMixin, CustomerMixin):
user_type: Mapped[int] = mapped_column(Integer, nullable=False, default=1, comment="用户类型(0:系统用户 1:租户用户 2:客户用户)")
salt: Mapped[str | None] = mapped_column(String(255), nullable=True, comment="加密盐")
# 部门关联
dept_id: Mapped[int | None] = mapped_column(
Integer,
ForeignKey('system_dept.id', ondelete="SET NULL", onupdate="CASCADE"),
@@ -128,8 +125,6 @@ class UserModel(ModelMixin, UserMixin, TenantMixin, CustomerMixin):
index=True,
comment="部门ID"
)
# 关联关系 (继承自UserMixin, TenantMixin, CustomerMixin)
dept: Mapped["DeptModel | None"] = relationship(
back_populates="users",
foreign_keys=[dept_id],
@@ -145,24 +140,3 @@ class UserModel(ModelMixin, UserMixin, TenantMixin, CustomerMixin):
back_populates="users",
lazy="selectin"
)
tenant: Mapped["TenantModel"] = relationship(
back_populates="users",
foreign_keys="UserModel.tenant_id",
lazy="selectin"
)
customer: Mapped["CustomerModel | None"] = relationship(
back_populates="users",
foreign_keys="UserModel.customer_id",
lazy="selectin"
)
created_by: Mapped["UserModel | None"] = relationship(
foreign_keys="UserModel.created_id",
remote_side="UserModel.id",
lazy="selectin"
)
updated_by: Mapped["UserModel | None"] = relationship(
foreign_keys="UserModel.updated_id",
remote_side="UserModel.id",
lazy="selectin"
)
@@ -30,7 +30,7 @@ class UserQueryParam:
# 精确查询字段
self.dept_id = dept_id
self.creator_id = creator
self.created_id = creator
self.status = status
# 时间范围查询
@@ -41,7 +41,7 @@ class UserRegisterSchema(BaseModel):
username: str = Field(..., max_length=32, description="账号")
password: str = Field(..., max_length=128, description="密码哈希值")
role_ids: Optional[List[int]] = Field(default=[1], description='角色ID')
creator_id: Optional[int] = Field(default=1, description='创建人ID')
created_id: Optional[int] = Field(default=1, description='创建人ID')
description: Optional[str] = Field(default=None, max_length=255, description="备注")
@field_validator("mobile")