refactor: 重构查询参数处理逻辑,统一搜索参数处理

- 移除各模块查询schema中的自定义model_validator,统一通过search_to_dict处理搜索参数
- 为需要的字段添加json_schema_extra标记查询操作类型
- 重构base_crud的条件解析逻辑,支持直接处理普通字符串、数字类型参数
- 重构base_schema中的公共查询参数校验逻辑,简化时间范围和创建更新人参数处理
- 修复菜单查询的异步懒加载问题,添加多级预加载
- 调整日志打印配置,关闭uvicorn.access重复日志
- 修复前端路由跳转路径错误
- 调整弹窗宽度适配内容
- 修复测试环境限流器未注册问题
- 清理无用的导入和废弃函数
This commit is contained in:
zhangtao
2026-07-16 01:19:03 +08:00
parent 3f7d5aa4b9
commit f74b5f277e
63 changed files with 217 additions and 490 deletions
@@ -44,7 +44,7 @@ async def get_type_detail_controller(
async def get_type_list_controller(
auth: Annotated[AuthSchema, Security(AuthPermission(["module_system:dict_type:query"]))],
page: Annotated[PaginationQueryParam, Depends()],
search: Annotated[DictTypeQueryParam, Query(description="字典类型查询参数")],
search: Annotated[DictTypeQueryParam, Query()],
db: Annotated[AsyncSession, Depends(db_getter)],
) -> JSONResponse:
result_dict = await DictTypeService(auth, db).page(
@@ -117,7 +117,7 @@ async def batch_set_available_dict_type_controller(
@DictRouter.post("/type/export", summary="导出字典类型")
async def export_type_list_controller(
auth: Annotated[AuthSchema, Security(AuthPermission(["module_system:dict_type:export"]))],
search: Annotated[DictTypeQueryParam, Query(description="字典类型查询参数")],
search: Annotated[DictTypeQueryParam, Query()],
db: Annotated[AsyncSession, Depends(db_getter)],
) -> StreamingResponse:
# 获取全量数据并转为dict列表
@@ -146,7 +146,7 @@ async def get_data_detail_controller(
async def get_data_list_controller(
auth: Annotated[AuthSchema, Security(AuthPermission(["module_system:dict_data:query"]))],
page: Annotated[PaginationQueryParam, Depends()],
search: Annotated[DictDataQueryParam, Query(description="字典数据查询参数")],
search: Annotated[DictDataQueryParam, Query()],
db: Annotated[AsyncSession, Depends(db_getter)],
) -> JSONResponse:
order_by = [{"order": "asc"}]
@@ -209,7 +209,7 @@ async def batch_set_available_dict_data_controller(
async def export_data_list_controller(
auth: Annotated[AuthSchema, Security(AuthPermission(["module_system:dict_data:export"]))],
page: Annotated[PaginationQueryParam, Depends()],
search: Annotated[DictDataQueryParam, Query(description="字典数据查询参数")],
search: Annotated[DictDataQueryParam, Query()],
db: Annotated[AsyncSession, Depends(db_getter)],
) -> StreamingResponse:
result_dict_list = await DictDataService(auth, db).get_list(search=search, order_by=page.order_by)
@@ -8,7 +8,6 @@ from pydantic import (
model_validator,
)
from app.common.enums import QueueEnum
from app.core.base_schema import BaseQueryParam, BaseSchema, TenantByQueryParam, TenantBySchema, UserByQueryParam, UserBySchema
@@ -81,19 +80,9 @@ class DictTypeOutSchema(DictTypeCreateSchema, BaseSchema, UserBySchema, TenantBy
class DictTypeQueryParam(BaseQueryParam, UserByQueryParam, TenantByQueryParam):
"""字典类型查询参数"""
dict_name: str | tuple[str, str] | None = Field(default=None, description="字典名称", max_length=100)
dict_type: str | tuple[str, str] | None = Field(default=None, description="字典类型", max_length=100)
status: int | tuple[str, int] | None = Field(default=None, ge=0, le=1, description="状态(0:启动 1:停用)")
@model_validator(mode="after")
def validate_query_params(self) -> "DictTypeQueryParam":
if isinstance(self.dict_name, str):
self.dict_name = (QueueEnum.like.value, self.dict_name)
if isinstance(self.dict_type, str):
self.dict_type = (QueueEnum.eq.value, self.dict_type)
if isinstance(self.status, int):
self.status = (QueueEnum.eq.value, self.status)
return self
dict_name: str | None = Field(default=None, description="字典名称", max_length=100)
dict_type: str | None = Field(default=None, description="字典类型", max_length=100, json_schema_extra={"q": "eq"})
status: int | None = Field(default=None, ge=0, le=1, description="状态(0:启动 1:停用)")
class DictDataCreateSchema(BaseModel):
@@ -158,19 +147,7 @@ class DictDataOutSchema(DictDataCreateSchema, BaseSchema, UserBySchema, TenantBy
class DictDataQueryParam(BaseQueryParam, UserByQueryParam, TenantByQueryParam):
"""字典数据查询参数"""
dict_label: str | tuple[str, str] | None = Field(default=None, description="字典标签", max_length=100)
dict_type: str | tuple[str, str] | None = Field(default=None, description="字典类型", max_length=100)
dict_type_id: int | tuple[str, int] | None = Field(default=None, description="字典类型ID")
status: int | tuple[str, int] | None = Field(default=None, ge=0, le=1, description="状态(0:启动 1:停用)")
@model_validator(mode="after")
def validate_query_params(self) -> "DictDataQueryParam":
if isinstance(self.dict_label, str):
self.dict_label = (QueueEnum.like.value, self.dict_label)
if isinstance(self.dict_type, str):
self.dict_type = (QueueEnum.eq.value, self.dict_type)
if isinstance(self.dict_type_id, int):
self.dict_type_id = (QueueEnum.eq.value, self.dict_type_id)
if isinstance(self.status, int):
self.status = (QueueEnum.eq.value, self.status)
return self
dict_label: str | None = Field(default=None, description="字典标签", max_length=100)
dict_type: str | None = Field(default=None, description="字典类型", max_length=100, json_schema_extra={"q": "eq"})
dict_type_id: int | None = Field(default=None, description="字典类型ID")
status: int | None = Field(default=None, ge=0, le=1, description="状态(0:启动 1:停用)")