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<>();