diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/rest/DeptController.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/rest/DeptController.java index 04d3652..7aa3024 100644 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/rest/DeptController.java +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/rest/DeptController.java @@ -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 allTree(DeptQueryCriteria criteria) throws Exception { + List deptDtos = deptService.queryAll(criteria, true); + JSONArray array = JSON.parseArray(JSON.toJSONString(deptDtos)); + List 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) diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/rest/UserController.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/rest/UserController.java index 608ff6d..592f25c 100644 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/rest/UserController.java +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/rest/UserController.java @@ -85,25 +85,7 @@ public class UserController { @GetMapping @SaCheckPermission("user:list") public ResponseEntity 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 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("新增用户") diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/DeptService.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/DeptService.java index 8b9298b..634eea5 100644 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/DeptService.java +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/DeptService.java @@ -72,6 +72,12 @@ public interface DeptService { */ void update(Dept resources); + /** + * 查询pid所有子集 + * + */ + Set findPidChild(Long pid); + /** * 删除 * diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/dto/DeptTree.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/dto/DeptTree.java index 7c1528a..ca8e585 100644 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/dto/DeptTree.java +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/dto/DeptTree.java @@ -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 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; - } - } diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/dto/UserQueryCriteria.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/dto/UserQueryCriteria.java index 2db196e..2052510 100644 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/dto/UserQueryCriteria.java +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/dto/UserQueryCriteria.java @@ -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; diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/impl/DeptServiceImpl.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/impl/DeptServiceImpl.java index f11973e..e783a80 100644 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/impl/DeptServiceImpl.java +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/impl/DeptServiceImpl.java @@ -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 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 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 deptDtos) { - Set trees = new LinkedHashSet<>(); + List trees= new ArrayList<>(); Set depts = new LinkedHashSet<>(); List 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 map = new HashMap<>(2); map.put("totalElements", deptDtos.size()); map.put("content", CollectionUtil.isEmpty(trees) ? deptDtos : trees); diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/impl/UserServiceImpl.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/impl/UserServiceImpl.java index 583542f..dc0951a 100644 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/impl/UserServiceImpl.java +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/impl/UserServiceImpl.java @@ -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 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") diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/wql/SYS_USER.wql b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/wql/SYS_USER.wql deleted file mode 100644 index e69de29..0000000 diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/sso/wql/SYS_DEPT.wql b/nladmin-system/nlsso-server/src/main/java/org/nl/sso/wql/SYS_DEPT.wql index 84e76dc..2ac1a5b 100644 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/sso/wql/SYS_DEPT.wql +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/sso/wql/SYS_DEPT.wql @@ -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 diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/sso/wql/SYS_USER.wql b/nladmin-system/nlsso-server/src/main/java/org/nl/sso/wql/SYS_USER.wql index 4dd34f1..4027ded 100644 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/sso/wql/SYS_USER.wql +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/sso/wql/SYS_USER.wql @@ -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 diff --git a/nladmin-ui/src/api/system/dept.js b/nladmin-ui/src/api/system/dept.js index ed4f944..b07cc27 100644 --- a/nladmin-ui/src/api/system/dept.js +++ b/nladmin-ui/src/api/system/dept.js @@ -8,6 +8,13 @@ export function getDepts(params) { }) } +export function getDeptTreee() { + return request({ + url: '/api/dept/allTree', + method: 'get' + }) +} + export function getDeptSuperior(ids) { const data = ids.length || ids.length === 0 ? ids : Array.of(ids) return request({ diff --git a/nladmin-ui/src/views/system/user/index.vue b/nladmin-ui/src/views/system/user/index.vue index f76dc76..2c5c548 100644 --- a/nladmin-ui/src/views/system/user/index.vue +++ b/nladmin-ui/src/views/system/user/index.vue @@ -16,10 +16,7 @@ @@ -200,7 +197,7 @@