refactor(系统设置): 用户组下拉用户根据名称排序
This commit is contained in:
parent
b645ac0f26
commit
5dc90fd67b
|
@ -26,7 +26,7 @@
|
||||||
<if test="keyword != null and keyword != ''">
|
<if test="keyword != null and keyword != ''">
|
||||||
and (u.name like concat('%', #{keyword}, '%') or u.email like concat('%', #{keyword}, '%'))
|
and (u.name like concat('%', #{keyword}, '%') or u.email like concat('%', #{keyword}, '%'))
|
||||||
</if>
|
</if>
|
||||||
order by u.create_time desc
|
order by u.name
|
||||||
limit 100
|
limit 100
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,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;
|
||||||
|
@ -44,7 +45,7 @@ public class UserRoleService {
|
||||||
UserRoleRelationExample example = new UserRoleRelationExample();
|
UserRoleRelationExample example = new UserRoleRelationExample();
|
||||||
example.createCriteria().andSourceIdEqualTo(sourceId);
|
example.createCriteria().andSourceIdEqualTo(sourceId);
|
||||||
List<UserRoleRelation> userRoleRelations = userRoleRelationMapper.selectByExample(example);
|
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,
|
Map<String, List<String>> userRoleMap = userRoleRelations.stream().collect(Collectors.groupingBy(UserRoleRelation::getUserId,
|
||||||
Collectors.mapping(UserRoleRelation::getRoleId, Collectors.toList())));
|
Collectors.mapping(UserRoleRelation::getRoleId, Collectors.toList())));
|
||||||
userRoleMap.forEach((k, v) -> {
|
userRoleMap.forEach((k, v) -> {
|
||||||
|
@ -61,7 +62,7 @@ public class UserRoleService {
|
||||||
// 设置用户信息, 用户不存在或者已删除, 则不展示
|
// 设置用户信息, 用户不存在或者已删除, 则不展示
|
||||||
List<String> userIds = userExtends.stream().map(UserExtend::getId).toList();
|
List<String> userIds = userExtends.stream().map(UserExtend::getId).toList();
|
||||||
List<User> users = extUserMapper.getRoleUserByParam(userIds, keyword);
|
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));
|
Map<String, User> userMap = users.stream().collect(Collectors.toMap(User::getId, user -> user));
|
||||||
userExtends.removeIf(userExtend -> {
|
userExtends.removeIf(userExtend -> {
|
||||||
if (userMap.containsKey(userExtend.getId())) {
|
if (userMap.containsKey(userExtend.getId())) {
|
||||||
|
@ -74,6 +75,8 @@ public class UserRoleService {
|
||||||
userExtends.clear();
|
userExtends.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
userExtends.sort(Comparator.comparing(UserExtend::getName));
|
||||||
return userExtends;
|
return userExtends;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue