From d129681f4f6dbc55524dd5212a6993b2f0dd809b Mon Sep 17 00:00:00 2001 From: WangXu10 Date: Sun, 4 Feb 2024 16:18:50 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E7=B3=BB=E7=BB=9F):=20=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E7=B3=BB=E7=BB=9F&=E7=BB=84=E7=BB=87&=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E7=AE=A1=E7=90=86=E4=B8=8B=E7=9A=84=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E7=BB=84=E6=8E=92=E5=BA=8F=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../metersphere/project/service/ProjectUserRoleService.java | 2 ++ .../metersphere/system/service/GlobalUserRoleService.java | 6 ++++++ .../system/service/OrganizationUserRoleService.java | 5 ++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectUserRoleService.java b/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectUserRoleService.java index ae1af651b1..229cf1e3b6 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectUserRoleService.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectUserRoleService.java @@ -26,6 +26,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; +import java.util.Comparator; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -71,6 +72,7 @@ public class ProjectUserRoleService extends BaseUserRoleService { role.setMemberCount(0); }); } + roles.sort(Comparator.comparing(UserRole::getInternal).reversed()); return roles; } diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/GlobalUserRoleService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/GlobalUserRoleService.java index cdfbcbf17a..da871e41ea 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/GlobalUserRoleService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/GlobalUserRoleService.java @@ -15,6 +15,7 @@ import jakarta.annotation.Resource; import jakarta.validation.Valid; import jakarta.validation.constraints.NotEmpty; import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -45,10 +46,15 @@ public class GlobalUserRoleService extends BaseUserRoleService { List userRoles = userRoleMapper.selectByExample(example); // 先按照类型排序,再按照创建时间排序 userRoles.sort(Comparator.comparingInt(this::getTypeOrder) + .thenComparingInt(item ->getInternal(item.getInternal())) .thenComparing(UserRole::getCreateTime)); return userRoles; } + private int getInternal(Boolean internal) { + return BooleanUtils.isTrue(internal) ? 0 : 1; + } + private int getTypeOrder(UserRole userRole) { Map typeOrderMap = new HashMap<>(3) {{ put(UserRoleType.SYSTEM.name(), 1); diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/OrganizationUserRoleService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/OrganizationUserRoleService.java index e726f7407d..887649cf52 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/OrganizationUserRoleService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/OrganizationUserRoleService.java @@ -17,6 +17,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.Arrays; +import java.util.Comparator; import java.util.List; import static io.metersphere.system.controller.result.SystemResultCode.NO_ORG_USER_ROLE_PERMISSION; @@ -46,7 +47,9 @@ public class OrganizationUserRoleService extends BaseUserRoleService { example.createCriteria().andTypeEqualTo(UserRoleType.ORGANIZATION.name()) .andScopeIdIn(Arrays.asList(organizationId, UserRoleEnum.GLOBAL.toString())); example.setOrderByClause("create_time asc"); - return userRoleMapper.selectByExample(example); + List userRoles = userRoleMapper.selectByExample(example); + userRoles.sort(Comparator.comparing(UserRole::getInternal).reversed()); + return userRoles; } @Override