修复排序bug
ci-userbase-service / build-and-push (push) Successful in 41s

This commit is contained in:
chenxing
2026-08-13 08:15:03 +08:00
parent 3855ea2eca
commit 8113045471
2 changed files with 32 additions and 7 deletions
@@ -500,15 +500,18 @@ public class SysUserService implements ISysUserService {
*/
@Override
public void exportUsers(Integer groupId, Integer withSub, String name, HttpServletResponse response) throws IOException {
// 1. 解析组范围(含子孙)并查询范围内全部用户(不分页)
SysUserQuery query = new SysUserQuery();
query.setGroupId(groupId);
query.setWithSub(withSub);
query.setName(name);
List<SysUser> users = sysUserRepository.findAll(buildSpecification(query));
// 1. 解析组范围(含子孙),复用与列表一致的 INNER JOIN 原生 SQL 取范围内用户(含超管豁免),不分页。
// 无组归属的用户被 INNER JOIN 天然排除;type=1 超管在 SQL 中显式豁免,永不导出。
List<Integer> groupIds = resolveGroupIds(groupId, withSub);
String nameKey = StringUtils.isNotBlank(name) ? name.trim() : null;
List<Integer> userIds = sysUserRepository.findGroupUserIds(groupIds, nameKey);
List<SysUser> users = userIds.isEmpty()
? Collections.emptyList()
: sysUserRepository.findAllById(userIds).stream()
.sorted(Comparator.comparing(SysUser::getId))
.collect(Collectors.toList());
// 2. 批量取每个用户的主组(isMain=1),用于填充「组名 / 组id」参考列
List<Integer> userIds = users.stream().map(SysUser::getId).collect(Collectors.toList());
Map<Integer, Integer> userMainGroup = resolveUserMainGroup(userIds);
// 3. 批量取组名