mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-21 12:52:26 +00:00
refactor: 简化AuthPermission调用方式 style: 更新日志输出格式和内容 fix: 修复BaseSchema字段可选性 perf: 优化数据库连接日志显示 chore: 更新requirements.txt添加sqlglot依赖 docs: 更新配置注释说明
76 lines
3.2 KiB
Python
76 lines
3.2 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
from fastapi import APIRouter, Body, Depends, Path, Query
|
|
from fastapi.responses import JSONResponse, StreamingResponse
|
|
|
|
from app.common.request import PaginationService
|
|
from app.common.response import SuccessResponse, StreamResponse
|
|
from app.utils.common_util import bytes2file_response
|
|
from app.core.router_class import OperationLogRoute
|
|
from app.core.dependencies import AuthPermission
|
|
from app.core.base_params import PaginationQueryParam
|
|
from app.core.logger import logger
|
|
from ..auth.schema import AuthSchema
|
|
from .param import OperationLogQueryParam
|
|
from .service import OperationLogService
|
|
|
|
|
|
LogRouter = APIRouter(route_class=OperationLogRoute, prefix="/log", tags=["日志管理"])
|
|
|
|
|
|
@LogRouter.get("/list", summary="查询日志", description="查询日志")
|
|
async def get_obj_list_controller(
|
|
page: PaginationQueryParam = Depends(),
|
|
search: OperationLogQueryParam = Depends(),
|
|
auth: AuthSchema = Depends(AuthPermission(["system:log:query"]))
|
|
) -> JSONResponse:
|
|
""" 查询日志 """
|
|
order_by = [{"created_at": "desc"}]
|
|
if page.order_by:
|
|
order_by = page.order_by
|
|
result_dict_list = await OperationLogService.get_log_list_service(search=search, auth=auth, order_by=order_by)
|
|
result_dict = await PaginationService.paginate(data_list= result_dict_list, page_no= page.page_no, page_size = page.page_size)
|
|
logger.info(f"查询日志成功")
|
|
return SuccessResponse(data=result_dict, msg="查询日志成功")
|
|
|
|
|
|
@LogRouter.get("/detail/{id}", summary="日志详情", description="日志详情")
|
|
async def get_obj_detail_controller(
|
|
id: int = Path(..., description="操作日志ID"),
|
|
auth: AuthSchema = Depends(AuthPermission(["system:log:query"]))
|
|
) -> JSONResponse:
|
|
""" 详情日志 """
|
|
result_dict = await OperationLogService.get_log_detail_service(id=id, auth=auth)
|
|
logger.info(f"查询日志成功 {id}")
|
|
return SuccessResponse(data=result_dict, msg="获取日志详情成功")
|
|
|
|
|
|
@LogRouter.delete("/delete", summary="删除日志", description="删除日志")
|
|
async def delete_obj_log_controller(
|
|
ids: list[int] = Body(..., description="ID列表"),
|
|
auth: AuthSchema = Depends(AuthPermission(["system:log:delete"]))
|
|
) -> JSONResponse:
|
|
""" 删除日志 """
|
|
await OperationLogService.delete_log_service(ids=ids, auth=auth)
|
|
logger.info(f"删除日志成功 {ids}")
|
|
return SuccessResponse(msg="删除日志成功")
|
|
|
|
|
|
@LogRouter.post("/export", summary="导出日志", description="导出日志")
|
|
async def export_obj_list_controller(
|
|
search: OperationLogQueryParam = Depends(),
|
|
auth: AuthSchema = Depends(AuthPermission(["system:log:export"]))
|
|
) -> StreamingResponse:
|
|
""" 导出日志 """
|
|
operation_log_list = await OperationLogService.get_log_list_service(search=search, auth=auth)
|
|
operation_log_export_result = await OperationLogService.export_log_list_service(operation_log_list=operation_log_list)
|
|
logger.info('导出日志成功')
|
|
|
|
return StreamResponse(
|
|
data=bytes2file_response(operation_log_export_result),
|
|
media_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
headers = {
|
|
'Content-Disposition': 'attachment; filename=log.xlsx'
|
|
}
|
|
)
|