From 26d360e060ac90fd17d8f1f256729f33d2a8d527 Mon Sep 17 00:00:00 2001 From: song-tianyang Date: Tue, 4 Jul 2023 11:27:29 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E7=B3=BB=E7=BB=9F=E8=AE=BE=E7=BD=AE):=20?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=88=A0=E9=99=A4=E5=8A=9F=E8=83=BD=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E6=97=A5=E5=BF=97=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 用户删除功能增加日志记录 --- .../system/controller/UserController.java | 2 ++ .../system/service/UserService.java | 32 ++++++++++++++++--- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/UserController.java b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/UserController.java index b43a962fac..e48537763c 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/UserController.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/UserController.java @@ -89,6 +89,8 @@ public class UserController { @PostMapping("/delete") + @Log(isBefore = true, type = OperationLogType.DELETE, module = OperationLogModule.SYSTEM_USER, isBatch = true, + details = "#msClass.getLogs(#userBatchProcessRequest)", msClass = UserService.class) @RequiresPermissions(PermissionConstants.SYSTEM_USER_READ_DELETE) public UserBatchProcessResponse deleteUser(@Validated @RequestBody UserChangeEnableRequest userBatchProcessRequest) { return userService.deleteUser(userBatchProcessRequest.getUserIdList()); diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/UserService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/UserService.java index 4a5acc341e..4c67f890e3 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/UserService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/UserService.java @@ -9,10 +9,7 @@ import io.metersphere.sdk.log.constants.OperationLogModule; import io.metersphere.sdk.log.constants.OperationLogType; import io.metersphere.sdk.log.service.OperationLogService; import io.metersphere.sdk.mapper.BaseUserMapper; -import io.metersphere.sdk.util.BeanUtils; -import io.metersphere.sdk.util.CodingUtil; -import io.metersphere.sdk.util.LogUtils; -import io.metersphere.sdk.util.Translator; +import io.metersphere.sdk.util.*; import io.metersphere.system.domain.OperationLog; import io.metersphere.system.domain.User; import io.metersphere.system.domain.UserExample; @@ -20,6 +17,7 @@ import io.metersphere.system.dto.UserBatchCreateDTO; import io.metersphere.system.dto.UserCreateInfo; import io.metersphere.system.dto.excel.UserExcel; import io.metersphere.system.dto.excel.UserExcelRowDTO; +import io.metersphere.system.dto.request.UserBatchProcessRequest; import io.metersphere.system.dto.request.UserChangeEnableRequest; import io.metersphere.system.dto.request.UserEditRequest; import io.metersphere.system.dto.response.UserBatchProcessResponse; @@ -78,6 +76,32 @@ public class UserService { return logs; } + public List selectByIdList(@NotEmpty List userIdList) { + UserExample example = new UserExample(); + example.createCriteria().andIdIn(userIdList); + return userMapper.selectByExample(example); + } + + //切面方法调用:获取接口日志 + public List getLogs(UserBatchProcessRequest request) { + List logs = new ArrayList<>(); + List userList = this.selectByIdList(request.getUserIdList()); + userList.forEach(user -> { + OperationLog log = new OperationLog(); + log.setId(UUID.randomUUID().toString()); + log.setCreateUser(SessionUtils.getUserId()); + log.setProjectId("system"); + log.setType(OperationLogType.DELETE.name()); + log.setModule(OperationLogModule.SYSTEM_USER); + log.setCreateTime(System.currentTimeMillis()); + log.setMethod("deleteUser"); + log.setSourceId(user.getId()); + log.setDetails(user.getName()); + logs.add(log); + }); + return logs; + } + private void validateUserInfo(List userList) { //判断参数内是否含有重复邮箱 List emailList = new ArrayList<>();