refactor(系统设置): 用户组下拉用户根据名称排序

This commit is contained in:
song-cc-rock 2023-09-15 19:18:30 +08:00 committed by 刘瑞斌
parent b645ac0f26
commit 5dc90fd67b
2 changed files with 6 additions and 3 deletions

View File

@ -26,7 +26,7 @@
<if test="keyword != null and keyword != ''">
and (u.name like concat('%', #{keyword}, '%') or u.email like concat('%', #{keyword}, '%'))
</if>
order by u.create_time desc
order by u.name
limit 100
</select>

View File

@ -13,6 +13,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;
@ -44,7 +45,7 @@ public class UserRoleService {
UserRoleRelationExample example = new UserRoleRelationExample();
example.createCriteria().andSourceIdEqualTo(sourceId);
List<UserRoleRelation> userRoleRelations = userRoleRelationMapper.selectByExample(example);
if (org.apache.commons.collections.CollectionUtils.isNotEmpty(userRoleRelations)) {
if (CollectionUtils.isNotEmpty(userRoleRelations)) {
Map<String, List<String>> userRoleMap = userRoleRelations.stream().collect(Collectors.groupingBy(UserRoleRelation::getUserId,
Collectors.mapping(UserRoleRelation::getRoleId, Collectors.toList())));
userRoleMap.forEach((k, v) -> {
@ -61,7 +62,7 @@ public class UserRoleService {
// 设置用户信息, 用户不存在或者已删除, 则不展示
List<String> userIds = userExtends.stream().map(UserExtend::getId).toList();
List<User> users = extUserMapper.getRoleUserByParam(userIds, keyword);
if (org.apache.commons.collections.CollectionUtils.isNotEmpty(users)) {
if (CollectionUtils.isNotEmpty(users)) {
Map<String, User> userMap = users.stream().collect(Collectors.toMap(User::getId, user -> user));
userExtends.removeIf(userExtend -> {
if (userMap.containsKey(userExtend.getId())) {
@ -74,6 +75,8 @@ public class UserRoleService {
userExtends.clear();
}
}
userExtends.sort(Comparator.comparing(UserExtend::getName));
return userExtends;
}
}