From 369b0399cce2b611633ffe94cdcd3d7e5b9bd85b Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Mon, 2 Mar 2020 18:20:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=BC=96=E8=BE=91=E6=88=90?= =?UTF-8?q?=E5=91=98=E8=A7=92=E8=89=B2=E6=97=B6=E5=87=BA=E7=8E=B0=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/OrganizationService.java | 27 +++++++++---------- .../metersphere/service/WorkspaceService.java | 27 +++++++++---------- 2 files changed, 26 insertions(+), 28 deletions(-) diff --git a/backend/src/main/java/io/metersphere/service/OrganizationService.java b/backend/src/main/java/io/metersphere/service/OrganizationService.java index c82c51fdbb..1a6465e303 100644 --- a/backend/src/main/java/io/metersphere/service/OrganizationService.java +++ b/backend/src/main/java/io/metersphere/service/OrganizationService.java @@ -84,21 +84,20 @@ public class OrganizationService { List roles = memberDTO.getRoleIds(); List allRoleIds = memberRoles.stream().map(Role::getId).collect(Collectors.toList()); // 更新用户时添加了角色 - if (roles.size() > allRoleIds.size()) { - for (int i = 0; i < roles.size(); i++) { - if (checkSourceRole(orgId, userId, roles.get(i)) == 0) { - UserRole userRole = new UserRole(); - userRole.setId(UUID.randomUUID().toString()); - userRole.setUserId(userId); - userRole.setRoleId(roles.get(i)); - userRole.setSourceId(orgId); - userRole.setCreateTime(System.currentTimeMillis()); - userRole.setUpdateTime(System.currentTimeMillis()); - userRoleMapper.insertSelective(userRole); - } + for (int i = 0; i < roles.size(); i++) { + if (checkSourceRole(orgId, userId, roles.get(i)) == 0) { + UserRole userRole = new UserRole(); + userRole.setId(UUID.randomUUID().toString()); + userRole.setUserId(userId); + userRole.setRoleId(roles.get(i)); + userRole.setSourceId(orgId); + userRole.setCreateTime(System.currentTimeMillis()); + userRole.setUpdateTime(System.currentTimeMillis()); + userRoleMapper.insertSelective(userRole); } - } else if (roles.size() < allRoleIds.size()){ - allRoleIds.removeAll(roles); + } + allRoleIds.removeAll(roles); + if (allRoleIds.size() > 0) { UserRoleExample userRoleExample = new UserRoleExample(); userRoleExample.createCriteria().andUserIdEqualTo(userId) .andSourceIdEqualTo(orgId) diff --git a/backend/src/main/java/io/metersphere/service/WorkspaceService.java b/backend/src/main/java/io/metersphere/service/WorkspaceService.java index 5e473018ef..6ea453e7f3 100644 --- a/backend/src/main/java/io/metersphere/service/WorkspaceService.java +++ b/backend/src/main/java/io/metersphere/service/WorkspaceService.java @@ -151,21 +151,20 @@ public class WorkspaceService { List roles = memberDTO.getRoleIds(); List allRoleIds = memberRoles.stream().map(Role::getId).collect(Collectors.toList()); // 更新用户时添加了角色 - if (roles.size() > allRoleIds.size()) { - for (int i = 0; i < roles.size(); i++) { - if (checkSourceRole(workspaceId, userId, roles.get(i)) == 0) { - UserRole userRole = new UserRole(); - userRole.setId(UUID.randomUUID().toString()); - userRole.setUserId(userId); - userRole.setRoleId(roles.get(i)); - userRole.setSourceId(workspaceId); - userRole.setCreateTime(System.currentTimeMillis()); - userRole.setUpdateTime(System.currentTimeMillis()); - userRoleMapper.insertSelective(userRole); - } + for (int i = 0; i < roles.size(); i++) { + if (checkSourceRole(workspaceId, userId, roles.get(i)) == 0) { + UserRole userRole = new UserRole(); + userRole.setId(UUID.randomUUID().toString()); + userRole.setUserId(userId); + userRole.setRoleId(roles.get(i)); + userRole.setSourceId(workspaceId); + userRole.setCreateTime(System.currentTimeMillis()); + userRole.setUpdateTime(System.currentTimeMillis()); + userRoleMapper.insertSelective(userRole); } - } else if (roles.size() < allRoleIds.size()){ - allRoleIds.removeAll(roles); + } + allRoleIds.removeAll(roles); + if (allRoleIds.size() > 0) { UserRoleExample userRoleExample = new UserRoleExample(); userRoleExample.createCriteria().andUserIdEqualTo(userId) .andSourceIdEqualTo(workspaceId)