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
@@ -1,17 +1,12 @@
# -*- coding: utf-8 -*-
from typing import TYPE_CHECKING
from sqlalchemy import String, Boolean, Integer, ForeignKey
from sqlalchemy.orm import relationship, Mapped, mapped_column
from sqlalchemy import String, Boolean
from sqlalchemy.orm import Mapped, mapped_column
from app.core.base_model import ModelMixin, UserMixin, TenantMixin
if TYPE_CHECKING:
from app.api.v1.module_system.tenant.model import TenantModel
from app.api.v1.module_system.user.model import UserModel
from app.core.base_model import ModelMixin
class ParamsModel(ModelMixin, UserMixin, TenantMixin):
class ParamsModel(ModelMixin):
"""
参数配置表
@@ -38,32 +33,7 @@ class ParamsModel(ModelMixin, UserMixin, TenantMixin):
__tablename__: str = "system_param"
__table_args__: dict[str, str] = ({'comment': '系统参数表'})
# 覆盖TenantMixin的tenant_id为可选(支持系统级参数)
tenant_id: Mapped[int | None] = mapped_column( # type: ignore
Integer,
ForeignKey("system_tenant.id", ondelete="CASCADE"),
default=None,
nullable=True,
index=True,
comment="所属租户ID(NULL表示系统级参数,所有租户共享)"
)
config_name: Mapped[str] = mapped_column(String(500), nullable=False, comment='参数名称')
config_key: Mapped[str] = mapped_column(String(500), nullable=False, comment='参数键名')
config_value: Mapped[str | None] = mapped_column(String(500), comment='参数键值')
config_type: Mapped[bool] = mapped_column(Boolean, default=False, nullable=True, comment="系统内置(True:是 False:否)")
# 关联关系 (继承自UserMixin和TenantMixin)
tenant: Mapped["TenantModel | None"] = relationship(
foreign_keys="ParamsModel.tenant_id",
lazy="selectin"
)
created_by: Mapped["UserModel | None"] = relationship(
foreign_keys="ParamsModel.created_id",
lazy="selectin"
)
updated_by: Mapped["UserModel | None"] = relationship(
foreign_keys="ParamsModel.updated_id",
lazy="selectin"
)
@@ -232,7 +232,7 @@ class ParamsService:
'description': '备注',
'created_at': '创建时间',
'updated_at': '更新时间',
'creator_id': '创建者ID',
'created_id': '创建者ID',
'creator': '创建者',
}