mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-21 12:52:26 +00:00
refactor: 重构项目模块结构与代码细节优化
1. 调整后端模块路由与插件文件结构,迁移部分模块代码至api/v1目录 2. 优化代码注释格式与文档字符串,简化冗余代码 3. 添加监控仪表盘、工单评论等新模块功能 4. 修复前端部分组件交互逻辑与类型定义 5. 清理冗余的初始化数据与废弃配置文件 6. 新增租户注册表单字段与国际化支持 7. 优化HTTP请求拦截器与快捷键功能
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
from typing import Annotated
|
||||
|
||||
from fastapi import APIRouter, Body, Depends, Path, Query
|
||||
from fastapi import APIRouter, Body, Path, Query, Security, status
|
||||
from fastapi.responses import JSONResponse
|
||||
from fastapi_cache import FastAPICache
|
||||
from fastapi_cache.decorator import cache
|
||||
@@ -17,55 +17,61 @@ DeptRouter = APIRouter(route_class=OperationLogRoute, prefix="/dept", tags=["部
|
||||
|
||||
_DEPT_NS = "dept"
|
||||
|
||||
|
||||
@DeptRouter.get("/tree", summary="查询部门树", response_model=ResponseSchema[list[DeptOutSchema]])
|
||||
@cache(expire=300, namespace=_DEPT_NS)
|
||||
async def get_dept_tree_controller(
|
||||
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_system:dept:query"]))],
|
||||
auth: Annotated[AuthSchema, Security(AuthPermission(["module_system:dept:query"]))],
|
||||
search: Annotated[DeptQueryParam, Query(description="部门查询参数")],
|
||||
) -> JSONResponse:
|
||||
order_by = [{"order": "asc"}]
|
||||
result_dict_tree = await DeptService(auth).tree(search=search, order_by=order_by)
|
||||
return SuccessResponse(data=result_dict_tree, msg="查询部门树成功")
|
||||
|
||||
|
||||
@DeptRouter.get("/detail/{id}", summary="查询部门详情", response_model=ResponseSchema[DeptOutSchema])
|
||||
async def get_obj_detail_controller(
|
||||
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_system:dept:detail"]))],
|
||||
id: Annotated[int, Path(description="部门ID")],
|
||||
auth: Annotated[AuthSchema, Security(AuthPermission(["module_system:dept:detail"]))],
|
||||
id: Annotated[int, Path(description="部门ID", ge=1)],
|
||||
) -> JSONResponse:
|
||||
result_dict = await DeptService(auth).detail(id=id)
|
||||
return SuccessResponse(data=result_dict, msg="查询部门详情成功")
|
||||
|
||||
@DeptRouter.post("/create", summary="创建部门", response_model=ResponseSchema[DeptOutSchema])
|
||||
|
||||
@DeptRouter.post("/create", status_code=status.HTTP_201_CREATED, summary="创建部门", response_model=ResponseSchema[DeptOutSchema])
|
||||
async def create_obj_controller(
|
||||
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_system:dept:create"]))],
|
||||
auth: Annotated[AuthSchema, Security(AuthPermission(["module_system:dept:create"]))],
|
||||
data: Annotated[DeptCreateSchema, Body(description="部门创建参数")],
|
||||
) -> JSONResponse:
|
||||
result_dict = await DeptService(auth).create(data=data)
|
||||
await FastAPICache.clear(namespace=_DEPT_NS)
|
||||
return SuccessResponse(data=result_dict, msg="创建部门成功")
|
||||
|
||||
|
||||
@DeptRouter.put("/update/{id}", summary="修改部门", response_model=ResponseSchema[DeptOutSchema])
|
||||
async def update_obj_controller(
|
||||
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_system:dept:update"]))],
|
||||
id: Annotated[int, Path(description="部门ID")],
|
||||
auth: Annotated[AuthSchema, Security(AuthPermission(["module_system:dept:update"]))],
|
||||
id: Annotated[int, Path(description="部门ID", ge=1)],
|
||||
data: Annotated[DeptUpdateSchema, Body(description="部门修改参数")],
|
||||
) -> JSONResponse:
|
||||
result_dict = await DeptService(auth).update(id=id, data=data)
|
||||
await FastAPICache.clear(namespace=_DEPT_NS)
|
||||
return SuccessResponse(data=result_dict, msg="修改部门成功")
|
||||
|
||||
|
||||
@DeptRouter.delete("/delete", summary="删除部门", response_model=ResponseSchema[None])
|
||||
async def delete_obj_controller(
|
||||
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_system:dept:delete"]))],
|
||||
auth: Annotated[AuthSchema, Security(AuthPermission(["module_system:dept:delete"]))],
|
||||
ids: Annotated[list[int], Body(description="ID列表")],
|
||||
) -> JSONResponse:
|
||||
await DeptService(auth).delete(ids=ids)
|
||||
await FastAPICache.clear(namespace=_DEPT_NS)
|
||||
return SuccessResponse(msg="删除部门成功")
|
||||
|
||||
|
||||
@DeptRouter.patch("/status/batch", summary="批量修改部门状态", response_model=ResponseSchema[None])
|
||||
async def batch_set_available_obj_controller(
|
||||
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_system:dept:patch"]))],
|
||||
auth: Annotated[AuthSchema, Security(AuthPermission(["module_system:dept:patch"]))],
|
||||
data: Annotated[BatchSetAvailable, Body(description="状态设置")],
|
||||
) -> JSONResponse:
|
||||
await DeptService(auth).batch_set_available(data=data)
|
||||
|
||||
@@ -12,8 +12,7 @@ if TYPE_CHECKING:
|
||||
|
||||
|
||||
class DeptModel(ModelMixin, TenantMixin, UserMixin):
|
||||
"""
|
||||
部门模型
|
||||
"""部门模型
|
||||
"""
|
||||
|
||||
__tablename__: str = "sys_dept"
|
||||
|
||||
@@ -62,12 +62,12 @@ class DeptTreeOutSchema(DeptOutSchema):
|
||||
class DeptQueryParam(BaseQueryParam, UserByQueryParam, TenantByQueryParam):
|
||||
"""部门管理查询参数"""
|
||||
|
||||
name: str | None = Field(None, description="部门名称")
|
||||
status: int | None = Field(None, ge=0, le=1, description="状态(0:启动 1:停用)")
|
||||
name: str | tuple[str, str] | None = Field(None, description="部门名称")
|
||||
status: int | tuple[str, int] | None = Field(None, ge=0, le=1, description="状态(0:启动 1:停用)")
|
||||
|
||||
@model_validator(mode="after")
|
||||
def validate_query_params(self) -> "DeptQueryParam":
|
||||
if self.name:
|
||||
if isinstance(self.name, str):
|
||||
self.name = (QueueEnum.like.value, self.name)
|
||||
if isinstance(self.status, int):
|
||||
self.status = (QueueEnum.eq.value, self.status)
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
from app.core.base_schema import AuthSchema, BatchSetAvailable
|
||||
from app.core.exceptions import CustomException
|
||||
from app.utils.common_util import (
|
||||
@@ -19,8 +18,7 @@ from .schema import (
|
||||
|
||||
|
||||
class DeptService:
|
||||
"""
|
||||
部门管理服务
|
||||
"""部门管理服务
|
||||
|
||||
提供部门 CRUD、树形结构查询、级联启/禁用、租户配额检查等业务能力。
|
||||
"""
|
||||
@@ -57,7 +55,10 @@ class DeptService:
|
||||
# 检查租户配额
|
||||
from app.api.v1.module_platform.tenant.service import TenantService
|
||||
|
||||
await TenantService(self.auth).check_quota(self.auth.tenant_id, "dept")
|
||||
user = self.auth.user
|
||||
if not user:
|
||||
raise CustomException(msg="未登录")
|
||||
await TenantService(self.auth).check_quota(user.tenant_id, "dept")
|
||||
|
||||
dept = await DeptCRUD(self.auth).create(data=data)
|
||||
return DeptOutSchema.model_validate(dept)
|
||||
@@ -90,7 +91,7 @@ class DeptService:
|
||||
child_id_map = get_child_id_map(model_list=all_depts)
|
||||
|
||||
for pid in ids:
|
||||
if pid in child_id_map and child_id_map[pid]:
|
||||
if child_id_map.get(pid):
|
||||
raise CustomException(msg="存在子部门,不允许删除父部门")
|
||||
|
||||
await DeptCRUD(self.auth).delete(ids=ids)
|
||||
|
||||
Reference in New Issue
Block a user