From 0221a76d45888cfb176378263f938b51ad851f9c Mon Sep 17 00:00:00 2001 From: song-tianyang Date: Tue, 22 Aug 2023 14:35:04 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E7=B3=BB=E7=BB=9F=E8=AE=BE=E7=BD=AE):?= =?UTF-8?q?=20=E8=A1=A8=E6=A0=BC=E6=89=B9=E9=87=8F=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E6=8F=90=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../metersphere/sdk/dto}/BaseCondition.java | 2 +- .../metersphere/sdk/dto/BasePageRequest.java | 11 +- .../sdk/dto/TableBatchProcessDTO.java} | 10 +- .../sdk/dto/TableBatchProcessResponse.java} | 8 +- .../resources/i18n/system_en_US.properties | 1 + .../resources/i18n/system_zh_CN.properties | 1 + .../resources/i18n/system_zh_TW.properties | 1 + .../GlobalUserRoleRelationController.java | 10 -- .../system/controller/UserController.java | 46 ++++--- .../request/user/UserAndRoleBatchRequest.java | 36 ----- .../request/user/UserChangeEnableRequest.java | 3 +- .../user/UserRoleBatchRelationRequest.java | 10 +- .../GlobalUserRoleRelationLogService.java | 6 +- .../GlobalUserRoleRelationService.java | 18 +-- .../system/service/UserService.java | 60 ++++----- .../user/UserControllerPermissionTests.java | 19 ++- .../controller/user/UserControllerTests.java | 127 +++++++++--------- 17 files changed, 159 insertions(+), 210 deletions(-) rename backend/{services/system-setting/src/main/java/io/metersphere/system/request/user => framework/sdk/src/main/java/io/metersphere/sdk/dto}/BaseCondition.java (90%) rename backend/{services/system-setting/src/main/java/io/metersphere/system/request/user/UserBaseBatchRequest.java => framework/sdk/src/main/java/io/metersphere/sdk/dto/TableBatchProcessDTO.java} (63%) rename backend/{services/system-setting/src/main/java/io/metersphere/system/response/user/BatchProcessResponse.java => framework/sdk/src/main/java/io/metersphere/sdk/dto/TableBatchProcessResponse.java} (55%) delete mode 100644 backend/services/system-setting/src/main/java/io/metersphere/system/request/user/UserAndRoleBatchRequest.java diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/request/user/BaseCondition.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/BaseCondition.java similarity index 90% rename from backend/services/system-setting/src/main/java/io/metersphere/system/request/user/BaseCondition.java rename to backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/BaseCondition.java index f1ba3c6e03..e9bb6ce37e 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/request/user/BaseCondition.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/BaseCondition.java @@ -1,4 +1,4 @@ -package io.metersphere.system.request.user; +package io.metersphere.sdk.dto; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/BasePageRequest.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/BasePageRequest.java index 53df4c831d..85a42b4abc 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/BasePageRequest.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/BasePageRequest.java @@ -10,14 +10,10 @@ import jakarta.validation.constraints.Pattern; import lombok.Data; import org.apache.commons.lang3.StringUtils; -import java.util.List; import java.util.Map; @Data -public class BasePageRequest { - @Schema(description = "关键字") - private String keyword; - +public class BasePageRequest extends BaseCondition { @Min(value = 1, message = "当前页码必须大于0") @Schema(description = "当前页码") private int current; @@ -30,11 +26,6 @@ public class BasePageRequest { @Schema(description = "排序字段(model中的字段 : asc/desc)") private Map<@Valid @Pattern(regexp = "^[A-Za-z]+$") String, @Valid @NotBlank String> sort; - @Schema(description = "过滤字段") - private Map> filter; - - @Schema(description = "高级搜索") - private Map combine; public String getSortString() { if (sort == null || sort.isEmpty()) { diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/request/user/UserBaseBatchRequest.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/TableBatchProcessDTO.java similarity index 63% rename from backend/services/system-setting/src/main/java/io/metersphere/system/request/user/UserBaseBatchRequest.java rename to backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/TableBatchProcessDTO.java index 7bc0cef32f..57609e7814 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/request/user/UserBaseBatchRequest.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/TableBatchProcessDTO.java @@ -1,24 +1,22 @@ -package io.metersphere.system.request.user; +package io.metersphere.sdk.dto; import io.metersphere.validation.groups.Created; import io.metersphere.validation.groups.Updated; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.Valid; import jakarta.validation.constraints.NotBlank; -import jakarta.validation.constraints.Size; import lombok.Data; import java.util.List; @Data -public class UserBaseBatchRequest { +public class TableBatchProcessDTO { @Schema(description = "用户ID", requiredMode = Schema.RequiredMode.REQUIRED) @Valid private List< - @NotBlank(message = "{user_role_relation.user_id.not_blank}", groups = {Created.class, Updated.class}) - @Size(min = 1, max = 50, message = "{user_role_relation.user_id.length_range}", groups = {Created.class, Updated.class}) + @NotBlank(message = "{id must not be blank}", groups = {Created.class, Updated.class}) String - > userIds; + > selectIds; @Schema(description = "不处理的用户ID") List excludeIds; diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/response/user/BatchProcessResponse.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/TableBatchProcessResponse.java similarity index 55% rename from backend/services/system-setting/src/main/java/io/metersphere/system/response/user/BatchProcessResponse.java rename to backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/TableBatchProcessResponse.java index 684d0bd0e1..c59a8afe7e 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/response/user/BatchProcessResponse.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/TableBatchProcessResponse.java @@ -1,10 +1,14 @@ -package io.metersphere.system.response.user; +package io.metersphere.sdk.dto; import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NoArgsConstructor; @Data -public class BatchProcessResponse { +@NoArgsConstructor +@AllArgsConstructor +public class TableBatchProcessResponse { @Schema(description = "全部数量") private long totalCount; @Schema(description = "成功数量") diff --git a/backend/framework/sdk/src/main/resources/i18n/system_en_US.properties b/backend/framework/sdk/src/main/resources/i18n/system_en_US.properties index 4f034f23d5..54714b8c8d 100644 --- a/backend/framework/sdk/src/main/resources/i18n/system_en_US.properties +++ b/backend/framework/sdk/src/main/resources/i18n/system_en_US.properties @@ -1,4 +1,5 @@ excel.parse.error=Excel parse error +id.not_blank=Id must not be blank role.not.global.system=Role is not global system role role.not.contains.member=Role not contains member user.not.login=User not login diff --git a/backend/framework/sdk/src/main/resources/i18n/system_zh_CN.properties b/backend/framework/sdk/src/main/resources/i18n/system_zh_CN.properties index f1b36bfd80..31d5334d7c 100644 --- a/backend/framework/sdk/src/main/resources/i18n/system_zh_CN.properties +++ b/backend/framework/sdk/src/main/resources/i18n/system_zh_CN.properties @@ -1,4 +1,5 @@ excel.parse.error=Excel解析失败 +id.not_blank=ID不能为空 role.not.global.system=角色不是全局系统角色 role.not.contains.member=角色不包含系统成员角色 user.not.login=未获取到登录用户 diff --git a/backend/framework/sdk/src/main/resources/i18n/system_zh_TW.properties b/backend/framework/sdk/src/main/resources/i18n/system_zh_TW.properties index 46ef98410d..1589ee4a50 100644 --- a/backend/framework/sdk/src/main/resources/i18n/system_zh_TW.properties +++ b/backend/framework/sdk/src/main/resources/i18n/system_zh_TW.properties @@ -1,4 +1,5 @@ excel.parse.error=Excel解析失敗 +id.not_blank=ID不能為空 role.not.global.system=角色不是為全局系統角色 role.not.contains.member=角色不包含系統成員角色 user.not.login=未獲取到登錄用戶 diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/GlobalUserRoleRelationController.java b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/GlobalUserRoleRelationController.java index e57b25b809..47dc14f669 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/GlobalUserRoleRelationController.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/GlobalUserRoleRelationController.java @@ -12,7 +12,6 @@ import io.metersphere.sdk.util.PageUtils; import io.metersphere.sdk.util.Pager; import io.metersphere.sdk.util.SessionUtils; import io.metersphere.system.dto.request.GlobalUserRoleRelationQueryRequest; -import io.metersphere.system.request.user.UserAndRoleBatchRequest; import io.metersphere.system.service.GlobalUserRoleRelationLogService; import io.metersphere.system.service.GlobalUserRoleRelationService; import io.metersphere.validation.groups.Created; @@ -56,15 +55,6 @@ public class GlobalUserRoleRelationController { globalUserRoleRelationService.add(request); } - //用户管理页面,批量添加用户到多个用户组。 权限所属是用户管理的编辑页面权限 - @PostMapping("/add/batch/user-role") - @Operation(summary = "批量添加用户到多个用户组中") - @RequiresPermissions(PermissionConstants.SYSTEM_USER_READ_UPDATE) - @Log(type = OperationLogType.ADD, expression = "#msClass.batchAddLog(#request)", msClass = GlobalUserRoleRelationLogService.class) - public void batchAdd(@Validated({Created.class}) @RequestBody UserAndRoleBatchRequest request) { - globalUserRoleRelationService.batchAdd(request, SessionUtils.getUserId()); - } - @GetMapping("/delete/{id}") @Operation(summary = "删除全局用户组和用户的关联关系") @RequiresPermissions(PermissionConstants.SYSTEM_USER_ROLE_UPDATE) 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 7e986410f9..d823f97dcd 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 @@ -6,9 +6,7 @@ import com.github.pagehelper.PageHelper; import io.metersphere.project.domain.Project; import io.metersphere.sdk.constants.PermissionConstants; import io.metersphere.sdk.constants.UserSourceEnum; -import io.metersphere.sdk.dto.BasePageRequest; -import io.metersphere.sdk.dto.OptionDTO; -import io.metersphere.sdk.dto.UserDTO; +import io.metersphere.sdk.dto.*; import io.metersphere.sdk.log.annotation.Log; import io.metersphere.sdk.log.constants.OperationLogType; import io.metersphere.sdk.util.PageUtils; @@ -19,8 +17,13 @@ import io.metersphere.system.dto.UserBatchCreateDTO; import io.metersphere.system.dto.UserExtend; import io.metersphere.system.request.OrganizationMemberBatchRequest; import io.metersphere.system.request.ProjectAddMemberBatchRequest; -import io.metersphere.system.request.user.*; -import io.metersphere.system.response.user.*; +import io.metersphere.system.request.user.UserChangeEnableRequest; +import io.metersphere.system.request.user.UserEditRequest; +import io.metersphere.system.request.user.UserRoleBatchRelationRequest; +import io.metersphere.system.response.user.UserImportResponse; +import io.metersphere.system.response.user.UserSelectOption; +import io.metersphere.system.response.user.UserTableResponse; +import io.metersphere.system.response.user.UserTreeSelectOption; import io.metersphere.system.service.*; import io.metersphere.system.utils.TreeNodeParseUtils; import io.metersphere.validation.groups.Created; @@ -88,7 +91,7 @@ public class UserController { @Operation(summary = "启用/禁用用户") @RequiresPermissions(PermissionConstants.SYSTEM_USER_READ_UPDATE) @Log(type = OperationLogType.UPDATE, expression = "#msClass.batchUpdateLog(#request)", msClass = UserService.class) - public BatchProcessResponse updateUserEnable(@Validated @RequestBody UserChangeEnableRequest request) { + public TableBatchProcessResponse updateUserEnable(@Validated @RequestBody UserChangeEnableRequest request) { return userService.updateUserEnable(request, SessionUtils.getSessionId()); } @@ -103,7 +106,7 @@ public class UserController { @Operation(summary = "删除用户") @Log(type = OperationLogType.DELETE, expression = "#msClass.deleteLog(#request)", msClass = UserService.class) @RequiresPermissions(PermissionConstants.SYSTEM_USER_READ_DELETE) - public BatchProcessResponse deleteUser(@Validated @RequestBody UserBaseBatchRequest request) { + public TableBatchProcessResponse deleteUser(@Validated @RequestBody TableBatchProcessDTO request) { return userService.deleteUser(request, SessionUtils.getUserId()); } @@ -111,7 +114,7 @@ public class UserController { @Operation(summary = "重置用户密码") @RequiresPermissions(PermissionConstants.SYSTEM_USER_READ_UPDATE) @Log(type = OperationLogType.UPDATE, expression = "#msClass.resetPasswordLog(#request)", msClass = UserService.class) - public BatchProcessResponse resetPassword(@Validated @RequestBody UserBaseBatchRequest request) { + public TableBatchProcessResponse resetPassword(@Validated @RequestBody TableBatchProcessDTO request) { return userService.resetPassword(request, SessionUtils.getUserId()); } @@ -123,14 +126,6 @@ public class UserController { return userService.getMemberOption(sourceId); } - @PostMapping("/add/batch/user-role") - @Operation(summary = "批量添加用户到多个用户组中") - @RequiresPermissions(PermissionConstants.SYSTEM_USER_READ_UPDATE) - @Log(type = OperationLogType.ADD, expression = "#msClass.batchAddLog(#request)", msClass = GlobalUserRoleRelationLogService.class) - public BatchProcessResponse batchAdd(@Validated({Created.class}) @RequestBody UserAndRoleBatchRequest request) { - return globalUserRoleRelationService.batchAdd(request, SessionUtils.getUserId()); - } - @GetMapping("/get/global/system/role") @Operation(summary = "查找系统级用户权限") @RequiresPermissions(PermissionConstants.SYSTEM_USER_ROLE_READ) @@ -153,24 +148,35 @@ public class UserController { return TreeNodeParseUtils.parseOrgProjectMap(orgProjectMap); } + @PostMapping("/add/batch/user-role") + @Operation(summary = "批量添加用户到多个用户组中") + @RequiresPermissions(PermissionConstants.SYSTEM_USER_READ_UPDATE) + @Log(type = OperationLogType.ADD, expression = "#msClass.batchAddLog(#request)", msClass = GlobalUserRoleRelationLogService.class) + public TableBatchProcessResponse batchAdd(@Validated({Created.class}) @RequestBody UserRoleBatchRelationRequest request) { + return globalUserRoleRelationService.batchAdd(request, SessionUtils.getUserId()); + } @PostMapping("/add-project-member") @Operation(summary = "批量添加用户到项目") @RequiresPermissions(value = {PermissionConstants.SYSTEM_USER_READ_UPDATE, PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_MEMBER_ADD}, logical = Logical.AND) - public void addProjectMember(@Validated @RequestBody UserRoleBatchRelationRequest userRoleBatchRelationRequest) { + public TableBatchProcessResponse addProjectMember(@Validated @RequestBody UserRoleBatchRelationRequest userRoleBatchRelationRequest) { ProjectAddMemberBatchRequest request = new ProjectAddMemberBatchRequest(); request.setProjectIds(userRoleBatchRelationRequest.getRoleIds()); - request.setUserIds(userRoleBatchRelationRequest.getUserIds()); + request.setUserIds(userRoleBatchRelationRequest.getSelectIds()); systemProjectService.addProjectMember(request, SessionUtils.getUserId()); + return new TableBatchProcessResponse(userRoleBatchRelationRequest.getSelectIds().size(), userRoleBatchRelationRequest.getSelectIds().size()); } @PostMapping("/add-org-member") @Operation(summary = "批量添加用户到组织") @RequiresPermissions(value = {PermissionConstants.SYSTEM_USER_READ_UPDATE, PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_MEMBER_ADD}, logical = Logical.AND) - public void addMember(@Validated @RequestBody UserRoleBatchRelationRequest userRoleBatchRelationRequest) { + public TableBatchProcessResponse addMember(@Validated @RequestBody UserRoleBatchRelationRequest userRoleBatchRelationRequest) { + //获取本次处理的用户 + userRoleBatchRelationRequest.setSelectIds(userService.getBatchUserIds(userRoleBatchRelationRequest)); OrganizationMemberBatchRequest request = new OrganizationMemberBatchRequest(); request.setOrganizationIds(userRoleBatchRelationRequest.getRoleIds()); - request.setMemberIds(userRoleBatchRelationRequest.getUserIds()); + request.setMemberIds(userRoleBatchRelationRequest.getSelectIds()); organizationService.addMemberBySystem(request, SessionUtils.getUserId()); + return new TableBatchProcessResponse(userRoleBatchRelationRequest.getSelectIds().size(), userRoleBatchRelationRequest.getSelectIds().size()); } } diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/request/user/UserAndRoleBatchRequest.java b/backend/services/system-setting/src/main/java/io/metersphere/system/request/user/UserAndRoleBatchRequest.java deleted file mode 100644 index a6c6bab92d..0000000000 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/request/user/UserAndRoleBatchRequest.java +++ /dev/null @@ -1,36 +0,0 @@ -package io.metersphere.system.request.user; - -import io.metersphere.validation.groups.Created; -import io.metersphere.validation.groups.Updated; -import io.swagger.v3.oas.annotations.media.Schema; -import jakarta.validation.Valid; -import jakarta.validation.constraints.NotBlank; -import jakarta.validation.constraints.NotEmpty; -import jakarta.validation.constraints.Size; -import lombok.Data; -import lombok.EqualsAndHashCode; - -import java.util.List; - -@Data -@EqualsAndHashCode(callSuper = false) -public class UserAndRoleBatchRequest extends UserBaseBatchRequest { - - @Schema(description = "组ID", requiredMode = Schema.RequiredMode.REQUIRED) - @NotEmpty(message = "{user_role_relation.role_id.not_blank}", groups = {Created.class}) - @Valid - private List< - @NotBlank(message = "{user_role_relation.role_id.not_blank}", groups = {Created.class, Updated.class}) - @Size(min = 1, max = 50, message = "{user_role_relation.user_id.length_range}", groups = {Created.class, Updated.class}) - String - > roleIds; - - @Schema(description = "用户ID", requiredMode = Schema.RequiredMode.REQUIRED) - @NotEmpty(message = "{user_role_relation.role_id.not_blank}", groups = {Created.class}) - @Valid - private List< - @NotBlank(message = "{user_role_relation.user_id.not_blank}", groups = {Created.class, Updated.class}) - @Size(min = 1, max = 50, message = "{user_role_relation.user_id.length_range}", groups = {Created.class, Updated.class}) - String - > userIds; -} diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/request/user/UserChangeEnableRequest.java b/backend/services/system-setting/src/main/java/io/metersphere/system/request/user/UserChangeEnableRequest.java index 91150ca655..e8deb44e1f 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/request/user/UserChangeEnableRequest.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/request/user/UserChangeEnableRequest.java @@ -1,12 +1,13 @@ package io.metersphere.system.request.user; +import io.metersphere.sdk.dto.TableBatchProcessDTO; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import lombok.EqualsAndHashCode; @Data @EqualsAndHashCode(callSuper = false) -public class UserChangeEnableRequest extends UserBaseBatchRequest { +public class UserChangeEnableRequest extends TableBatchProcessDTO { @Schema(description = "禁用/启用", requiredMode = Schema.RequiredMode.REQUIRED) boolean enable; } diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/request/user/UserRoleBatchRelationRequest.java b/backend/services/system-setting/src/main/java/io/metersphere/system/request/user/UserRoleBatchRelationRequest.java index 58350f837d..e20180261e 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/request/user/UserRoleBatchRelationRequest.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/request/user/UserRoleBatchRelationRequest.java @@ -1,5 +1,6 @@ package io.metersphere.system.request.user; +import io.metersphere.sdk.dto.TableBatchProcessDTO; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotEmpty; import lombok.Data; @@ -7,18 +8,11 @@ import lombok.Data; import java.util.List; @Data -public class UserRoleBatchRelationRequest { +public class UserRoleBatchRelationRequest extends TableBatchProcessDTO { /** * 权限ID集合 */ @Schema(description = "权限ID集合", requiredMode = Schema.RequiredMode.REQUIRED) @NotEmpty(message = "{organization.id.not_blank}") private List roleIds; - - /** - * 成员ID集合 - */ - @Schema(description = "成员ID集合", requiredMode = Schema.RequiredMode.REQUIRED) - @NotEmpty(message = "{user.id.not_blank}") - private List userIds; } diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/GlobalUserRoleRelationLogService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/GlobalUserRoleRelationLogService.java index 4cb1069bbf..729bff9bc3 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/GlobalUserRoleRelationLogService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/GlobalUserRoleRelationLogService.java @@ -14,7 +14,7 @@ import io.metersphere.system.domain.UserRoleExample; import io.metersphere.system.domain.UserRoleRelation; import io.metersphere.system.mapper.UserRoleMapper; import io.metersphere.system.mapper.UserRoleRelationMapper; -import io.metersphere.system.request.user.UserAndRoleBatchRequest; +import io.metersphere.system.request.user.UserRoleBatchRelationRequest; import jakarta.annotation.Resource; import org.springframework.stereotype.Service; @@ -58,11 +58,11 @@ public class GlobalUserRoleRelationLogService { return dto; } - public List batchAddLog(UserAndRoleBatchRequest request) { + public List batchAddLog(UserRoleBatchRelationRequest request) { UserRoleExample example = new UserRoleExample(); example.createCriteria().andIdIn(request.getRoleIds()); List userRoles = userRoleMapper.selectByExample(example); - List userIds = request.getUserIds(); + List userIds = request.getSelectIds(); List users = baseUserMapper.selectUserOptionByIds(userIds); List returnList = new ArrayList<>(); 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 234abe8c0b..4b9058c4d1 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 @@ -1,5 +1,6 @@ package io.metersphere.system.service; +import io.metersphere.sdk.dto.TableBatchProcessResponse; import io.metersphere.sdk.dto.UserRoleRelationUserDTO; import io.metersphere.sdk.dto.request.GlobalUserRoleRelationUpdateRequest; import io.metersphere.sdk.exception.MSException; @@ -12,8 +13,7 @@ import io.metersphere.system.domain.UserRoleRelation; import io.metersphere.system.domain.UserRoleRelationExample; import io.metersphere.system.dto.request.GlobalUserRoleRelationQueryRequest; import io.metersphere.system.mapper.ExtUserRoleRelationMapper; -import io.metersphere.system.request.user.UserAndRoleBatchRequest; -import io.metersphere.system.response.user.BatchProcessResponse; +import io.metersphere.system.request.user.UserRoleBatchRelationRequest; import io.metersphere.validation.groups.Created; import io.metersphere.validation.groups.Updated; import jakarta.annotation.Resource; @@ -85,20 +85,20 @@ public class GlobalUserRoleRelationService extends BaseUserRoleRelationService { return userRoleRelationMapper.selectByExample(example); } - public BatchProcessResponse batchAdd(@Validated({Created.class, Updated.class}) UserAndRoleBatchRequest request, String operator) { + public TableBatchProcessResponse batchAdd(@Validated({Created.class, Updated.class}) UserRoleBatchRelationRequest request, String operator) { //检查角色的合法性 this.checkGlobalSystemUserRoleLegality(request.getRoleIds()); //获取本次处理的用户 - request.setUserIds(userService.getBatchUserIds(request)); + request.setSelectIds(userService.getBatchUserIds(request)); //检查用户的合法性 - userService.checkUserLegality(request.getUserIds()); - List savedUserRoleRelation = this.selectByUserIdAndRuleId(request.getUserIds(), request.getRoleIds()); + userService.checkUserLegality(request.getSelectIds()); + List savedUserRoleRelation = this.selectByUserIdAndRuleId(request.getSelectIds(), request.getRoleIds()); //过滤已经存储过的用户关系 Map> userRoleIdMap = savedUserRoleRelation.stream() .collect(Collectors.groupingBy(UserRoleRelation::getUserId, Collectors.mapping(UserRoleRelation::getRoleId, Collectors.toList()))); long createTime = System.currentTimeMillis(); List saveList = new ArrayList<>(); - for (String userId : request.getUserIds()) { + for (String userId : request.getSelectIds()) { for (String roleId : request.getRoleIds()) { if (userRoleIdMap.containsKey(userId) && userRoleIdMap.get(userId).contains(roleId)) { continue; @@ -116,8 +116,8 @@ public class GlobalUserRoleRelationService extends BaseUserRoleRelationService { if (CollectionUtils.isNotEmpty(saveList)) { userRoleRelationMapper.batchInsert(saveList); } - BatchProcessResponse response = new BatchProcessResponse(); - response.setTotalCount(request.getUserIds().size()); + TableBatchProcessResponse response = new TableBatchProcessResponse(); + response.setTotalCount(request.getSelectIds().size()); response.setSuccessCount(saveList.size()); 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 c6ff9b12ae..095ea4e979 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 @@ -3,10 +3,7 @@ package io.metersphere.system.service; import com.alibaba.excel.EasyExcelFactory; import io.metersphere.sdk.constants.HttpMethodConstants; import io.metersphere.sdk.constants.OperationLogConstants; -import io.metersphere.sdk.dto.BasePageRequest; -import io.metersphere.sdk.dto.ExcelParseDTO; -import io.metersphere.sdk.dto.LogDTO; -import io.metersphere.sdk.dto.UserDTO; +import io.metersphere.sdk.dto.*; import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.log.constants.OperationLogModule; import io.metersphere.sdk.log.constants.OperationLogType; @@ -22,10 +19,8 @@ import io.metersphere.system.dto.excel.UserExcel; import io.metersphere.system.dto.excel.UserExcelRowDTO; import io.metersphere.system.mapper.ExtUserMapper; import io.metersphere.system.mapper.UserMapper; -import io.metersphere.system.request.user.UserBaseBatchRequest; import io.metersphere.system.request.user.UserChangeEnableRequest; import io.metersphere.system.request.user.UserEditRequest; -import io.metersphere.system.response.user.BatchProcessResponse; import io.metersphere.system.response.user.UserImportResponse; import io.metersphere.system.response.user.UserTableResponse; import io.metersphere.system.utils.UserImportEventListener; @@ -197,14 +192,14 @@ public class UserService { return userEditRequest; } - public BatchProcessResponse updateUserEnable(UserChangeEnableRequest request, String operator) { - request.setUserIds(this.getBatchUserIds(request)); - this.checkUserInDb(request.getUserIds()); - BatchProcessResponse response = new BatchProcessResponse(); - response.setTotalCount(request.getUserIds().size()); + public TableBatchProcessResponse updateUserEnable(UserChangeEnableRequest request, String operator) { + request.setSelectIds(this.getBatchUserIds(request)); + this.checkUserInDb(request.getSelectIds()); + TableBatchProcessResponse response = new TableBatchProcessResponse(); + response.setTotalCount(request.getSelectIds().size()); UserExample userExample = new UserExample(); userExample.createCriteria().andIdIn( - request.getUserIds() + request.getSelectIds() ); User updateUser = new User(); updateUser.setEnable(request.isEnable()); @@ -282,7 +277,7 @@ public class UserService { } - public BatchProcessResponse deleteUser(@Valid UserBaseBatchRequest request, String operator) { + public TableBatchProcessResponse deleteUser(@Valid TableBatchProcessDTO request, String operator) { List userIdList = this.getBatchUserIds(request); this.checkUserInDb(userIdList); //检查是否含有Admin @@ -290,7 +285,7 @@ public class UserService { UserExample userExample = new UserExample(); userExample.createCriteria().andIdIn(userIdList); //更新删除标志位 - BatchProcessResponse response = new BatchProcessResponse(); + TableBatchProcessResponse response = new TableBatchProcessResponse(); response.setTotalCount(userIdList.size()); response.setSuccessCount(this.deleteUserByList(userIdList, operator)); //删除用户角色关系 @@ -342,10 +337,10 @@ public class UserService { return null; } - public List batchUpdateLog(UserBaseBatchRequest request) { + public List batchUpdateLog(TableBatchProcessDTO request) { List logDTOList = new ArrayList<>(); - request.setUserIds(this.getBatchUserIds(request)); - List userList = this.selectByIdList(request.getUserIds()); + request.setSelectIds(this.getBatchUserIds(request)); + List userList = this.selectByIdList(request.getSelectIds()); for (User user : userList) { LogDTO dto = new LogDTO( OperationLogConstants.SYSTEM, @@ -365,11 +360,11 @@ public class UserService { /** * @param request 批量重置密码 用于记录Log使用 */ - public List resetPasswordLog(UserBaseBatchRequest request) { - request.setUserIds(this.getBatchUserIds(request)); + public List resetPasswordLog(TableBatchProcessDTO request) { + request.setSelectIds(this.getBatchUserIds(request)); List returnList = new ArrayList<>(); UserExample example = new UserExample(); - example.createCriteria().andIdIn(request.getUserIds()); + example.createCriteria().andIdIn(request.getSelectIds()); List userList = userMapper.selectByExample(example); for (User user : userList) { LogDTO dto = new LogDTO( @@ -388,9 +383,9 @@ public class UserService { return returnList; } - public List deleteLog(UserBaseBatchRequest request) { + public List deleteLog(TableBatchProcessDTO request) { List logDTOList = new ArrayList<>(); - request.getUserIds().forEach(item -> { + request.getSelectIds().forEach(item -> { User user = userMapper.selectByPrimaryKey(item); if (user != null) { @@ -422,15 +417,15 @@ public class UserService { return extUserMapper.getMemberOption(sourceId); } - public BatchProcessResponse resetPassword(UserBaseBatchRequest request, String operator) { - request.setUserIds(this.getBatchUserIds(request)); - this.checkUserInDb(request.getUserIds()); + public TableBatchProcessResponse resetPassword(TableBatchProcessDTO request, String operator) { + request.setSelectIds(this.getBatchUserIds(request)); + this.checkUserInDb(request.getSelectIds()); SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH); UserMapper batchUpdateMapper = sqlSession.getMapper(UserMapper.class); int insertIndex = 0; long updateTime = System.currentTimeMillis(); - List userList = this.selectByIdList(request.getUserIds()); + List userList = this.selectByIdList(request.getSelectIds()); for (User user : userList) { User updateModel = new User(); updateModel.setId(user.getId()); @@ -450,13 +445,16 @@ public class UserService { sqlSession.flushStatements(); SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory); - BatchProcessResponse response = new BatchProcessResponse(); - response.setTotalCount(request.getUserIds().size()); - response.setSuccessCount(request.getUserIds().size()); + TableBatchProcessResponse response = new TableBatchProcessResponse(); + response.setTotalCount(request.getSelectIds().size()); + response.setSuccessCount(request.getSelectIds().size()); return response; } public void checkUserLegality(List userIds) { + if (CollectionUtils.isEmpty(userIds)) { + throw new MSException(Translator.get("user.not.exist")); + } UserExample example = new UserExample(); example.createCriteria().andIdIn(userIds); if (userMapper.countByExample(example) != userIds.size()) { @@ -464,7 +462,7 @@ public class UserService { } } - public List getBatchUserIds(UserBaseBatchRequest request) { + public List getBatchUserIds(TableBatchProcessDTO request) { if (request.isSelectAll()) { List userList = baseUserMapper.selectByKeyword(request.getCondition().getKeyword(), true); List userIdList = userList.stream().map(User::getId).collect(Collectors.toList()); @@ -473,7 +471,7 @@ public class UserService { } return userIdList; } else { - return request.getUserIds(); + return request.getSelectIds(); } } diff --git a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/user/UserControllerPermissionTests.java b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/user/UserControllerPermissionTests.java index 4c93d76ed9..c4210281f8 100644 --- a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/user/UserControllerPermissionTests.java +++ b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/user/UserControllerPermissionTests.java @@ -2,9 +2,8 @@ package io.metersphere.system.controller.user; import io.metersphere.sdk.base.BaseTest; import io.metersphere.sdk.constants.PermissionConstants; +import io.metersphere.sdk.dto.TableBatchProcessDTO; import io.metersphere.system.dto.UserCreateInfo; -import io.metersphere.system.request.user.UserAndRoleBatchRequest; -import io.metersphere.system.request.user.UserBaseBatchRequest; import io.metersphere.system.request.user.UserChangeEnableRequest; import io.metersphere.system.request.user.UserRoleBatchRelationRequest; import io.metersphere.system.response.user.UserSelectOption; @@ -63,7 +62,7 @@ public class UserControllerPermissionTests extends BaseTest { //校验权限:启用/禁用用户 UserChangeEnableRequest userChangeEnableRequest = new UserChangeEnableRequest(); userChangeEnableRequest.setEnable(false); - userChangeEnableRequest.setUserIds(new ArrayList<>() {{ + userChangeEnableRequest.setSelectIds(new ArrayList<>() {{ this.add("admin"); }}); this.requestPostPermissionTest(PermissionConstants.SYSTEM_USER_READ_UPDATE, UserRequestUtils.URL_USER_UPDATE_ENABLE, userChangeEnableRequest); @@ -77,20 +76,20 @@ public class UserControllerPermissionTests extends BaseTest { this.requestMultipartPermissionTest(PermissionConstants.SYSTEM_USER_READ_IMPORT, UserRequestUtils.URL_USER_IMPORT, paramMap); //用户删除 - UserBaseBatchRequest request = new UserBaseBatchRequest(); - request.setUserIds(new ArrayList<>() {{ + TableBatchProcessDTO request = new TableBatchProcessDTO(); + request.setSelectIds(new ArrayList<>() {{ this.add("testId"); }}); this.requestPostPermissionTest(PermissionConstants.SYSTEM_USER_READ_DELETE, UserRequestUtils.URL_USER_DELETE, request); //重置密码 - request = new UserBaseBatchRequest(); - request.setUserIds(Collections.singletonList("admin")); + request = new TableBatchProcessDTO(); + request.setSelectIds(Collections.singletonList("admin")); this.requestPostPermissionTest(PermissionConstants.SYSTEM_USER_READ_UPDATE, UserRequestUtils.URL_USER_RESET_PASSWORD, request); //批量添加用户到用户组 - UserAndRoleBatchRequest userAndRoleBatchRequest = new UserAndRoleBatchRequest(); - userAndRoleBatchRequest.setUserIds(Collections.singletonList("admin")); + UserRoleBatchRelationRequest userAndRoleBatchRequest = new UserRoleBatchRelationRequest(); + userAndRoleBatchRequest.setSelectIds(Collections.singletonList("admin")); userAndRoleBatchRequest.setRoleIds(Collections.singletonList("member")); this.requestPostPermissionTest(PermissionConstants.SYSTEM_USER_READ_UPDATE, UserRequestUtils.URL_USER_ROLE_RELATION, userAndRoleBatchRequest); @@ -104,7 +103,7 @@ public class UserControllerPermissionTests extends BaseTest { // 批量添加用户到项目 UserRoleBatchRelationRequest roleBatchRelationRequest = new UserRoleBatchRelationRequest(); - roleBatchRelationRequest.setUserIds(Collections.singletonList("admin")); + roleBatchRelationRequest.setSelectIds(Collections.singletonList("admin")); roleBatchRelationRequest.setRoleIds(Collections.singletonList("member")); List addMemberPermissionList = new ArrayList<>(); addMemberPermissionList.add(PermissionConstants.SYSTEM_USER_READ_UPDATE); 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 35390b43e5..70d66ac785 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 @@ -4,9 +4,7 @@ import io.metersphere.project.domain.Project; import io.metersphere.project.mapper.ProjectMapper; import io.metersphere.sdk.base.BaseTest; import io.metersphere.sdk.controller.handler.ResultHolder; -import io.metersphere.sdk.dto.BasePageRequest; -import io.metersphere.sdk.dto.ExcelParseDTO; -import io.metersphere.sdk.dto.UserDTO; +import io.metersphere.sdk.dto.*; import io.metersphere.sdk.log.constants.OperationLogType; import io.metersphere.sdk.util.BeanUtils; import io.metersphere.sdk.util.CodingUtil; @@ -20,8 +18,13 @@ import io.metersphere.system.dto.UserCreateInfo; import io.metersphere.system.dto.excel.UserExcelRowDTO; import io.metersphere.system.mapper.UserMapper; import io.metersphere.system.mapper.UserRoleRelationMapper; -import io.metersphere.system.request.user.*; -import io.metersphere.system.response.user.*; +import io.metersphere.system.request.user.UserChangeEnableRequest; +import io.metersphere.system.request.user.UserEditRequest; +import io.metersphere.system.request.user.UserRoleBatchRelationRequest; +import io.metersphere.system.response.user.UserImportResponse; +import io.metersphere.system.response.user.UserSelectOption; +import io.metersphere.system.response.user.UserTableResponse; +import io.metersphere.system.response.user.UserTreeSelectOption; import io.metersphere.system.service.GlobalUserRoleRelationService; import io.metersphere.system.service.UserService; import io.metersphere.system.utils.user.UserParamUtils; @@ -364,12 +367,12 @@ public class UserControllerTests extends BaseTest { //单独修改状态 UserCreateInfo userInfo = USER_LIST.get(0); UserChangeEnableRequest userChangeEnableRequest = new UserChangeEnableRequest(); - userChangeEnableRequest.setUserIds(new ArrayList<>() {{ + userChangeEnableRequest.setSelectIds(new ArrayList<>() {{ this.add(userInfo.getId()); }}); userChangeEnableRequest.setEnable(false); this.requestPost(userRequestUtils.URL_USER_UPDATE_ENABLE, userChangeEnableRequest, status().isOk()); - for (String item : userChangeEnableRequest.getUserIds()) { + for (String item : userChangeEnableRequest.getSelectIds()) { checkLog(item, OperationLogType.UPDATE); } @@ -386,7 +389,7 @@ public class UserControllerTests extends BaseTest { userChangeEnableRequest.setEnable(false); this.requestPost(userRequestUtils.URL_USER_UPDATE_ENABLE, userChangeEnableRequest, BAD_REQUEST_MATCHER); //含有非法用户 - userChangeEnableRequest.setUserIds(new ArrayList<>() {{ + userChangeEnableRequest.setSelectIds(new ArrayList<>() {{ this.add("BCDEDIT"); }}); this.requestPost(userRequestUtils.URL_USER_UPDATE_ENABLE, userChangeEnableRequest, ERROR_REQUEST_MATCHER); @@ -479,8 +482,8 @@ public class UserControllerTests extends BaseTest { public void testUserResetPasswordError() throws Exception { //用户不存在 { - UserBaseBatchRequest request = new UserBaseBatchRequest(); - request.setUserIds(Collections.singletonList("none user")); + TableBatchProcessDTO request = new TableBatchProcessDTO(); + request.setSelectIds(Collections.singletonList("none user")); this.requestPostAndReturn(userRequestUtils.URL_USER_RESET_PASSWORD, request, ERROR_REQUEST_MATCHER); } } @@ -602,12 +605,9 @@ public class UserControllerTests extends BaseTest { this.checkUserList(); //重置admin的密码 { - UserBaseBatchRequest request = new UserBaseBatchRequest(); - request.setUserIds(Collections.singletonList("admin")); - userRequestUtils.parseObjectFromMvcResult( - this.requestPostAndReturn(userRequestUtils.URL_USER_RESET_PASSWORD, request), - BatchProcessResponse.class - ); + TableBatchProcessDTO request = new TableBatchProcessDTO(); + request.setSelectIds(Collections.singletonList("admin")); + this.requestPostAndReturn(userRequestUtils.URL_USER_RESET_PASSWORD, request); //检查数据库 UserExample userExample = new UserExample(); userExample.createCriteria().andIdEqualTo("admin").andPasswordEqualTo(CodingUtil.md5("metersphere")); @@ -621,11 +621,11 @@ public class UserControllerTests extends BaseTest { paramUser.setId(userId); paramUser.setPassword("I can't say any dirty words"); Assertions.assertEquals(1, userMapper.updateByPrimaryKeySelective(paramUser)); - UserBaseBatchRequest request = new UserBaseBatchRequest(); - request.setUserIds(Collections.singletonList(userId)); - BatchProcessResponse response = userRequestUtils.parseObjectFromMvcResult( + TableBatchProcessDTO request = new TableBatchProcessDTO(); + request.setSelectIds(Collections.singletonList(userId)); + TableBatchProcessResponse response = userRequestUtils.parseObjectFromMvcResult( this.requestPostAndReturn(userRequestUtils.URL_USER_RESET_PASSWORD, request), - BatchProcessResponse.class + TableBatchProcessResponse.class ); Assertions.assertEquals(response.getTotalCount(), response.getSuccessCount(), 1); List userList = userService.selectByIdList(Collections.singletonList(userId)); @@ -638,12 +638,12 @@ public class UserControllerTests extends BaseTest { } //重置非Admin用户的密码 { - UserBaseBatchRequest request = new UserBaseBatchRequest(); + TableBatchProcessDTO request = new TableBatchProcessDTO(); request.setExcludeIds(Collections.singletonList("admin")); request.setSelectAll(true); - BatchProcessResponse response = userRequestUtils.parseObjectFromMvcResult( + TableBatchProcessResponse response = userRequestUtils.parseObjectFromMvcResult( this.requestPostAndReturn(userRequestUtils.URL_USER_RESET_PASSWORD, request), - BatchProcessResponse.class + TableBatchProcessResponse.class ); UserExample example = new UserExample(); example.createCriteria().andIdNotEqualTo("admin"); @@ -671,14 +671,14 @@ public class UserControllerTests extends BaseTest { } List last50Users = USER_LIST.subList(USER_LIST.size() - 50, USER_LIST.size()); //测试添加角色权限。 预期数据:每个用户都会增加对应的权限 - UserAndRoleBatchRequest request = new UserAndRoleBatchRequest(); - request.setUserIds(last50Users.stream().map(UserCreateInfo::getId).collect(Collectors.toList())); + UserRoleBatchRelationRequest request = new UserRoleBatchRelationRequest(); + request.setSelectIds(last50Users.stream().map(UserCreateInfo::getId).collect(Collectors.toList())); request.setRoleIds(USER_ROLE_LIST.stream().map(UserSelectOption::getId).collect(Collectors.toList())); userRequestUtils.requestPost(userRequestUtils.URL_USER_ROLE_RELATION, request, null); //检查有权限的数据量是否一致 Assertions.assertEquals( - globalUserRoleRelationService.selectByUserIdAndRuleId(request.getUserIds(), request.getRoleIds()).size(), - request.getUserIds().size() * request.getRoleIds().size() + globalUserRoleRelationService.selectByUserIdAndRuleId(request.getSelectIds(), request.getRoleIds()).size(), + request.getSelectIds().size() * request.getRoleIds().size() ); //检查日志 for (UserSelectOption option : USER_ROLE_LIST) { @@ -689,8 +689,8 @@ public class UserControllerTests extends BaseTest { userRequestUtils.requestPost(userRequestUtils.URL_USER_ROLE_RELATION, request, null); //检查有权限的数据量是否一致 Assertions.assertEquals( - globalUserRoleRelationService.selectByUserIdAndRuleId(request.getUserIds(), request.getRoleIds()).size(), - request.getUserIds().size() * request.getRoleIds().size() + globalUserRoleRelationService.selectByUserIdAndRuleId(request.getSelectIds(), request.getRoleIds()).size(), + request.getSelectIds().size() * request.getRoleIds().size() ); //检查日志 for (UserSelectOption option : USER_ROLE_LIST) { @@ -707,24 +707,24 @@ public class UserControllerTests extends BaseTest { } List last50Users = USER_LIST.subList(USER_LIST.size() - 50, USER_LIST.size()); // 用户ID为空 - UserAndRoleBatchRequest request = new UserAndRoleBatchRequest(); - request.setUserIds(new ArrayList<>()); + UserRoleBatchRelationRequest request = new UserRoleBatchRelationRequest(); + request.setSelectIds(new ArrayList<>()); request.setRoleIds(USER_ROLE_LIST.stream().map(UserSelectOption::getId).collect(Collectors.toList())); - userRequestUtils.requestPost(userRequestUtils.URL_USER_ROLE_RELATION, request, BAD_REQUEST_MATCHER); + userRequestUtils.requestPost(userRequestUtils.URL_USER_ROLE_RELATION, request, ERROR_REQUEST_MATCHER); // 角色id为空 - request = new UserAndRoleBatchRequest(); - request.setUserIds(last50Users.stream().map(UserCreateInfo::getId).collect(Collectors.toList())); + request = new UserRoleBatchRelationRequest(); + request.setSelectIds(last50Users.stream().map(UserCreateInfo::getId).collect(Collectors.toList())); request.setRoleIds(new ArrayList<>()); - userRequestUtils.requestPost(userRequestUtils.URL_USER_ROLE_RELATION, request, BAD_REQUEST_MATCHER); + userRequestUtils.requestPost(userRequestUtils.URL_USER_ROLE_RELATION, request, ERROR_REQUEST_MATCHER); // 用户ID含有不存在的 - request = new UserAndRoleBatchRequest(); - request.setUserIds(last50Users.stream().map(UserCreateInfo::getId).collect(Collectors.toList())); + request = new UserRoleBatchRelationRequest(); + request.setSelectIds(last50Users.stream().map(UserCreateInfo::getId).collect(Collectors.toList())); request.setRoleIds(USER_ROLE_LIST.stream().map(UserSelectOption::getId).collect(Collectors.toList())); - request.getUserIds().add("none user"); + request.getSelectIds().add("none user"); userRequestUtils.requestPost(userRequestUtils.URL_USER_ROLE_RELATION, request, ERROR_REQUEST_MATCHER); // 角色ID含有不存在的 - request = new UserAndRoleBatchRequest(); - request.setUserIds(last50Users.stream().map(UserCreateInfo::getId).collect(Collectors.toList())); + request = new UserRoleBatchRelationRequest(); + request.setSelectIds(last50Users.stream().map(UserCreateInfo::getId).collect(Collectors.toList())); request.setRoleIds(USER_ROLE_LIST.stream().map(UserSelectOption::getId).collect(Collectors.toList())); request.getRoleIds().add("none role"); userRequestUtils.requestPost(userRequestUtils.URL_USER_ROLE_RELATION, request, ERROR_REQUEST_MATCHER); @@ -768,7 +768,7 @@ public class UserControllerTests extends BaseTest { List last50Users = USER_LIST.subList(USER_LIST.size() - 50, USER_LIST.size()); UserRoleBatchRelationRequest request = new UserRoleBatchRelationRequest(); - request.setUserIds(last50Users.stream().map(UserCreateInfo::getId).collect(Collectors.toList())); + request.setSelectIds(last50Users.stream().map(UserCreateInfo::getId).collect(Collectors.toList())); request.setRoleIds(PROJECT_LIST.stream().map(UserSelectOption::getId).collect(Collectors.toList())); //排除树结构中的组织ID request.getRoleIds().removeAll(ORG_LIST.stream().map(UserSelectOption::getId).collect(Collectors.toList())); @@ -779,7 +779,7 @@ public class UserControllerTests extends BaseTest { for (String projectId : request.getRoleIds()) { Project project = projectMapper.selectByPrimaryKey(projectId); String orgId = project.getOrganizationId(); - for (String userId : request.getUserIds()) { + for (String userId : request.getSelectIds()) { checkExample.createCriteria().andUserIdEqualTo(userId).andSourceIdEqualTo(projectId); //检查是否在对应的项目下 Assertions.assertEquals( @@ -813,13 +813,13 @@ public class UserControllerTests extends BaseTest { List last50Users = USER_LIST.subList(USER_LIST.size() - 50, USER_LIST.size()); UserRoleBatchRelationRequest request = new UserRoleBatchRelationRequest(); - request.setUserIds(last50Users.stream().map(UserCreateInfo::getId).collect(Collectors.toList())); + request.setSelectIds(last50Users.stream().map(UserCreateInfo::getId).collect(Collectors.toList())); request.setRoleIds(ORG_LIST.stream().map(UserSelectOption::getId).collect(Collectors.toList())); this.requestPost(userRequestUtils.URL_ADD_ORGANIZATION_MEMBER, request); //检查有权限的数据量是否一致 UserRoleRelationExample checkExample = new UserRoleRelationExample(); for (String orgId : request.getRoleIds()) { - for (String userId : request.getUserIds()) { + for (String userId : request.getSelectIds()) { checkExample.clear(); //检查是否在对应的组织下 checkExample.createCriteria().andUserIdEqualTo(userId).andSourceIdEqualTo(orgId); @@ -842,44 +842,44 @@ public class UserControllerTests extends BaseTest { } // 用户ID为空 UserRoleBatchRelationRequest addToProjectRequest = new UserRoleBatchRelationRequest(); - addToProjectRequest.setUserIds(new ArrayList<>()); + addToProjectRequest.setSelectIds(new ArrayList<>()); addToProjectRequest.setRoleIds(PROJECT_LIST.stream().map(UserSelectOption::getId).collect(Collectors.toList())); - userRequestUtils.requestPost(userRequestUtils.URL_ADD_PROJECT_MEMBER, addToProjectRequest, BAD_REQUEST_MATCHER); + userRequestUtils.requestPost(userRequestUtils.URL_ADD_PROJECT_MEMBER, addToProjectRequest, ERROR_REQUEST_MATCHER); // 项目为空 addToProjectRequest = new UserRoleBatchRelationRequest(); - addToProjectRequest.setUserIds(USER_LIST.stream().map(UserCreateInfo::getId).collect(Collectors.toList())); + addToProjectRequest.setSelectIds(USER_LIST.stream().map(UserCreateInfo::getId).collect(Collectors.toList())); addToProjectRequest.setRoleIds(new ArrayList<>()); userRequestUtils.requestPost(userRequestUtils.URL_ADD_PROJECT_MEMBER, addToProjectRequest, BAD_REQUEST_MATCHER); // 用户ID含有不存在的 addToProjectRequest = new UserRoleBatchRelationRequest(); - addToProjectRequest.setUserIds(Collections.singletonList("none user")); + addToProjectRequest.setSelectIds(Collections.singletonList("none user")); addToProjectRequest.setRoleIds(PROJECT_LIST.stream().map(UserSelectOption::getId).collect(Collectors.toList())); userRequestUtils.requestPost(userRequestUtils.URL_ADD_PROJECT_MEMBER, addToProjectRequest, ERROR_REQUEST_MATCHER); // 项目ID含有不存在的 addToProjectRequest = new UserRoleBatchRelationRequest(); - addToProjectRequest.setUserIds(USER_LIST.stream().map(UserCreateInfo::getId).collect(Collectors.toList())); + addToProjectRequest.setSelectIds(USER_LIST.stream().map(UserCreateInfo::getId).collect(Collectors.toList())); addToProjectRequest.setRoleIds(Collections.singletonList("none role")); userRequestUtils.requestPost(userRequestUtils.URL_ADD_PROJECT_MEMBER, addToProjectRequest, ERROR_REQUEST_MATCHER); // 用户ID为空 UserRoleBatchRelationRequest orgRequest = new UserRoleBatchRelationRequest(); - orgRequest.setUserIds(new ArrayList<>()); + orgRequest.setSelectIds(new ArrayList<>()); orgRequest.setRoleIds(ORG_LIST.stream().map(UserSelectOption::getId).collect(Collectors.toList())); - userRequestUtils.requestPost(userRequestUtils.URL_ADD_PROJECT_MEMBER, orgRequest, BAD_REQUEST_MATCHER); + userRequestUtils.requestPost(userRequestUtils.URL_ADD_PROJECT_MEMBER, orgRequest, ERROR_REQUEST_MATCHER); // 项目为空 orgRequest = new UserRoleBatchRelationRequest(); - orgRequest.setUserIds(USER_LIST.stream().map(UserCreateInfo::getId).collect(Collectors.toList())); + orgRequest.setSelectIds(USER_LIST.stream().map(UserCreateInfo::getId).collect(Collectors.toList())); orgRequest.setRoleIds(new ArrayList<>()); userRequestUtils.requestPost(userRequestUtils.URL_ADD_PROJECT_MEMBER, orgRequest, BAD_REQUEST_MATCHER); // 用户ID含有不存在的 orgRequest = new UserRoleBatchRelationRequest(); - orgRequest.setUserIds(Collections.singletonList("none user")); + orgRequest.setSelectIds(Collections.singletonList("none user")); orgRequest.setRoleIds(ORG_LIST.stream().map(UserSelectOption::getId).collect(Collectors.toList())); userRequestUtils.requestPost(userRequestUtils.URL_ADD_PROJECT_MEMBER, orgRequest, ERROR_REQUEST_MATCHER); // 项目ID含有不存在的 orgRequest = new UserRoleBatchRelationRequest(); - orgRequest.setUserIds(USER_LIST.stream().map(UserCreateInfo::getId).collect(Collectors.toList())); + orgRequest.setSelectIds(USER_LIST.stream().map(UserCreateInfo::getId).collect(Collectors.toList())); orgRequest.setRoleIds(Collections.singletonList("none role")); userRequestUtils.requestPost(userRequestUtils.URL_ADD_PROJECT_MEMBER, orgRequest, ERROR_REQUEST_MATCHER); } @@ -892,11 +892,12 @@ public class UserControllerTests extends BaseTest { //删除指定的用户 { UserCreateInfo deleteUser = USER_LIST.get(0); - UserBaseBatchRequest request = new UserBaseBatchRequest(); - request.setUserIds(Collections.singletonList(deleteUser.getId())); - BatchProcessResponse response = userRequestUtils.parseObjectFromMvcResult(userRequestUtils.responsePost(userRequestUtils.URL_USER_DELETE, request), BatchProcessResponse.class); - Assertions.assertEquals(request.getUserIds().size(), response.getTotalCount()); - Assertions.assertEquals(request.getUserIds().size(), response.getSuccessCount()); + TableBatchProcessDTO request = new TableBatchProcessDTO(); + request.setSelectIds(Collections.singletonList(deleteUser.getId())); + TableBatchProcessResponse response = userRequestUtils.parseObjectFromMvcResult( + userRequestUtils.responsePost(userRequestUtils.URL_USER_DELETE, request), TableBatchProcessResponse.class); + Assertions.assertEquals(request.getSelectIds().size(), response.getTotalCount()); + Assertions.assertEquals(request.getSelectIds().size(), response.getSuccessCount()); //检查数据库 User user = userMapper.selectByPrimaryKey(deleteUser.getId()); Assertions.assertTrue(user.getDeleted()); @@ -909,20 +910,20 @@ public class UserControllerTests extends BaseTest { @Order(100) public void testUserDeleteError() throws Exception { //参数为空 - UserBaseBatchRequest request = new UserBaseBatchRequest(); + TableBatchProcessDTO request = new TableBatchProcessDTO(); this.requestPost(userRequestUtils.URL_USER_DELETE, request, ERROR_REQUEST_MATCHER); //用户不存在 - request.setUserIds(Collections.singletonList("none user")); + request.setSelectIds(Collections.singletonList("none user")); this.requestPost(userRequestUtils.URL_USER_DELETE, request, ERROR_REQUEST_MATCHER); //测试用户已经被删除的 if (CollectionUtils.isEmpty(DELETED_USER_ID_LIST)) { this.testUserDeleteSuccess(); } - request.setUserIds(DELETED_USER_ID_LIST); + request.setSelectIds(DELETED_USER_ID_LIST); this.requestPost(userRequestUtils.URL_USER_DELETE, request, ERROR_REQUEST_MATCHER); //测试包含Admin用户 - request = new UserBaseBatchRequest(); + request = new TableBatchProcessDTO(); request.setSelectAll(true); this.requestPost(userRequestUtils.URL_USER_DELETE, request, ERROR_REQUEST_MATCHER); }