refactor(系统): 优化系统&组织&项目管理下的用户组排序规则
This commit is contained in:
parent
13bc39a45c
commit
d129681f4f
|
@ -26,6 +26,7 @@ import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
@ -71,6 +72,7 @@ public class ProjectUserRoleService extends BaseUserRoleService {
|
||||||
role.setMemberCount(0);
|
role.setMemberCount(0);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
roles.sort(Comparator.comparing(UserRole::getInternal).reversed());
|
||||||
return roles;
|
return roles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ import jakarta.annotation.Resource;
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
import jakarta.validation.constraints.NotEmpty;
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
|
import org.apache.commons.lang3.BooleanUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
@ -45,10 +46,15 @@ public class GlobalUserRoleService extends BaseUserRoleService {
|
||||||
List<UserRole> userRoles = userRoleMapper.selectByExample(example);
|
List<UserRole> userRoles = userRoleMapper.selectByExample(example);
|
||||||
// 先按照类型排序,再按照创建时间排序
|
// 先按照类型排序,再按照创建时间排序
|
||||||
userRoles.sort(Comparator.comparingInt(this::getTypeOrder)
|
userRoles.sort(Comparator.comparingInt(this::getTypeOrder)
|
||||||
|
.thenComparingInt(item ->getInternal(item.getInternal()))
|
||||||
.thenComparing(UserRole::getCreateTime));
|
.thenComparing(UserRole::getCreateTime));
|
||||||
return userRoles;
|
return userRoles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int getInternal(Boolean internal) {
|
||||||
|
return BooleanUtils.isTrue(internal) ? 0 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
private int getTypeOrder(UserRole userRole) {
|
private int getTypeOrder(UserRole userRole) {
|
||||||
Map<String, Integer> typeOrderMap = new HashMap<>(3) {{
|
Map<String, Integer> typeOrderMap = new HashMap<>(3) {{
|
||||||
put(UserRoleType.SYSTEM.name(), 1);
|
put(UserRoleType.SYSTEM.name(), 1);
|
||||||
|
|
|
@ -17,6 +17,7 @@ import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static io.metersphere.system.controller.result.SystemResultCode.NO_ORG_USER_ROLE_PERMISSION;
|
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())
|
example.createCriteria().andTypeEqualTo(UserRoleType.ORGANIZATION.name())
|
||||||
.andScopeIdIn(Arrays.asList(organizationId, UserRoleEnum.GLOBAL.toString()));
|
.andScopeIdIn(Arrays.asList(organizationId, UserRoleEnum.GLOBAL.toString()));
|
||||||
example.setOrderByClause("create_time asc");
|
example.setOrderByClause("create_time asc");
|
||||||
return userRoleMapper.selectByExample(example);
|
List<UserRole> userRoles = userRoleMapper.selectByExample(example);
|
||||||
|
userRoles.sort(Comparator.comparing(UserRole::getInternal).reversed());
|
||||||
|
return userRoles;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue