diff --git a/yanzhu-modules/yanzhu-system/src/main/java/com/yanzhu/system/controller/SysDeptController.java b/yanzhu-modules/yanzhu-system/src/main/java/com/yanzhu/system/controller/SysDeptController.java index 447f4215..85503c06 100644 --- a/yanzhu-modules/yanzhu-system/src/main/java/com/yanzhu/system/controller/SysDeptController.java +++ b/yanzhu-modules/yanzhu-system/src/main/java/com/yanzhu/system/controller/SysDeptController.java @@ -1,5 +1,6 @@ package com.yanzhu.system.controller; +import java.util.ArrayList; import java.util.List; import java.util.concurrent.TimeUnit; @@ -7,6 +8,7 @@ import com.yanzhu.common.core.constant.CacheConstants; import com.yanzhu.common.core.constant.Constants; import com.yanzhu.common.core.enums.IsDelEnums; import com.yanzhu.common.redis.service.RedisService; +import com.yanzhu.system.domain.vo.TreeSelect; import org.apache.commons.lang3.ArrayUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; @@ -159,4 +161,14 @@ public class SysDeptController extends BaseController redisService.setCacheObject(key,depts, Constants.CAPTCHA_EXPIRATION, TimeUnit.MINUTES); return success(depts); } + @RequiresPermissions("system:dept:list") + @GetMapping("/deptTree") + public AjaxResult userDeptTree(){ + SysDept comp= SecurityUtils.getLoginUser().getSysUser().getComp(); + if(comp==null){ + return success(deptService.buildDeptTreeSelect(new ArrayList<>())); + } + List treeList = deptService.buildDeptTreeSelect(deptService.selectDeptListForComp(comp)); + return success(treeList); + } } diff --git a/yanzhu-modules/yanzhu-system/src/main/java/com/yanzhu/system/mapper/SysDeptMapper.java b/yanzhu-modules/yanzhu-system/src/main/java/com/yanzhu/system/mapper/SysDeptMapper.java index 6c7dc7f0..fc2a45c7 100644 --- a/yanzhu-modules/yanzhu-system/src/main/java/com/yanzhu/system/mapper/SysDeptMapper.java +++ b/yanzhu-modules/yanzhu-system/src/main/java/com/yanzhu/system/mapper/SysDeptMapper.java @@ -19,6 +19,11 @@ public interface SysDeptMapper */ public List selectDeptList(SysDept dept); + + /** + * 根据deptId查询此ID及下面的子项,用于构建树 + */ + public List selectDeptListForComp(SysDept dept); /** * 根据角色ID查询部门树信息 * diff --git a/yanzhu-modules/yanzhu-system/src/main/java/com/yanzhu/system/service/ISysDeptService.java b/yanzhu-modules/yanzhu-system/src/main/java/com/yanzhu/system/service/ISysDeptService.java index bb036296..a972d88e 100644 --- a/yanzhu-modules/yanzhu-system/src/main/java/com/yanzhu/system/service/ISysDeptService.java +++ b/yanzhu-modules/yanzhu-system/src/main/java/com/yanzhu/system/service/ISysDeptService.java @@ -121,4 +121,8 @@ public interface ISysDeptService * @return 结果 */ public int deleteDeptById(Long deptId); + /** + * 根据deptId查询此ID及下面的子项,用于构建树 + */ + List selectDeptListForComp(SysDept comp); } diff --git a/yanzhu-modules/yanzhu-system/src/main/java/com/yanzhu/system/service/impl/SysDeptServiceImpl.java b/yanzhu-modules/yanzhu-system/src/main/java/com/yanzhu/system/service/impl/SysDeptServiceImpl.java index cd9000eb..cbbdb1fa 100644 --- a/yanzhu-modules/yanzhu-system/src/main/java/com/yanzhu/system/service/impl/SysDeptServiceImpl.java +++ b/yanzhu-modules/yanzhu-system/src/main/java/com/yanzhu/system/service/impl/SysDeptServiceImpl.java @@ -293,6 +293,13 @@ public class SysDeptServiceImpl implements ISysDeptService { return deptMapper.deleteDeptById(deptId); } + /** + * 根据deptId查询此ID及下面的子项,用于构建树 + */ + @Override + public List selectDeptListForComp(SysDept comp) { + return deptMapper.selectDeptListForComp(comp); + } /** * 递归列表 diff --git a/yanzhu-modules/yanzhu-system/src/main/resources/mapper/system/SysDeptMapper.xml b/yanzhu-modules/yanzhu-system/src/main/resources/mapper/system/SysDeptMapper.xml index 0f7e0c31..16d20708 100644 --- a/yanzhu-modules/yanzhu-system/src/main/resources/mapper/system/SysDeptMapper.xml +++ b/yanzhu-modules/yanzhu-system/src/main/resources/mapper/system/SysDeptMapper.xml @@ -56,7 +56,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ${params.dataScope} order by d.parent_id, d.order_num - +