From 5c9cacf5086edefa54b92480deaf516fb421ec11 Mon Sep 17 00:00:00 2001 From: song-tianyang Date: Mon, 14 Aug 2023 14:10:25 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E7=B3=BB=E7=BB=9F=E8=AE=BE=E7=BD=AE):?= =?UTF-8?q?=20=E7=94=A8=E6=88=B7=E7=AE=A1=E7=90=86=E6=89=B9=E9=87=8F?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E6=8E=A5=E5=8F=A3=E8=BF=94=E5=9B=9E=E5=80=BC?= =?UTF-8?q?=E7=AE=80=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../response/UserBatchProcessResponse.java | 3 --- .../GlobalUserRoleRelationService.java | 1 - .../system/service/UserService.java | 3 --- .../controller/user/UserControllerTests.java | 27 ++++++++++--------- 4 files changed, 15 insertions(+), 19 deletions(-) diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/dto/response/UserBatchProcessResponse.java b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/response/UserBatchProcessResponse.java index 9d63f6c397..e4dcdaed50 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/dto/response/UserBatchProcessResponse.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/response/UserBatchProcessResponse.java @@ -2,11 +2,8 @@ package io.metersphere.system.dto.response; import lombok.Data; -import java.util.List; - @Data public class UserBatchProcessResponse { private long totalCount; private long successCount; - private List processedIds; } diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/GlobalUserRoleRelationService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/GlobalUserRoleRelationService.java index 06536e48c6..52e5ae8db2 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/GlobalUserRoleRelationService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/GlobalUserRoleRelationService.java @@ -118,7 +118,6 @@ public class GlobalUserRoleRelationService extends BaseUserRoleRelationService { UserBatchProcessResponse response = new UserBatchProcessResponse(); response.setTotalCount(request.getUserIds().size()); response.setSuccessCount(saveList.size()); - response.setProcessedIds(saveList.stream().map(UserRoleRelation::getUserId).collect(Collectors.toList())); return response; } 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 cbdbbccb91..ea9dde4acc 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 @@ -211,7 +211,6 @@ public class UserService { updateUser.setUpdateUser(operator); updateUser.setUpdateTime(System.currentTimeMillis()); response.setSuccessCount(userMapper.updateByExampleSelective(updateUser, userExample)); - response.setProcessedIds(request.getUserIds()); return response; } @@ -293,7 +292,6 @@ public class UserService { //更新删除标志位 UserBatchProcessResponse response = new UserBatchProcessResponse(); response.setTotalCount(userIdList.size()); - response.setProcessedIds(userIdList); response.setSuccessCount(this.deleteUserByList(userIdList, operator)); //删除用户角色关系 userRoleRelationService.deleteByUserIdList(userIdList); @@ -455,7 +453,6 @@ public class UserService { UserBatchProcessResponse response = new UserBatchProcessResponse(); response.setTotalCount(request.getUserIds().size()); response.setSuccessCount(request.getUserIds().size()); - response.setProcessedIds(request.getUserIds()); return response; } diff --git a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/user/UserControllerTests.java b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/user/UserControllerTests.java index 099c859200..166f8b9653 100644 --- a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/user/UserControllerTests.java +++ b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/user/UserControllerTests.java @@ -611,7 +611,8 @@ public class UserControllerTests extends BaseTest { this.requestPostAndReturn(userRequestUtils.URL_USER_RESET_PASSWORD, request), UserBatchProcessResponse.class ); - List userList = userService.selectByIdList(response.getProcessedIds()); + Assertions.assertEquals(response.getTotalCount(), response.getSuccessCount(), 1); + List userList = userService.selectByIdList(Collections.singletonList(userId)); for (User checkUser : userList) { UserExample userExample = new UserExample(); userExample.createCriteria().andIdEqualTo(checkUser.getId()).andPasswordEqualTo(CodingUtil.md5(checkUser.getEmail())); @@ -628,7 +629,14 @@ public class UserControllerTests extends BaseTest { this.requestPostAndReturn(userRequestUtils.URL_USER_RESET_PASSWORD, request), UserBatchProcessResponse.class ); - List userList = userService.selectByIdList(response.getProcessedIds()); + UserExample example = new UserExample(); + example.createCriteria().andIdNotEqualTo("admin"); + long count = userMapper.countByExample(example); + Assertions.assertEquals(response.getTotalCount(), response.getSuccessCount(), count); + + example.clear(); + example.createCriteria().andIdNotEqualTo("admin"); + List userList = userMapper.selectByExample(example); for (User checkUser : userList) { UserExample userExample = new UserExample(); userExample.createCriteria().andIdEqualTo(checkUser.getId()).andPasswordEqualTo(CodingUtil.md5(checkUser.getEmail())); @@ -731,12 +739,8 @@ public class UserControllerTests extends BaseTest { Assertions.assertEquals(request.getUserIds().size(), response.getTotalCount()); Assertions.assertEquals(request.getUserIds().size(), response.getSuccessCount()); //检查数据库 - UserExample example = new UserExample(); - example.createCriteria().andIdIn(response.getProcessedIds()); - List userList = userMapper.selectByExample(example); - for (User user : userList) { - Assertions.assertTrue(user.getDeleted()); - } + User user = userMapper.selectByPrimaryKey(deleteUser.getId()); + Assertions.assertTrue(user.getDeleted()); USER_LIST.remove(deleteUser); } @@ -746,11 +750,10 @@ public class UserControllerTests extends BaseTest { request.setUserIds(USER_LIST.stream().map(UserCreateInfo::getId).collect(Collectors.toList())); request.setSkipIds(Collections.singletonList("admin")); UserBatchProcessResponse response = userRequestUtils.parseObjectFromMvcResult(userRequestUtils.responsePost(userRequestUtils.URL_USER_DELETE, request), UserBatchProcessResponse.class); - Assertions.assertEquals(request.getUserIds().size(), response.getTotalCount()); - Assertions.assertEquals(request.getUserIds().size(), response.getSuccessCount()); + Assertions.assertEquals(request.getUserIds().size(), response.getTotalCount(), response.getSuccessCount()); //检查数据库 UserExample example = new UserExample(); - example.createCriteria().andIdIn(response.getProcessedIds()); + example.createCriteria().andIdIn(request.getUserIds()); List userList = userMapper.selectByExample(example); for (User user : userList) { Assertions.assertTrue(user.getDeleted()); @@ -759,7 +762,7 @@ public class UserControllerTests extends BaseTest { //记录已经删除了的用户,用于反例 DELETED_USER_ID_LIST.clear(); USER_LIST.clear(); - DELETED_USER_ID_LIST.addAll(response.getProcessedIds()); + DELETED_USER_ID_LIST.addAll(request.getUserIds()); //检查删除了的用户,可以用其邮箱继续注册 this.testAddSuccess(); }