mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-22 21:06:32 +00:00
这是一次综合性的重构更新,包含以下主要变更: 1. 升级Python版本到3.12,更新依赖配置 2. 替换旧的.j2模板为.jinja2格式,新增代码生成模板 3. 重构权限过滤策略,更新权限枚举与模型配置 4. 移除Prefect依赖,替换为自研拓扑并行执行引擎 5. 重构认证与上下文管理,拆分租户/请求上下文 6. 简化响应模型、CRUD与服务层代码 7. 清理废弃的支付网关模块,重构订单定时任务 8. 更新在线用户、监控等模块的接口与路由 9. 优化邮件模板与工具类,新增邮件模板文件 10. 修复数据库会话配置与类型提示
131 lines
4.7 KiB
Python
131 lines
4.7 KiB
Python
from typing import Annotated
|
|
|
|
from fastapi import APIRouter, Body, Depends, Path
|
|
from fastapi.responses import JSONResponse, StreamingResponse
|
|
from fastapi_cache import FastAPICache
|
|
from fastapi_cache.decorator import cache
|
|
|
|
from app.common.response import ResponseSchema, StreamResponse, SuccessResponse
|
|
from app.core.base_params import PaginationQueryParam
|
|
from app.core.base_schema import AuthSchema, BatchSetAvailable, PageResultSchema
|
|
from app.core.dependencies import AuthPermission
|
|
from app.core.router_class import OperationLogRoute
|
|
from app.utils.common_util import bytes2file_response
|
|
|
|
from .schema import (
|
|
PositionCreateSchema,
|
|
PositionOutSchema,
|
|
PositionQueryParam,
|
|
PositionUpdateSchema,
|
|
)
|
|
from .service import PositionService
|
|
|
|
PositionRouter = APIRouter(route_class=OperationLogRoute, prefix="/position", tags=["系统管理", "岗位管理"])
|
|
|
|
_POS_NS = "position"
|
|
|
|
@PositionRouter.get(
|
|
"/list",
|
|
summary="查询岗位",
|
|
response_model=ResponseSchema[PageResultSchema[PositionOutSchema]],
|
|
)
|
|
@cache(expire=300, namespace=_POS_NS)
|
|
async def get_obj_list_controller(
|
|
page: Annotated[PaginationQueryParam, Depends()],
|
|
search: Annotated[PositionQueryParam, Depends()],
|
|
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_system:position:query"]))],
|
|
) -> JSONResponse:
|
|
order_by = [{"order": "asc"}]
|
|
if page.order_by:
|
|
order_by = page.order_by
|
|
result_dict = await PositionService(auth).page(
|
|
page_no=page.page_no,
|
|
page_size=page.page_size,
|
|
search=search,
|
|
order_by=order_by,
|
|
)
|
|
return SuccessResponse(data=result_dict, msg="查询岗位列表成功")
|
|
|
|
@PositionRouter.get(
|
|
"/detail/{id}",
|
|
summary="查询岗位详情",
|
|
response_model=ResponseSchema[PositionOutSchema],
|
|
)
|
|
async def get_obj_detail_controller(
|
|
id: Annotated[int, Path(description="岗位ID")],
|
|
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_system:position:detail"]))],
|
|
) -> JSONResponse:
|
|
result_dict = await PositionService(auth).detail(id=id)
|
|
return SuccessResponse(data=result_dict, msg="获取岗位详情成功")
|
|
|
|
@PositionRouter.post(
|
|
"/create",
|
|
summary="创建岗位",
|
|
response_model=ResponseSchema[PositionOutSchema],
|
|
)
|
|
async def create_obj_controller(
|
|
data: PositionCreateSchema,
|
|
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_system:position:create"]))],
|
|
) -> JSONResponse:
|
|
result_dict = await PositionService(auth).create(data=data)
|
|
await FastAPICache.clear(namespace=_POS_NS)
|
|
return SuccessResponse(data=result_dict, msg="创建岗位成功")
|
|
|
|
@PositionRouter.put(
|
|
"/update/{id}",
|
|
summary="修改岗位",
|
|
response_model=ResponseSchema[PositionOutSchema],
|
|
)
|
|
async def update_obj_controller(
|
|
data: PositionUpdateSchema,
|
|
id: Annotated[int, Path(description="岗位ID")],
|
|
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_system:position:update"]))],
|
|
) -> JSONResponse:
|
|
result_dict = await PositionService(auth).update(id=id, data=data)
|
|
await FastAPICache.clear(namespace=_POS_NS)
|
|
return SuccessResponse(data=result_dict, msg="修改岗位成功")
|
|
|
|
@PositionRouter.delete(
|
|
"/delete",
|
|
summary="删除岗位",
|
|
response_model=ResponseSchema[None],
|
|
)
|
|
async def delete_obj_controller(
|
|
ids: Annotated[list[int], Body(description="ID列表")],
|
|
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_system:position:delete"]))],
|
|
) -> JSONResponse:
|
|
await PositionService(auth).delete(ids=ids)
|
|
await FastAPICache.clear(namespace=_POS_NS)
|
|
return SuccessResponse(msg="删除岗位成功")
|
|
|
|
@PositionRouter.patch(
|
|
"/status/batch",
|
|
summary="批量修改岗位状态",
|
|
response_model=ResponseSchema[None],
|
|
)
|
|
async def batch_set_available_obj_controller(
|
|
data: BatchSetAvailable,
|
|
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_system:position:patch"]))],
|
|
) -> JSONResponse:
|
|
await PositionService(auth).set_available(data=data)
|
|
await FastAPICache.clear(namespace=_POS_NS)
|
|
return SuccessResponse(msg="批量修改岗位状态成功")
|
|
|
|
@PositionRouter.get(
|
|
"/export",
|
|
summary="导出岗位",
|
|
response_model=ResponseSchema[None],
|
|
)
|
|
async def export_obj_list_controller(
|
|
search: Annotated[PositionQueryParam, Depends()],
|
|
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_system:position:export"]))],
|
|
) -> StreamingResponse:
|
|
position_query_result = await PositionService(auth).list(search=search)
|
|
position_export_result = PositionService.export_list(position_list=position_query_result)
|
|
|
|
return StreamResponse(
|
|
data=bytes2file_response(position_export_result),
|
|
media_type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
headers={"Content-Disposition": "attachment; filename=position.xlsx"},
|
|
)
|