feat(系统设置): 用户删除功能增加日志记录

用户删除功能增加日志记录
This commit is contained in:
song-tianyang 2023-07-04 11:27:29 +08:00 committed by 刘瑞斌
parent 13da0485f7
commit 26d360e060
2 changed files with 30 additions and 4 deletions

View File

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

View File

@ -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<User> selectByIdList(@NotEmpty List<String> userIdList) {
UserExample example = new UserExample();
example.createCriteria().andIdIn(userIdList);
return userMapper.selectByExample(example);
}
//切面方法调用获取接口日志
public List<OperationLog> getLogs(UserBatchProcessRequest request) {
List<OperationLog> logs = new ArrayList<>();
List<User> 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<UserCreateInfo> userList) {
//判断参数内是否含有重复邮箱
List<String> emailList = new ArrayList<>();