refactor: 大规模代码整理与功能优化

1. 重构后端API路由、CRUD与模块结构,整合日志管理,移除废弃demo代码
2. 优化前端组件类型定义、样式与路由配置,修复权限判断逻辑
3. 调整默认排序规则、滚动条样式与工具类函数,更新依赖与配置文件
4. 修复多处类型不匹配与默认值问题,完善表单与菜单验证逻辑
This commit is contained in:
zhangtao
2026-06-17 01:56:31 +08:00
parent 17b3cd0a4c
commit 73f2823692
500 changed files with 40763 additions and 26616 deletions
@@ -4,29 +4,27 @@ from fastapi import APIRouter, Body, Depends, Path
from fastapi.responses import JSONResponse, StreamingResponse
from redis.asyncio.client import Redis
from app.api.v1.module_system.auth.schema import AuthSchema
from app.common.response import ResponseSchema, StreamResponse, SuccessResponse
from app.core.base_params import PaginationQueryParam
from app.core.base_schema import AuthSchema, PageResultSchema
from app.core.dependencies import AuthPermission, redis_getter
from app.core.logger import log
from app.core.router_class import OperationLogRoute
from app.utils.common_util import bytes2file_response
from .schema import ParamsCreateSchema, ParamsOutSchema, ParamsQueryParam, ParamsUpdateSchema
from .service import ParamsService
ParamsRouter = APIRouter(route_class=OperationLogRoute, prefix="/param", tags=["参数管理"])
ParamsRouter = APIRouter(route_class=OperationLogRoute, prefix="/param", tags=["系统管理/参数管理"])
@ParamsRouter.get(
"/detail/{id}",
summary="获取参数详情",
description="获取参数详情",
response_model=ResponseSchema[ParamsOutSchema],
)
async def get_type_detail_controller(
id: Annotated[int, Path(description="参数ID")],
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_system:param:detail"]))],
auth: Annotated[AuthSchema, Depends(AuthPermission(['module_system:param:detail']))],
) -> JSONResponse:
"""
获取参数详情
@@ -39,19 +37,17 @@ async def get_type_detail_controller(
- JSONResponse: 包含参数详情的 JSON 响应
"""
result_dict = await ParamsService.get_obj_detail_service(id=id, auth=auth)
log.info(f"获取参数详情成功 {id}")
return SuccessResponse(data=result_dict, msg="获取参数详情成功")
@ParamsRouter.get(
"/key/{config_key}",
summary="根据配置键获取参数详情",
description="根据配置键获取参数详情",
response_model=ResponseSchema[ParamsOutSchema],
)
async def get_obj_by_key_controller(
config_key: Annotated[str, Path(description="配置键")],
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_system:param:query"]))],
auth: Annotated[AuthSchema, Depends(AuthPermission(['module_system:param:query']))],
) -> JSONResponse:
"""
根据配置键获取参数详情
@@ -64,19 +60,17 @@ async def get_obj_by_key_controller(
- JSONResponse: 包含参数详情的 JSON 响应
"""
result_dict = await ParamsService.get_obj_by_key_service(config_key=config_key, auth=auth)
log.info(f"根据配置键获取参数详情成功 {config_key}")
return SuccessResponse(data=result_dict, msg="根据配置键获取参数详情成功")
@ParamsRouter.get(
"/value/{config_key}",
summary="根据配置键获取参数值",
description="根据配置键获取参数值",
response_model=ResponseSchema[ParamsOutSchema],
)
async def get_config_value_by_key_controller(
config_key: Annotated[str, Path(description="配置键")],
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_system:param:query"]))],
auth: Annotated[AuthSchema, Depends(AuthPermission(['module_system:param:query']))],
) -> JSONResponse:
"""
根据配置键获取参数值
@@ -91,18 +85,16 @@ async def get_config_value_by_key_controller(
result_value = await ParamsService.get_config_value_by_key_service(
config_key=config_key, auth=auth
)
log.info(f"根据配置键获取参数值成功 {config_key}")
return SuccessResponse(data=result_value, msg="根据配置键获取参数值成功")
@ParamsRouter.get(
"/list",
summary="获取参数列表",
description="获取参数列表",
response_model=ResponseSchema[list[ParamsOutSchema]],
response_model=ResponseSchema[PageResultSchema[ParamsOutSchema]],
)
async def get_obj_list_controller(
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_system:param:query"]))],
auth: Annotated[AuthSchema, Depends(AuthPermission(['module_system:param:query']))],
page: Annotated[PaginationQueryParam, Depends()],
search: Annotated[ParamsQueryParam, Depends()],
) -> JSONResponse:
@@ -124,20 +116,18 @@ async def get_obj_list_controller(
search=search,
order_by=page.order_by,
)
log.info("获取参数列表成功")
return SuccessResponse(data=result_dict, msg="查询参数列表成功")
@ParamsRouter.post(
"/create",
summary="创建参数",
description="创建参数",
response_model=ResponseSchema[ParamsOutSchema],
)
async def create_obj_controller(
data: ParamsCreateSchema,
redis: Annotated[Redis, Depends(redis_getter)],
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_system:param:create"]))],
auth: Annotated[AuthSchema, Depends(AuthPermission(['module_system:param:create']))],
) -> JSONResponse:
"""
创建参数
@@ -151,21 +141,19 @@ async def create_obj_controller(
- JSONResponse: 包含创建参数结果的 JSON 响应
"""
result_dict = await ParamsService.create_obj_service(auth=auth, redis=redis, data=data)
log.info(f"创建参数成功: {result_dict}")
return SuccessResponse(data=result_dict, msg="创建参数成功")
@ParamsRouter.put(
"/update/{id}",
summary="修改参数",
description="修改参数",
response_model=ResponseSchema[ParamsOutSchema],
)
async def update_objs_controller(
data: ParamsUpdateSchema,
id: Annotated[int, Path(description="参数ID")],
redis: Annotated[Redis, Depends(redis_getter)],
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_system:param:update"]))],
auth: Annotated[AuthSchema, Depends(AuthPermission(['module_system:param:update']))],
) -> JSONResponse:
"""
修改参数
@@ -180,20 +168,18 @@ async def update_objs_controller(
- JSONResponse: 包含修改参数结果的 JSON 响应
"""
result_dict = await ParamsService.update_obj_service(auth=auth, redis=redis, id=id, data=data)
log.info(f"更新参数成功 {result_dict}")
return SuccessResponse(data=result_dict, msg="更新参数成功")
@ParamsRouter.delete(
"/delete",
summary="删除参数",
description="删除参数",
response_model=ResponseSchema[ParamsOutSchema],
)
async def delete_obj_controller(
redis: Annotated[Redis, Depends(redis_getter)],
ids: Annotated[list[int], Body(description="ID列表")],
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_system:param:delete"]))],
auth: Annotated[AuthSchema, Depends(AuthPermission(['module_system:param:delete']))],
) -> JSONResponse:
"""
删除参数
@@ -207,20 +193,18 @@ async def delete_obj_controller(
- JSONResponse: 包含删除参数结果的 JSON 响应
"""
await ParamsService.delete_obj_service(auth=auth, redis=redis, ids=ids)
log.info(f"删除参数成功: {ids}")
return SuccessResponse(msg="删除参数成功")
@ParamsRouter.patch(
"/status/batch",
summary="批量设置参数状态",
description="批量设置参数状态",
response_model=ResponseSchema,
)
async def batch_set_status_controller(
ids: Annotated[list[int], Body(description="参数ID列表")],
status: Annotated[str, Body(description="状态值")],
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_system:param:patch"]))],
auth: Annotated[AuthSchema, Depends(AuthPermission(['module_system:param:patch']))],
) -> JSONResponse:
"""
批量设置参数状态
@@ -234,19 +218,17 @@ async def batch_set_status_controller(
- JSONResponse: 包含批量设置参数状态结果的 JSON 响应
"""
await ParamsService.batch_set_status_service(auth=auth, ids=ids, status=status)
log.info(f"批量设置参数状态成功: ids={ids}, status={status}")
return SuccessResponse(msg="批量设置参数状态成功")
@ParamsRouter.get(
"/export",
summary="导出参数",
description="导出参数列表",
response_model=ResponseSchema[None],
)
async def export_obj_list_controller(
search: Annotated[ParamsQueryParam, Depends()],
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_system:param:export"]))],
auth: Annotated[AuthSchema, Depends(AuthPermission(['module_system:param:export']))],
) -> StreamingResponse:
"""
导出参数
@@ -259,8 +241,8 @@ async def export_obj_list_controller(
- StreamingResponse: 包含导出参数的 Excel 文件流响应
"""
result_dict_list = await ParamsService.get_obj_list_service(search=search, auth=auth)
export_result = await ParamsService.export_obj_service(data_list=result_dict_list)
log.info("导出参数成功")
export_data = [item.model_dump() for item in result_dict_list]
export_result = await ParamsService.export_obj_service(data_list=export_data)
return StreamResponse(
data=bytes2file_response(export_result),
@@ -272,7 +254,6 @@ async def export_obj_list_controller(
@ParamsRouter.get(
"/info",
summary="获取初始化缓存参数",
description="获取初始化缓存参数",
response_model=ResponseSchema[list[ParamsOutSchema]],
)
async def get_init_obj_controller(
@@ -288,5 +269,4 @@ async def get_init_obj_controller(
- JSONResponse: 获取初始化缓存参数的 JSON 响应
"""
result_dict = await ParamsService.get_init_config_service(redis=redis, tenant_id=1)
log.info(f"获取初始化缓存参数成功 {result_dict}")
return SuccessResponse(data=result_dict, msg="获取初始化缓存参数成功")