用户列表修改

This commit is contained in:
zhangzhiqiang
2022-11-30 18:52:58 +08:00
parent 4004f6d4df
commit df996c5eef
12 changed files with 122 additions and 82 deletions

View File

@@ -18,6 +18,8 @@ package org.nl.modules.system.rest;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaMode;
import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
@@ -58,6 +60,16 @@ public class DeptController {
return new ResponseEntity<>(PageUtil.toPage(deptDtos, deptDtos.size()),HttpStatus.OK);
}
@ApiOperation("查询所有部门树")
@GetMapping("/allTree")
public ResponseEntity<Object> allTree(DeptQueryCriteria criteria) throws Exception {
List<Dept> deptDtos = deptService.queryAll(criteria, true);
JSONArray array = JSON.parseArray(JSON.toJSONString(deptDtos));
List<DeptTree> deptTrees = array.toJavaList(DeptTree.class);
Object o = deptService.buildTree(deptTrees);
return new ResponseEntity<>(o,HttpStatus.OK);
}
@ApiOperation("查询部门:根据ID获取同级与上级数据")
@PostMapping("/superior")
@SaCheckPermission(value = {"user:list", "dept:list"}, mode = SaMode.AND)

View File

@@ -85,25 +85,7 @@ public class UserController {
@GetMapping
@SaCheckPermission("user:list")
public ResponseEntity<Object> query(UserQueryCriteria criteria, Pageable pageable){
if (!ObjectUtils.isEmpty(criteria.getDeptId())) {
criteria.getDeptIds().add(criteria.getDeptId());
criteria.getDeptIds().addAll(deptService.getDeptChildren(deptService.findByPid(criteria.getDeptId())));
}
// 数据权限
List<Long> dataScopes = dataService.getDeptIds(userService.findByName(SecurityUtils.getCurrentUsername()));
// criteria.getDeptIds() 不为空并且数据权限不为空则取交集
if (!CollectionUtils.isEmpty(criteria.getDeptIds()) && !CollectionUtils.isEmpty(dataScopes)){
// 取交集
criteria.getDeptIds().retainAll(dataScopes);
if(!CollectionUtil.isEmpty(criteria.getDeptIds())){
return new ResponseEntity<>(userService.queryAll(criteria,pageable),HttpStatus.OK);
}
} else {
// 否则取并集
criteria.getDeptIds().addAll(dataScopes);
return new ResponseEntity<>(userService.queryAll(criteria,pageable),HttpStatus.OK);
}
return new ResponseEntity<>(PageUtil.toPage(null,0),HttpStatus.OK);
return new ResponseEntity<>(userService.queryAll(criteria,pageable),HttpStatus.OK);
}
@Log("新增用户")

View File

@@ -72,6 +72,12 @@ public interface DeptService {
*/
void update(Dept resources);
/**
* 查询pid所有子集
*
*/
Set<Long> findPidChild(Long pid);
/**
* 删除
*

View File

@@ -30,35 +30,12 @@ import java.util.Objects;
*/
@Getter
@Setter
public class DeptTree extends BaseDTO implements Serializable {
public class DeptTree implements Serializable {
private Long Dept_id;
private Long pid;
private String name;
private Boolean is_used;
private Integer dept_sort;
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private List<DeptTree> children;
private Long pid;
private Integer sub_count;
private String versionId;
public Boolean getHasChildren() {
return sub_count > 0;
}
public Boolean getLeaf() {
return sub_count <= 0;
}
public String getLabel() {
return name;
}
}

View File

@@ -39,6 +39,8 @@ public class UserQueryCriteria implements Serializable {
@Query(blurry = "email,username,nickName")
private String blurry;
private Boolean needAll;
@Query
private Boolean is_used;

View File

@@ -24,6 +24,7 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import org.nl.modules.common.exception.BadRequestException;
import org.nl.modules.common.utils.CacheKey;
import org.nl.modules.common.utils.RedisUtils;
@@ -98,6 +99,31 @@ public class DeptServiceImpl implements DeptService {
JSONArray result = WQLObject.getWQLObject("sys_dept").query("pid ='" + pid + "'").getResultJSONArray(0);
return result.toJavaList(Dept.class);
}
@Override
@SneakyThrows
public Set<Long> findPidChild(Long pid) {
if (pid!=null) {
String sql = "SELECT\n" +
" max(t3.childId) as deptIds \n" +
" from\n" +
" (\n" +
" select *,\n" +
" if( find_in_set(t1.pid, @p) > 0,@p := concat(@p,',',id),0 ) as childId\n" +
" from\n" +
" (select dept_id as id, pid from sys_dept t order by id) t1,\n" +
" (select @p := '" + pid + "') t2\n" +
" ) t3\n" +
" where childId != '0'";
List<Entity> list = Db.use((DataSource) SpringContextHolder.getBean("dataSource")).query(sql);
System.out.println(list);
Object deptIds = list.get(0).get("deptIds");
if (deptIds != null && (deptIds instanceof String)) {
String[] split = ((String) deptIds).split(",");
return Arrays.stream(split).map(a -> Long.valueOf(a)).collect(Collectors.toSet());
}
}
return new HashSet();
}
@Override
@@ -166,7 +192,7 @@ public class DeptServiceImpl implements DeptService {
@Override
public Object buildTree(List<DeptTree> deptDtos) {
Set<DeptTree> trees = new LinkedHashSet<>();
List<DeptTree> trees= new ArrayList<>();
Set<DeptTree> depts = new LinkedHashSet<>();
List<String> deptNames = deptDtos.stream().map(DeptTree::getName).collect(Collectors.toList());
boolean isChild;
@@ -191,9 +217,6 @@ public class DeptServiceImpl implements DeptService {
}
}
if (CollectionUtil.isEmpty(trees)) {
trees = depts;
}
Map<String, Object> map = new HashMap<>(2);
map.put("totalElements", deptDtos.size());
map.put("content", CollectionUtil.isEmpty(trees) ? deptDtos : trees);

View File

@@ -33,6 +33,7 @@ import org.nl.modules.common.utils.*;
import org.nl.modules.common.utils.dto.CurrentUser;
import org.nl.modules.security.service.OnlineUserService;
import org.nl.modules.system.domain.User;
import org.nl.modules.system.service.DeptService;
import org.nl.modules.system.service.UserService;
import org.nl.modules.system.service.dto.UserQueryCriteria;
@@ -66,11 +67,18 @@ public class UserServiceImpl implements UserService {
private final FileProperties properties;
private final RedisUtils redisUtils;
private final OnlineUserService onlineUserService;
private final DeptService deptService;
@Override
public Object queryAll(UserQueryCriteria criteria, Pageable pageable) {
if(criteria.getNeedAll()!=null && criteria.getNeedAll()){
Set<Long> pidChild = deptService.findPidChild(criteria.getDeptId());
criteria.getDeptIds().addAll(pidChild);
criteria.getDeptIds().add(criteria.getDeptId());
criteria.setDeptId(null);
}
JSONObject o = (JSONObject)JSON.toJSON(criteria);
HashMap map = MapOf.of("user_id", MapUtil.getStr(o, "user_id")
, "blurry", MapUtil.getStr(o, "blurry")

View File

@@ -75,3 +75,20 @@
ENDSELECT
ENDPAGEQUERY
ENDIF
IF 输入.flag = "2"
PAGEQUERY
SELECT
max(t3.childId)
from
(
select *,
if( find_in_set(t1.pid, @p) > 0,@p := concat(@p,',',id),0 ) as childId
from
(select dept_id as id, pid from sys_dept t order by id) t1,
(select @p := '输入.pid') t2
) t3
where childId != '0'
ENDSELECT
ENDPAGEQUERY
ENDIF

View File

@@ -14,8 +14,8 @@
## 表字段对应输入参数
#################################################
输入.flag TYPEAS s_string
输入.deptIds TYPEAS s_string
输入.deptId TYPEAS s_string
输入.deptIds TYPEAS f_string
输入.deptId TYPEAS f_string
输入.id TYPEAS s_string
输入.blurry TYPEAS s_string
输入.is_used TYPEAS s_string
@@ -60,7 +60,7 @@
sys_user.id = 输入.id
ENDOPTION
OPTION 输入.deptIds <> ""
sys_user.dept_id in 输入.deptIds
sys_user_dept.dept_id in 输入.deptIds
ENDOPTION
OPTION 输入.blurry <> ""
(email like 输入.blurry or username like 输入.blurry or nickName like 输入.blurry)
@@ -69,7 +69,7 @@
sys_user.is_used = 输入.enabled
ENDOPTION
OPTION 输入.deptId <> ""
sys_user.dept_id = 输入.deptId
sys_user_dept.dept_id = 输入.deptId
ENDOPTION
OPTION 输入.startTime <> ""
sys_user.create_time >= 输入.startTime