From 4d31fe7a92c47738f7054fcc872e7e887eb38568 Mon Sep 17 00:00:00 2001 From: insistence <3055204202@qq.com> Date: Wed, 10 Jul 2024 20:50:39 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E5=9C=A8=E7=BA=BF?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E6=A8=A1=E5=9D=97service=E5=B1=82=E5=8F=8A?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/online_controller.py | 30 +++++++------------ .../module_admin/service/online_service.py | 6 ++-- 2 files changed, 13 insertions(+), 23 deletions(-) diff --git a/ruoyi-fastapi-backend/module_admin/controller/online_controller.py b/ruoyi-fastapi-backend/module_admin/controller/online_controller.py index 71531ea..be9669c 100644 --- a/ruoyi-fastapi-backend/module_admin/controller/online_controller.py +++ b/ruoyi-fastapi-backend/module_admin/controller/online_controller.py @@ -16,28 +16,18 @@ onlineController = APIRouter(prefix='/monitor/online', dependencies=[Depends(Log @onlineController.get("/list", response_model=PageResponseModel, dependencies=[Depends(CheckUserInterfaceAuth('monitor:online:list'))]) async def get_monitor_online_list(request: Request, online_page_query: OnlineQueryModel = Depends(OnlineQueryModel.as_query)): - try: - # 获取全量数据 - online_query_result = await OnlineService.get_online_list_services(request, online_page_query) - logger.info('获取成功') - return ResponseUtil.success(model_content=PageResponseModel(rows=online_query_result, total=len(online_query_result))) - except Exception as e: - logger.exception(e) - return ResponseUtil.error(msg=str(e)) + # 获取全量数据 + online_query_result = await OnlineService.get_online_list_services(request, online_page_query) + logger.info('获取成功') + + return ResponseUtil.success(model_content=PageResponseModel(rows=online_query_result, total=len(online_query_result))) @onlineController.delete("/{token_ids}", dependencies=[Depends(CheckUserInterfaceAuth('monitor:online:forceLogout'))]) @log_decorator(title='在线用户', business_type=BusinessType.FORCE) async def delete_monitor_online(request: Request, token_ids: str, query_db: AsyncSession = Depends(get_db)): - try: - delete_online = DeleteOnlineModel(tokenIds=token_ids) - delete_online_result = await OnlineService.delete_online_services(request, delete_online) - if delete_online_result.is_success: - logger.info(delete_online_result.message) - return ResponseUtil.success(msg=delete_online_result.message) - else: - logger.warning(delete_online_result.message) - return ResponseUtil.failure(msg=delete_online_result.message) - except Exception as e: - logger.exception(e) - return ResponseUtil.error(msg=str(e)) + delete_online = DeleteOnlineModel(tokenIds=token_ids) + delete_online_result = await OnlineService.delete_online_services(request, delete_online) + logger.info(delete_online_result.message) + + return ResponseUtil.success(msg=delete_online_result.message) diff --git a/ruoyi-fastapi-backend/module_admin/service/online_service.py b/ruoyi-fastapi-backend/module_admin/service/online_service.py index 968aacb..2b679f9 100644 --- a/ruoyi-fastapi-backend/module_admin/service/online_service.py +++ b/ruoyi-fastapi-backend/module_admin/service/online_service.py @@ -3,6 +3,7 @@ from jose import jwt from config.env import JwtConfig, RedisInitKeyConfig from module_admin.entity.vo.online_vo import * from module_admin.entity.vo.common_vo import CrudResponseModel +from exceptions.exception import ServiceException from utils.common_util import CamelCaseUtil @@ -65,7 +66,6 @@ class OnlineService: token_id_list = page_object.token_ids.split(',') for token_id in token_id_list: await request.app.state.redis.delete(f"{RedisInitKeyConfig.ACCESS_TOKEN.get('key')}:{token_id}") - result = dict(is_success=True, message='强退成功') + return CrudResponseModel(is_success=True, message='强退成功') else: - result = dict(is_success=False, message='传入session_id为空') - return CrudResponseModel(**result) + raise ServiceException(message='传入session_id为空')