|
@@ -2,6 +2,7 @@ package com.qunzhixinxi.hnqz.admin.controller.user;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
+import com.qunzhixinxi.hnqz.admin.api.entity.SysDept;
|
|
|
import com.qunzhixinxi.hnqz.admin.api.entity.SysUser;
|
|
|
import com.qunzhixinxi.hnqz.common.core.constant.CacheConstants;
|
|
|
import com.qunzhixinxi.hnqz.common.core.util.R;
|
|
@@ -9,6 +10,7 @@ import java.util.Collections;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.Set;
|
|
|
import java.util.stream.Collectors;
|
|
|
import javax.annotation.Resource;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -29,7 +31,6 @@ public class SysUserControllerV2 {
|
|
|
|
|
|
@Resource private RedisTemplate redisTemplate;
|
|
|
|
|
|
-
|
|
|
@GetMapping(value = "/avail")
|
|
|
public R<List<Map<String, Object>>> listAvail(
|
|
|
@RequestParam(value = "realName", required = false) String realName) {
|
|
@@ -41,18 +42,35 @@ public class SysUserControllerV2 {
|
|
|
}
|
|
|
|
|
|
if (StrUtil.isNotBlank(realName)) {
|
|
|
- range = range.stream().filter(u -> StrUtil.contains(u.getRealname(), realName)).collect(
|
|
|
- Collectors.toList());
|
|
|
-
|
|
|
+ range =
|
|
|
+ range.stream()
|
|
|
+ .filter(u -> StrUtil.contains(u.getRealname(), realName))
|
|
|
+ .collect(Collectors.toList());
|
|
|
}
|
|
|
|
|
|
- List<Map<String, Object>> collect = range.stream().map(u -> {
|
|
|
- Map<String, Object> map = new HashMap<>(3);
|
|
|
- map.put("userId", u.getUserId());
|
|
|
- map.put("realName", u.getRealname());
|
|
|
- map.put("username", u.getUsername());
|
|
|
- return map;
|
|
|
- }).collect(Collectors.toList());
|
|
|
+ List<SysDept> depts = redisTemplate.opsForList().range(CacheConstants.DEPT_KEY, 0, -1);
|
|
|
+
|
|
|
+ Set<Integer> deptIds =
|
|
|
+ CollUtil.isEmpty(depts)
|
|
|
+ ? Collections.emptySet()
|
|
|
+ : depts.stream()
|
|
|
+ .filter(d -> d.getLevel() == 4)
|
|
|
+ .mapToInt(SysDept::getDeptId)
|
|
|
+ .boxed()
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+
|
|
|
+ List<Map<String, Object>> collect =
|
|
|
+ range.stream()
|
|
|
+ .filter(u -> deptIds.contains(u.getDeptId()))
|
|
|
+ .map(
|
|
|
+ u -> {
|
|
|
+ Map<String, Object> map = new HashMap<>(3);
|
|
|
+ map.put("userId", u.getUserId());
|
|
|
+ map.put("realName", u.getRealname());
|
|
|
+ map.put("username", u.getUsername());
|
|
|
+ return map;
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
|
return R.ok(collect);
|
|
|
}
|