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
@@ -25,7 +25,7 @@ _STATS_NS = "online_stats"
async def get_online_list_controller(
redis: Annotated[Redis, Depends(redis_getter)],
page: Annotated[PaginationQueryParam, Depends()],
search: Annotated[OnlineQueryParam, Query(description="在线用户查询参数")],
search: Annotated[OnlineQueryParam, Query()],
) -> JSONResponse:
result_dict_list = await OnlineService.get_online_list(redis=redis, search=search)
result_dict = await PaginationService.paginate(
@@ -1,8 +1,7 @@
from datetime import datetime
from pydantic import BaseModel, Field, model_validator
from pydantic import BaseModel, Field
from app.common.enums import QueueEnum
from app.core.base_schema import SessionInfoSchema
@@ -13,19 +12,9 @@ class OnlineOutSchema(SessionInfoSchema):
class OnlineQueryParam(BaseModel):
"""在线用户查询参数"""
name: str | tuple[str, str] | None = Field(None, description="登录名称")
ipaddr: str | tuple[str, str] | None = Field(None, description="登陆IP地址")
login_location: str | tuple[str, str] | None = Field(None, description="登录所属地")
@model_validator(mode="after")
def validate_query_params(self) -> "OnlineQueryParam":
if isinstance(self.name, str):
self.name = (QueueEnum.like.value, self.name)
if isinstance(self.ipaddr, str):
self.ipaddr = (QueueEnum.like.value, self.ipaddr)
if isinstance(self.login_location, str):
self.login_location = (QueueEnum.like.value, self.login_location)
return self
name: str | None = Field(None, description="登录名称")
ipaddr: str | None = Field(None, description="登陆IP地址")
login_location: str | None = Field(None, description="登录所属地")
class RecentLoginItem(BaseModel):
@@ -21,7 +21,7 @@ ResourceRouter = APIRouter(route_class=OperationLogRoute, prefix="/resource", ta
async def get_directory_list_controller(
request: Request,
page: Annotated[PaginationQueryParam, Depends()],
search: Annotated[ResourceSearchQueryParam, Query(description="资源查询参数")],
search: Annotated[ResourceSearchQueryParam, Query()],
) -> JSONResponse:
result_dict_list = await ResourceService.get_resources_list(search=search, base_url=str(request.base_url))
result_dict = await PaginationService.paginate(
@@ -111,7 +111,7 @@ async def create_directory_controller(
@ResourceRouter.post("/export", summary="导出资源列表", dependencies=[Security(AuthPermission(["module_monitor:resource:export"]))])
async def export_resource_list_controller(
request: Request,
search: Annotated[ResourceSearchQueryParam, Query(description="资源查询参数")],
search: Annotated[ResourceSearchQueryParam, Query()],
) -> StreamingResponse:
result_dict_list = await ResourceService.get_resources_list(search=search, base_url=str(request.base_url))
export_result = await ResourceService.export_resource(data_list=result_dict_list)
@@ -9,9 +9,6 @@ from pydantic import (
model_validator,
)
from app.common.enums import QueueEnum
class ResourceItemSchema(BaseModel):
"""资源项目模型"""
@@ -186,13 +183,7 @@ class ResourceCreateDirSchema(BaseModel):
class ResourceSearchQueryParam(BaseModel):
"""资源搜索查询参数"""
name: str | tuple[str, str] | None = Field(None, description="搜索关键词")
path: str | tuple[str, str] | None = Field(None, description="目录路径")
name: str | None = Field(None, description="搜索关键词")
path: str | None = Field(None, description="目录路径")
@model_validator(mode="after")
def validate_query_params(self) -> "ResourceSearchQueryParam":
if isinstance(self.name, str):
self.name = (QueueEnum.like.value, self.name)
if isinstance(self.path, str):
self.path = (QueueEnum.like.value, self.path)
return self