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