|
@@ -1,5 +1,6 @@
|
|
|
package com.qunzhixinxi.hnqz.admin.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.collection.ListUtil;
|
|
@@ -242,7 +243,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|
|
* @return 用户分页
|
|
|
*/
|
|
|
@Override
|
|
|
- public Page<SysUser> pageUser(SysUserDTO.OnPage query, HnqzUser operator) {
|
|
|
+ public Page<?> pageUser(SysUserDTO.OnPage query, HnqzUser operator) {
|
|
|
|
|
|
Page<SysUser> toPage = new Page<>(query.getCurrent(), query.getSize());
|
|
|
|
|
@@ -251,14 +252,14 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|
|
areas = query.getAreaCodes();
|
|
|
} else {
|
|
|
areas = userAreaService.listUserAreas(Long.valueOf(operator.getId()));
|
|
|
- if (CollUtil.isNotEmpty(areas)) {
|
|
|
- areas = areaEntityService.list(Wrappers.<SysAreaEntity>lambdaQuery()
|
|
|
- .in(SysAreaEntity::getAreaId, areas)
|
|
|
- .eq(SysAreaEntity::getAreaStatus, Boolean.TRUE)
|
|
|
- .eq(SysAreaEntity::getAreaType, UpmsType.AreaType.DISTRICT))
|
|
|
- .stream()
|
|
|
- .mapToLong(SysAreaEntity::getAreaId).boxed().distinct().collect(Collectors.toList());
|
|
|
- }
|
|
|
+ // if (CollUtil.isNotEmpty(areas)) {
|
|
|
+ // areas = areaEntityService.list(Wrappers.<SysAreaEntity>lambdaQuery()
|
|
|
+ // .in(SysAreaEntity::getAreaId, areas)
|
|
|
+ // .eq(SysAreaEntity::getAreaStatus, Boolean.TRUE)
|
|
|
+ // .eq(SysAreaEntity::getAreaType, UpmsType.AreaType.DISTRICT))
|
|
|
+ // .stream()
|
|
|
+ // .mapToLong(SysAreaEntity::getAreaId).boxed().distinct().collect(Collectors.toList());
|
|
|
+ // }
|
|
|
|
|
|
}
|
|
|
|
|
@@ -269,11 +270,19 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|
|
return toPage;
|
|
|
}
|
|
|
|
|
|
- Set<Integer> userIdByRoleIdSet = sysUserRoleService.list(Wrappers.<SysUserRole>lambdaQuery()
|
|
|
+
|
|
|
+ List<SysUserRole> userRoles = sysUserRoleService.list(Wrappers.<SysUserRole>lambdaQuery()
|
|
|
.in(SysUserRole::getUserId, areaUserIds)
|
|
|
- .in(SysUserRole::getRoleId, query.getFinalQueryRoleIds())).stream().mapToInt(SysUserRole::getUserId).boxed().collect(Collectors.toSet());
|
|
|
+ .in(SysUserRole::getRoleId, query.getFinalQueryRoleIds()));
|
|
|
+
|
|
|
|
|
|
- if (CollUtil.isEmpty(userIdByRoleIdSet)) {
|
|
|
+ Map<Integer, List<Integer>> collect = userRoles.stream().collect(Collectors.groupingBy(SysUserRole::getUserId, Collectors.mapping(SysUserRole::getRoleId, Collectors.toList())));
|
|
|
+
|
|
|
+ // Set<Integer> userIdByRoleIdSet = sysUserRoleService.list(Wrappers.<SysUserRole>lambdaQuery()
|
|
|
+ // .in(SysUserRole::getUserId, areaUserIds)
|
|
|
+ // .in(SysUserRole::getRoleId, query.getFinalQueryRoleIds())).stream().mapToInt(SysUserRole::getUserId).boxed().collect(Collectors.toSet());
|
|
|
+
|
|
|
+ if (CollUtil.isEmpty(collect)) {
|
|
|
return toPage;
|
|
|
}
|
|
|
|
|
@@ -282,11 +291,37 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|
|
.like(StrUtil.isNotBlank(query.getRealName()), SysUser::getRealname, query.getRealName())
|
|
|
.eq(StrUtil.isNotBlank(query.getLockFlag()), SysUser::getLockFlag, query.getLockFlag())
|
|
|
.eq(query.getDeptId() != null, SysUser::getDeptId, query.getDeptId())
|
|
|
- .in(SysUser::getUserId, userIdByRoleIdSet);
|
|
|
+ .in(SysUser::getUserId, collect.keySet())
|
|
|
+ .orderByDesc(SysUser::getCreateTime);
|
|
|
|
|
|
this.page(toPage, queryWrapper);
|
|
|
|
|
|
- return toPage;
|
|
|
+ List<SysUser> records = toPage.getRecords();
|
|
|
+ if (CollUtil.isEmpty(records)){
|
|
|
+ return toPage;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 拼装角色
|
|
|
+ List<UserVO> userVOS = records.stream().map(item -> {
|
|
|
+ UserVO userVO = BeanUtil.copyProperties(item, UserVO.class);
|
|
|
+ List<Integer> roleIds = collect.get(item.getUserId());
|
|
|
+ List<SysRole> roles = roleIds.stream().map(rId -> {
|
|
|
+ SysRole role = new SysRole();
|
|
|
+ role.setRoleId(rId);
|
|
|
+ return role;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ userVO.setRoleList(roles);
|
|
|
+ return userVO;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+
|
|
|
+ Page<UserVO> userVOPage = new Page<>();
|
|
|
+ userVOPage.setSize(toPage.getSize());
|
|
|
+ userVOPage.setCurrent(toPage.getCurrent());
|
|
|
+ userVOPage.setTotal(toPage.getTotal());
|
|
|
+ userVOPage.setRecords(userVOS);
|
|
|
+
|
|
|
+ return userVOPage;
|
|
|
}
|
|
|
|
|
|
/**
|