mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-20 20:39:55 +00:00
feat(system): 优化删除操作并添加清除在线用户功能
- 重构了多个模块的删除操作,支持批量删除 - 在线监控模块增加了清除所有在线用户的功能 - 优化了前端API接口,提高了可维护性
This commit is contained in:
@@ -43,7 +43,7 @@ async def get_online_list_controller(
|
||||
summary="强制下线",
|
||||
description="强制下线"
|
||||
)
|
||||
async def delete__online_controller(
|
||||
async def delete_online_controller(
|
||||
session_id: str = Body(..., description="会话编号"),
|
||||
redis: Redis = Depends(redis_getter),
|
||||
)->JSONResponse:
|
||||
@@ -53,4 +53,21 @@ async def delete__online_controller(
|
||||
return SuccessResponse(msg="强制下线成功")
|
||||
else:
|
||||
logger.info("强制下线失败")
|
||||
return ErrorResponse(msg="强制下线失败")
|
||||
return ErrorResponse(msg="强制下线失败")
|
||||
|
||||
@router.delete(
|
||||
'/clear',
|
||||
dependencies=[Depends(AuthPermission(permissions=['monitor:online:delete']))],
|
||||
summary="清除所有在线用户",
|
||||
description="清除所有在线用户"
|
||||
)
|
||||
async def clear_online_controller(
|
||||
redis: Redis = Depends(redis_getter),
|
||||
)->JSONResponse:
|
||||
is_ok = await OnlineService.clear_online_service(redis=redis)
|
||||
if is_ok:
|
||||
logger.info("清除所有在线用户成功")
|
||||
return SuccessResponse(msg="清除所有在线用户成功")
|
||||
else:
|
||||
logger.info("清除所有在线用户失败")
|
||||
return ErrorResponse(msg="清除所有在线用户失败")
|
||||
@@ -63,7 +63,7 @@ async def get_new_token_controller(
|
||||
return SuccessResponse(data=token_dict, msg="刷新成功")
|
||||
|
||||
|
||||
@router.post("/captcha/get", summary="获取验证码", description="获取登录验证码", response_model=CaptchaOutSchema)
|
||||
@router.get("/captcha/get", summary="获取验证码", description="获取登录验证码", response_model=CaptchaOutSchema)
|
||||
async def get_captcha_for_login_controller(
|
||||
redis: Redis = Depends(redis_getter)
|
||||
) -> JSONResponse:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from fastapi import APIRouter, Depends, Query, Request, UploadFile
|
||||
from fastapi import APIRouter, Body, Depends, Query, Request, UploadFile
|
||||
from fastapi.responses import JSONResponse, StreamingResponse
|
||||
from aioredis import Redis
|
||||
|
||||
@@ -67,10 +67,10 @@ async def update_objs_controller(
|
||||
@router.delete("/delete", summary="删除系统配置", description="删除系统配置")
|
||||
async def delete_type_controller(
|
||||
redis: Redis = Depends(redis_getter),
|
||||
id: int = Query(..., description="系统配置ID"),
|
||||
ids: list[int] = Body(..., description="ID列表"),
|
||||
auth: AuthSchema = Depends(AuthPermission(permissions=["system:config:delete"]))
|
||||
) -> JSONResponse:
|
||||
await ConfigService.delete_obj_service(auth=auth, redis=redis, id=id)
|
||||
await ConfigService.delete_obj_service(auth=auth, redis=redis, ids=ids)
|
||||
logger.info(f"删除系统配置成功: {id}")
|
||||
return SuccessResponse(msg="删除系统配置成功")
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from fastapi import APIRouter, Depends, Query
|
||||
from fastapi import APIRouter, Body, Depends, Query
|
||||
from fastapi.responses import JSONResponse
|
||||
|
||||
from app.common.response import SuccessResponse
|
||||
@@ -66,10 +66,10 @@ async def update_obj_controller(
|
||||
|
||||
@router.delete("/delete", summary="删除部门", description="删除部门")
|
||||
async def delete_obj_controller(
|
||||
id: int = Query(..., description="部门ID"),
|
||||
ids: list[int] = Body(..., description="ID列表"),
|
||||
auth: AuthSchema = Depends(AuthPermission(permissions=["system:dept:delete"]))
|
||||
) -> JSONResponse:
|
||||
await DeptService.delete_dept_service(id=id, auth=auth)
|
||||
await DeptService.delete_dept_service(ids=ids, auth=auth)
|
||||
logger.info(f"删除部门成功: {id}")
|
||||
return SuccessResponse(msg="删除部门成功")
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import json
|
||||
from fastapi import APIRouter, Depends, Query
|
||||
from fastapi import APIRouter, Body, Depends, Query
|
||||
from fastapi.responses import JSONResponse, StreamingResponse
|
||||
from aioredis import Redis
|
||||
|
||||
@@ -76,10 +76,10 @@ async def update_type_controller(
|
||||
@router.delete("/type/delete", summary="删除字典类型", description="删除字典类型")
|
||||
async def delete_type_controller(
|
||||
redis: Redis = Depends(redis_getter),
|
||||
id: int = Query(..., description="字典类型ID"),
|
||||
ids: list[int] = Body(..., description="ID列表"),
|
||||
auth: AuthSchema = Depends(AuthPermission(permissions=["system:dict_type:delete"]))
|
||||
) -> JSONResponse:
|
||||
await DictTypeService.delete_obj_service(auth=auth, redis=redis, id=id)
|
||||
await DictTypeService.delete_obj_service(auth=auth, redis=redis, ids=ids)
|
||||
logger.info(f"删除字典类型成功: {id}")
|
||||
return SuccessResponse(msg="删除字典类型成功")
|
||||
|
||||
@@ -144,10 +144,10 @@ async def update_data_controller(
|
||||
@router.delete("/data/delete", summary="删除字典数据", description="删除字典数据")
|
||||
async def delete_data_controller(
|
||||
redis: Redis = Depends(redis_getter),
|
||||
id: int = Query(..., description="字典数据ID"),
|
||||
ids: list[int] = Body(..., description="ID列表"),
|
||||
auth: AuthSchema = Depends(AuthPermission(permissions=["system:dict_data:delete"]))
|
||||
) -> JSONResponse:
|
||||
await DictDataService.delete_obj_service(auth=auth, redis=redis, id=id)
|
||||
await DictDataService.delete_obj_service(auth=auth, redis=redis, ids=ids)
|
||||
logger.info(f"删除字典数据成功: {id}")
|
||||
return SuccessResponse(msg="删除字典数据成功")
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from fastapi import APIRouter, Depends, Query
|
||||
from fastapi import APIRouter, Body, Depends, Query
|
||||
from fastapi.responses import JSONResponse, StreamingResponse
|
||||
|
||||
from app.common.response import StreamResponse, SuccessResponse
|
||||
@@ -62,10 +62,10 @@ async def update_obj_controller(
|
||||
|
||||
@router.delete("/delete", summary="删除定时任务", description="删除定时任务")
|
||||
async def delete_obj_controller(
|
||||
id: int = Query(..., description="定时任务ID"),
|
||||
ids: list[int] = Body(..., description="ID列表"),
|
||||
auth: AuthSchema = Depends(AuthPermission(permissions=["system:job:delete"]))
|
||||
) -> JSONResponse:
|
||||
await JobService.delete_job_service(auth=auth, id=id)
|
||||
await JobService.delete_job_service(auth=auth, ids=ids)
|
||||
logger.info(f"删除定时任务成功: {id}")
|
||||
return SuccessResponse(msg="删除定时任务成功")
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from fastapi import APIRouter, Depends, Query
|
||||
from fastapi import APIRouter, Body, Depends, Query
|
||||
from fastapi.responses import JSONResponse
|
||||
|
||||
from app.common.response import SuccessResponse
|
||||
@@ -67,10 +67,10 @@ async def update_obj_controller(
|
||||
|
||||
@router.delete("/delete", summary="删除菜单", description="删除菜单")
|
||||
async def delete_obj_controller(
|
||||
id: int = Query(..., description="菜单ID"),
|
||||
ids: list[int] = Body(..., description="ID列表"),
|
||||
auth: AuthSchema = Depends(AuthPermission(permissions=["system:menu:delete"]))
|
||||
) -> JSONResponse:
|
||||
await MenuService.delete_menu_service(id=id, auth=auth)
|
||||
await MenuService.delete_menu_service(ids=ids, auth=auth)
|
||||
logger.info(f"删除菜单成功: {id}")
|
||||
return SuccessResponse(msg="删除菜单成功")
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from fastapi import APIRouter, Depends, Query
|
||||
from fastapi import APIRouter, Body, Depends, Query
|
||||
from fastapi.responses import JSONResponse, StreamingResponse
|
||||
|
||||
from app.common.response import StreamResponse, SuccessResponse
|
||||
@@ -62,10 +62,10 @@ async def update_obj_controller(
|
||||
|
||||
@router.delete("/delete", summary="删除公告", description="删除公告")
|
||||
async def delete_obj_controller(
|
||||
id: int = Query(..., description="公告ID"),
|
||||
ids: list[int] = Body(..., description="ID列表"),
|
||||
auth: AuthSchema = Depends(AuthPermission(permissions=["system:notice:delete"]))
|
||||
) -> JSONResponse:
|
||||
await NoticeService.delete_notice_service(auth=auth, id=id)
|
||||
await NoticeService.delete_notice_service(auth=auth, ids=ids)
|
||||
logger.info(f"删除公告成功: {id}")
|
||||
return SuccessResponse(msg="删除公告成功")
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from fastapi import APIRouter, Depends, Query
|
||||
from fastapi import APIRouter, Body, Depends, Query
|
||||
from fastapi.responses import JSONResponse, StreamingResponse
|
||||
|
||||
from app.common.request import PaginationService
|
||||
@@ -32,7 +32,7 @@ async def get_obj_list_controller(
|
||||
|
||||
@router.get("/detail", summary="日志详情", description="日志详情")
|
||||
async def get_obj_detail_controller(
|
||||
id: int = Query(..., description="操作日志ID"),
|
||||
id: int = Body(..., description="操作日志ID"),
|
||||
auth: AuthSchema = Depends(AuthPermission(permissions=["system:log:query"]))
|
||||
) -> JSONResponse:
|
||||
""" 详情日志 """
|
||||
@@ -43,11 +43,11 @@ async def get_obj_detail_controller(
|
||||
|
||||
@router.delete("/delete", summary="删除日志", description="删除日志")
|
||||
async def delete_obj_log_controller(
|
||||
id: int = Query(..., description="操作日志ID"),
|
||||
ids: list[int] = Query(..., description="ID列表"),
|
||||
auth: AuthSchema = Depends(AuthPermission(permissions=["system:log:delete"]))
|
||||
) -> JSONResponse:
|
||||
""" 删除日志 """
|
||||
await OperationLogService.delete_log_service(id=id, auth=auth)
|
||||
await OperationLogService.delete_log_service(ids=ids, auth=auth)
|
||||
logger.info(f"删除日志成功 {id}")
|
||||
return SuccessResponse(msg="删除日志成功")
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from fastapi import APIRouter, Depends, Query
|
||||
from fastapi import APIRouter, Body, Depends, Query
|
||||
from fastapi.responses import JSONResponse, StreamingResponse
|
||||
|
||||
from app.common.response import StreamResponse, SuccessResponse
|
||||
@@ -67,10 +67,10 @@ async def update_obj_controller(
|
||||
|
||||
@router.delete("/delete", summary="删除岗位", description="删除岗位")
|
||||
async def delete_obj_controller(
|
||||
id: int = Query(..., description="岗位ID"),
|
||||
ids: list[int] = Body(..., description="ID列表"),
|
||||
auth: AuthSchema = Depends(AuthPermission(permissions=["system:position:delete"])),
|
||||
) -> JSONResponse:
|
||||
await PositionService.delete_position_service(id=id, auth=auth)
|
||||
await PositionService.delete_position_service(ids=ids, auth=auth)
|
||||
logger.info(f"删除岗位成功: {id}")
|
||||
return SuccessResponse(msg="删除岗位成功")
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from fastapi import APIRouter, Depends, Query
|
||||
from fastapi import APIRouter, Body, Depends, Query
|
||||
from fastapi.responses import JSONResponse, StreamingResponse
|
||||
|
||||
from app.common.response import StreamResponse, SuccessResponse
|
||||
@@ -68,10 +68,10 @@ async def update_obj_controller(
|
||||
|
||||
@router.delete("/delete", summary="删除角色", description="删除角色")
|
||||
async def delete_obj_controller(
|
||||
id: int = Query(..., description="角色ID"),
|
||||
ids: list[int] = Body(..., description="ID列表"),
|
||||
auth: AuthSchema = Depends(AuthPermission(permissions=["system:role:delete"])),
|
||||
) -> JSONResponse:
|
||||
await RoleService.delete_role_service(id=id, auth=auth)
|
||||
await RoleService.delete_role_service(ids=ids, auth=auth)
|
||||
logger.info(f"删除角色成功: {id}")
|
||||
return SuccessResponse(msg="删除角色成功")
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from fastapi import APIRouter, Depends, Query, UploadFile, Request
|
||||
from fastapi import APIRouter, Body, Depends, Query, UploadFile, Request
|
||||
from fastapi.responses import JSONResponse, StreamingResponse
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
import urllib.parse
|
||||
@@ -133,10 +133,10 @@ async def update_obj_controller(
|
||||
|
||||
@router.delete("/delete", summary="删除用户", description="删除用户")
|
||||
async def delete_obj_controller(
|
||||
id: int = Query(..., description="用户ID"),
|
||||
ids: list[int] = Body(..., description="ID列表"),
|
||||
auth: AuthSchema = Depends(AuthPermission(permissions=["system:user:delete"])),
|
||||
) -> JSONResponse:
|
||||
await UserService.delete_user_service(id=id, auth=auth)
|
||||
await UserService.delete_user_service(ids=ids, auth=auth)
|
||||
logger.info(f"删除用户成功: {id}")
|
||||
return SuccessResponse(msg="删除用户成功")
|
||||
|
||||
|
||||
@@ -53,6 +53,17 @@ class OnlineService:
|
||||
logger.info(f"强制下线用户会话: {session_id}")
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
async def clear_online_service(cls, redis: Redis) -> bool:
|
||||
"""强制下线在线用户"""
|
||||
# 删除 token
|
||||
await RedisCURD(redis).delete(f"{RedisInitKeyConfig.ACCESS_TOKEN.key}:*")
|
||||
await RedisCURD(redis).delete(f"{RedisInitKeyConfig.REFRESH_TOKEN.key}:*")
|
||||
|
||||
logger.info(f"清除所有在线用户会话成功")
|
||||
return True
|
||||
|
||||
|
||||
@staticmethod
|
||||
def _match_search_conditions(online_info: Dict, search: Optional[OnlineQueryParams]) -> bool:
|
||||
"""检查是否匹配搜索条件"""
|
||||
|
||||
@@ -16,7 +16,7 @@ from app.common.enums import RedisInitKeyConfig
|
||||
from app.core.redis_crud import RedisCURD
|
||||
from app.utils.excel_util import ExcelUtil
|
||||
from app.utils.upload_util import UploadUtil
|
||||
from app.core.base_schema import UploadResponseSchema
|
||||
from app.core.base_schema import DeleteIdsSchema, UploadResponseSchema
|
||||
from app.core.exceptions import CustomException
|
||||
from app.config.setting import settings
|
||||
from app.core.logger import logger
|
||||
@@ -100,16 +100,19 @@ class ConfigService:
|
||||
return new_obj_dict
|
||||
|
||||
@classmethod
|
||||
async def delete_obj_service(cls, auth: AuthSchema, redis: Redis, id: int) -> None:
|
||||
exist_obj = await ConfigCRUD(auth).get_obj_by_id_crud(id=id)
|
||||
if not exist_obj:
|
||||
raise CustomException(msg='删除失败,该数据字典类型不存在')
|
||||
# 检查是否是否初始化类型
|
||||
if exist_obj.config_type:
|
||||
# 如果有字典数据,不能删除
|
||||
raise CustomException(msg='删除失败,系统初始化配置不可以删除')
|
||||
async def delete_obj_service(cls, auth: AuthSchema, redis: Redis, ids: list[int]) -> None:
|
||||
if len(ids) < 1:
|
||||
raise CustomException(msg='删除失败,删除对象不能为空')
|
||||
for id in ids:
|
||||
exist_obj = await ConfigCRUD(auth).get_obj_by_id_crud(id=id)
|
||||
if not exist_obj:
|
||||
raise CustomException(msg='删除失败,该数据字典类型不存在')
|
||||
# 检查是否是否初始化类型
|
||||
if exist_obj.config_type:
|
||||
# 如果有字典数据,不能删除
|
||||
raise CustomException(msg=f'{exist_obj.config_name} 删除失败,系统初始化配置不可以删除')
|
||||
|
||||
await ConfigCRUD(auth).delete_obj_crud(ids=[id])
|
||||
await ConfigCRUD(auth).delete_obj_crud(ids=ids)
|
||||
# 同步删除Redis缓存
|
||||
redis_key = f"{RedisInitKeyConfig.SYSTEM_CONFIG.key}:{exist_obj.config_key}"
|
||||
try:
|
||||
|
||||
@@ -92,17 +92,20 @@ class DeptService:
|
||||
return DeptOutSchema.model_validate(dept).model_dump()
|
||||
|
||||
@classmethod
|
||||
async def delete_dept_service(cls, auth: AuthSchema, id: int) -> None:
|
||||
async def delete_dept_service(cls, auth: AuthSchema, ids: list[int]) -> None:
|
||||
"""
|
||||
删除部门service
|
||||
|
||||
:param auth: 认证对象
|
||||
:param id: 部门ID
|
||||
"""
|
||||
dept = await DeptCRUD(auth).get_by_id_crud(id=id)
|
||||
if not dept:
|
||||
raise CustomException(msg='删除失败,该部门不存在')
|
||||
await DeptCRUD(auth).delete(ids=[id])
|
||||
if len(ids) < 1:
|
||||
raise CustomException(msg='删除失败,删除对象不能为空')
|
||||
for id in ids:
|
||||
dept = await DeptCRUD(auth).get_by_id_crud(id=id)
|
||||
if not dept:
|
||||
raise CustomException(msg='删除失败,该部门不存在')
|
||||
await DeptCRUD(auth).delete(ids=ids)
|
||||
|
||||
@classmethod
|
||||
async def batch_set_available_service(cls, auth: AuthSchema, data: BatchSetAvailable) -> None:
|
||||
|
||||
@@ -115,24 +115,28 @@ class DictTypeService:
|
||||
return new_obj_dict
|
||||
|
||||
@classmethod
|
||||
async def delete_obj_service(cls, auth: AuthSchema, redis: Redis, id: int) -> None:
|
||||
exist_obj = await DictTypeCRUD(auth).get_obj_by_id_crud(id=id)
|
||||
if not exist_obj:
|
||||
raise CustomException(msg='删除失败,该数据字典类型不存在')
|
||||
# 检查是否有字典数据
|
||||
exist_obj_type_list = await DictDataCRUD(auth).list(search={'dict_type': id})
|
||||
if len(exist_obj_type_list) > 0:
|
||||
# 如果有字典数据,不能删除
|
||||
raise CustomException(msg='删除失败,该数据字典类型下存在字典数据')
|
||||
await DictTypeCRUD(auth).delete_obj_crud(ids=[id])
|
||||
# 删除Redis缓存
|
||||
redis_key = f"{RedisInitKeyConfig.SYSTEM_DICT.key}:{exist_obj.dict_type}"
|
||||
try:
|
||||
await RedisCURD(redis).delete(redis_key)
|
||||
logger.info(f"删除字典类型成功: {id}")
|
||||
except Exception as e:
|
||||
logger.error(f"删除字典类型失败: {e}")
|
||||
raise CustomException(msg=f"删除字典类型失败")
|
||||
async def delete_obj_service(cls, auth: AuthSchema, redis: Redis, ids: list[int]) -> None:
|
||||
if len(ids) < 1:
|
||||
raise CustomException(msg='删除失败,删除对象不能为空')
|
||||
for id in ids:
|
||||
exist_obj = await DictTypeCRUD(auth).get_obj_by_id_crud(id=id)
|
||||
if not exist_obj:
|
||||
raise CustomException(msg='删除失败,该数据字典类型不存在')
|
||||
# 检查是否有字典数据
|
||||
exist_obj_type_list = await DictDataCRUD(auth).list(search={'dict_type': id})
|
||||
if len(exist_obj_type_list) > 0:
|
||||
# 如果有字典数据,不能删除
|
||||
raise CustomException(msg='删除失败,该数据字典类型下存在字典数据')
|
||||
# 删除Redis缓存
|
||||
redis_key = f"{RedisInitKeyConfig.SYSTEM_DICT.key}:{exist_obj.dict_type}"
|
||||
try:
|
||||
await RedisCURD(redis).delete(redis_key)
|
||||
logger.info(f"删除字典类型成功: {id}")
|
||||
except Exception as e:
|
||||
logger.error(f"删除字典类型失败: {e}")
|
||||
raise CustomException(msg=f"删除字典类型失败")
|
||||
await DictTypeCRUD(auth).delete_obj_crud(ids=ids)
|
||||
|
||||
|
||||
@classmethod
|
||||
async def export_obj_service(cls, data_list: List[Dict[str, Any]]) -> bytes:
|
||||
@@ -294,20 +298,23 @@ class DictDataService:
|
||||
return DictDataOutSchema.model_validate(obj).model_dump()
|
||||
|
||||
@classmethod
|
||||
async def delete_obj_service(cls, auth: AuthSchema, redis: Redis, id: int) -> None:
|
||||
exist_obj = await DictDataCRUD(auth).get_obj_by_id_crud(id=id)
|
||||
if not exist_obj:
|
||||
raise CustomException(msg='删除失败,该字典数据不存在')
|
||||
await DictDataCRUD(auth).delete_obj_crud(ids=[id])
|
||||
# 删除Redis缓存
|
||||
redis_key = f"{RedisInitKeyConfig.SYSTEM_DICT.key}:{exist_obj.dict_type}"
|
||||
try:
|
||||
async def delete_obj_service(cls, auth: AuthSchema, redis: Redis, ids: list[int]) -> None:
|
||||
|
||||
for id in ids:
|
||||
|
||||
exist_obj = await DictDataCRUD(auth).get_obj_by_id_crud(id=id)
|
||||
if not exist_obj:
|
||||
raise CustomException(msg=f'{id} 删除失败,该字典数据不存在')
|
||||
# 删除Redis缓存
|
||||
await RedisCURD(redis).delete(redis_key)
|
||||
logger.info(f"删除字典数据成功: {id}")
|
||||
except Exception as e:
|
||||
logger.error(f"删除字典数据失败: {e}")
|
||||
raise CustomException(msg=f"删除字典数据失败 {e}")
|
||||
redis_key = f"{RedisInitKeyConfig.SYSTEM_DICT.key}:{exist_obj.dict_type}"
|
||||
try:
|
||||
# 删除Redis缓存
|
||||
await RedisCURD(redis).delete(redis_key)
|
||||
logger.info(f"删除字典数据成功: {id}")
|
||||
except Exception as e:
|
||||
logger.error(f"删除字典数据失败: {e}")
|
||||
raise CustomException(msg=f"删除字典数据失败 {e}")
|
||||
await DictDataCRUD(auth).delete_obj_crud(ids=ids)
|
||||
|
||||
@classmethod
|
||||
async def export_obj_service(cls, data_list: List[Dict[str, Any]]) -> bytes:
|
||||
|
||||
@@ -53,12 +53,16 @@ class JobService:
|
||||
return JobOutSchema.model_validate(obj).model_dump()
|
||||
|
||||
@classmethod
|
||||
async def delete_job_service(cls, auth: AuthSchema, id: int) -> None:
|
||||
exist_obj = await JobCRUD(auth).get_obj_by_id_crud(id=id)
|
||||
if not exist_obj:
|
||||
raise CustomException(msg='删除失败,该数据定时任务不存在')
|
||||
await JobCRUD(auth).delete_obj_crud(ids=[id])
|
||||
SchedulerUtil.remove_job(job_id=id)
|
||||
async def delete_job_service(cls, auth: AuthSchema, ids: list[int]) -> None:
|
||||
if len(ids) < 1:
|
||||
raise CustomException(msg='删除失败,删除对象不能为空')
|
||||
for id in ids:
|
||||
exist_obj = await JobCRUD(auth).get_obj_by_id_crud(id=id)
|
||||
if not exist_obj:
|
||||
raise CustomException(msg='删除失败,该数据定时任务不存在')
|
||||
SchedulerUtil.remove_job(job_id=id)
|
||||
await JobCRUD(auth).delete_obj_crud(ids=ids)
|
||||
|
||||
|
||||
@classmethod
|
||||
async def clear_job_service(cls, auth: AuthSchema) -> None:
|
||||
|
||||
@@ -92,11 +92,14 @@ class MenuService:
|
||||
return new_menu_dict
|
||||
|
||||
@classmethod
|
||||
async def delete_menu_service(cls, auth: AuthSchema, id: int) -> None:
|
||||
menu = await MenuCRUD(auth).get_by_id_crud(id=id)
|
||||
if not menu:
|
||||
raise CustomException(msg='删除失败,该菜单不存在')
|
||||
await MenuCRUD(auth).delete(ids=[id])
|
||||
async def delete_menu_service(cls, auth: AuthSchema, ids: list[int]) -> None:
|
||||
if len(ids) < 1:
|
||||
raise CustomException(msg='删除失败,删除对象不能为空')
|
||||
for id in ids:
|
||||
menu = await MenuCRUD(auth).get_by_id_crud(id=id)
|
||||
if not menu:
|
||||
raise CustomException(msg='删除失败,该菜单不存在')
|
||||
await MenuCRUD(auth).delete(ids=ids)
|
||||
|
||||
@classmethod
|
||||
async def set_menu_available_service(cls, auth: AuthSchema, data: BatchSetAvailable) -> None:
|
||||
|
||||
@@ -53,11 +53,14 @@ class NoticeService:
|
||||
return NoticeOutSchema.model_validate(config_obj).model_dump()
|
||||
|
||||
@classmethod
|
||||
async def delete_notice_service(cls, auth: AuthSchema, id: int) -> None:
|
||||
config = await NoticeCRUD(auth).get_by_id_crud(id=id)
|
||||
if not config:
|
||||
raise CustomException(msg='删除失败,该公告通知不存在')
|
||||
await NoticeCRUD(auth).delete_crud(ids=[id])
|
||||
async def delete_notice_service(cls, auth: AuthSchema, ids: list[int]) -> None:
|
||||
if len(ids) < 1:
|
||||
raise CustomException(msg='删除失败,删除对象不能为空')
|
||||
for id in ids:
|
||||
config = await NoticeCRUD(auth).get_by_id_crud(id=id)
|
||||
if not config:
|
||||
raise CustomException(msg='删除失败,该公告通知不存在')
|
||||
await NoticeCRUD(auth).delete_crud(ids=ids)
|
||||
|
||||
@classmethod
|
||||
async def set_notice_available_service(cls, auth: AuthSchema, data: BatchSetAvailable) -> None:
|
||||
|
||||
@@ -9,6 +9,7 @@ from app.api.v1.schemas.system.operation_log_schema import (
|
||||
OperationLogCreateSchema,
|
||||
OperationLogOutSchema
|
||||
)
|
||||
from app.core.exceptions import CustomException
|
||||
from app.utils.excel_util import ExcelUtil
|
||||
from app.api.v1.params.system.operation_log_param import OperationLogQueryParams
|
||||
|
||||
@@ -44,9 +45,11 @@ class OperationLogService:
|
||||
return new_log_dict
|
||||
|
||||
@classmethod
|
||||
async def delete_log_service(cls, auth: AuthSchema, id: int) -> None:
|
||||
async def delete_log_service(cls, auth: AuthSchema, ids: list[int]) -> None:
|
||||
"""删除日志"""
|
||||
await OperationLogCRUD(auth).delete(ids=[id])
|
||||
if len(ids) < 1:
|
||||
raise CustomException(msg='删除失败,删除对象不能为空')
|
||||
await OperationLogCRUD(auth).delete(ids=ids)
|
||||
|
||||
@classmethod
|
||||
async def export_log_list_service(cls, operation_log_list: List[Dict[str, Any]]) -> bytes:
|
||||
|
||||
@@ -55,12 +55,15 @@ class PositionService:
|
||||
return PositionOutSchema.model_validate(updated_position).model_dump()
|
||||
|
||||
@classmethod
|
||||
async def delete_position_service(cls, auth: AuthSchema, id: int) -> None:
|
||||
async def delete_position_service(cls, auth: AuthSchema, ids: list[int]) -> None:
|
||||
"""删除岗位"""
|
||||
position = await PositionCRUD(auth).get_by_id_crud(id=id)
|
||||
if not position:
|
||||
raise CustomException(msg='删除失败,该岗位不存在')
|
||||
await PositionCRUD(auth).delete(ids=[id])
|
||||
if len(ids) < 1:
|
||||
raise CustomException(msg='删除失败,删除对象不能为空')
|
||||
for id in ids:
|
||||
position = await PositionCRUD(auth).get_by_id_crud(id=id)
|
||||
if not position:
|
||||
raise CustomException(msg='删除失败,该岗位不存在')
|
||||
await PositionCRUD(auth).delete(ids=ids)
|
||||
|
||||
@classmethod
|
||||
async def set_position_available_service(cls, auth: AuthSchema, data: BatchSetAvailable) -> None:
|
||||
|
||||
@@ -57,12 +57,15 @@ class RoleService:
|
||||
return RoleOutSchema.model_validate(updated_role).model_dump()
|
||||
|
||||
@classmethod
|
||||
async def delete_role_service(cls, auth: AuthSchema, id: int) -> None:
|
||||
async def delete_role_service(cls, auth: AuthSchema, ids: list[id]) -> None:
|
||||
"""删除角色"""
|
||||
role = await RoleCRUD(auth).get_by_id_crud(id=id)
|
||||
if not role:
|
||||
raise CustomException(msg='删除失败,该角色不存在')
|
||||
await RoleCRUD(auth).delete(ids=[id])
|
||||
if len(ids) < 1:
|
||||
raise CustomException(msg='删除失败,删除对象不能为空')
|
||||
for id in ids:
|
||||
role = await RoleCRUD(auth).get_by_id_crud(id=id)
|
||||
if not role:
|
||||
raise CustomException(msg='删除失败,该角色不存在')
|
||||
await RoleCRUD(auth).delete(ids=ids)
|
||||
|
||||
@classmethod
|
||||
async def set_role_permission_service(cls, auth: AuthSchema, data: RolePermissionSettingSchema) -> None:
|
||||
|
||||
@@ -143,25 +143,28 @@ class UserService:
|
||||
return user_dict
|
||||
|
||||
@classmethod
|
||||
async def delete_user_service(cls, auth: AuthSchema, id: int) -> None:
|
||||
async def delete_user_service(cls, auth: AuthSchema, ids: list[int]) -> None:
|
||||
"""删除用户"""
|
||||
user = await UserCRUD(auth).get_by_id_crud(id=id)
|
||||
if not user:
|
||||
raise CustomException(msg="用户不存在")
|
||||
if user.is_superuser:
|
||||
raise CustomException(msg="超级管理员不能删除")
|
||||
if user.status:
|
||||
raise CustomException(msg="用户已启用,不能删除")
|
||||
if auth.user.id == id:
|
||||
raise CustomException(msg="不能删除当前登陆用户")
|
||||
if len(ids) < 1:
|
||||
raise CustomException(msg='删除失败,删除对象不能为空')
|
||||
for id in ids:
|
||||
user = await UserCRUD(auth).get_by_id_crud(id=id)
|
||||
if not user:
|
||||
raise CustomException(msg="用户不存在")
|
||||
if user.is_superuser:
|
||||
raise CustomException(msg="超级管理员不能删除")
|
||||
if user.status:
|
||||
raise CustomException(msg="用户已启用,不能删除")
|
||||
if auth.user.id == id:
|
||||
raise CustomException(msg="不能删除当前登陆用户")
|
||||
# 删除用户角色关联数据
|
||||
await UserCRUD(auth).set_user_roles_crud(user_ids=[id], role_ids=[])
|
||||
await UserCRUD(auth).set_user_roles_crud(user_ids=ids, role_ids=[])
|
||||
|
||||
# 删除用户岗位关联数据
|
||||
await UserCRUD(auth).set_user_positions_crud(user_ids=[id], position_ids=[])
|
||||
await UserCRUD(auth).set_user_positions_crud(user_ids=ids, position_ids=[])
|
||||
|
||||
# 删除用户
|
||||
await UserCRUD(auth).delete(ids=[id])
|
||||
await UserCRUD(auth).delete(ids=ids)
|
||||
|
||||
@classmethod
|
||||
async def get_current_user_info_service(cls, auth: AuthSchema) -> Dict:
|
||||
|
||||
Reference in New Issue
Block a user