Ver Fonte

支部(部门)树形结构

Wang Zi Wen há 2 anos atrás
pai
commit
1ead5f26b5

+ 46 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDeptController.java

@@ -34,6 +34,52 @@ public class SysDeptController extends BaseController
     @Autowired
     private ISysDeptService deptService;
 
+    /**
+     * 获取部门下拉树列表
+     */
+    @GetMapping("/treeselect")
+    public AjaxResult treeselect(SysDept dept)
+    {
+        List<SysDept> depts = deptService.selectDeptList(dept);
+        return AjaxResult.success(deptService.buildDeptTreeSelect(depts));
+    }
+
+    /**
+     * 获取部门下拉树列表(全部)
+     */
+    @GetMapping("/alltreeselect")
+    public AjaxResult alltreeselect(SysDept dept)
+    {
+        List<SysDept> depts = deptService.selectAllDeptList(dept);
+        return AjaxResult.success(deptService.buildDeptTreeSelect(depts));
+    }
+
+    /**
+     * 加载对应角色部门列表树
+     */
+    @GetMapping(value = "/roleDeptTreeselect/{roleId}")
+    public AjaxResult roleDeptTreeselect(@PathVariable("roleId") Long roleId)
+    {
+        List<SysDept> depts = deptService.selectDeptList(new SysDept());
+        AjaxResult ajax = AjaxResult.success();
+        ajax.put("checkedKeys", deptService.selectDeptListByRoleId(roleId));
+        ajax.put("depts", deptService.buildDeptTreeSelect(depts));
+        return ajax;
+    }
+
+    /**
+     * 加载对应用户部门列表树
+     */
+    @GetMapping(value = "/userDeptTreeselect/{userId}")
+    public AjaxResult userDeptTreeselect(@PathVariable("userId") Long userId)
+    {
+        List<SysDept> depts = deptService.selectDeptList(new SysDept());
+        AjaxResult ajax = AjaxResult.success();
+        ajax.put("checkedKeys", deptService.selectDeptListByUserId(userId));
+        ajax.put("depts", deptService.buildDeptTreeSelect(depts));
+        return ajax;
+    }
+
     /**
      * 获取部门列表
      */

+ 11 - 0
ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/SysUser.java

@@ -89,6 +89,17 @@ public class SysUser extends BaseEntity
     /** 角色ID */
     private Long roleId;
 
+    /** 部门树选择项是否关联显示(0:父子不互相关联显示 1:父子互相关联显示 ) */
+    private boolean isDeptCheckStrictly;
+
+    public boolean isDeptCheckStrictly() {
+        return isDeptCheckStrictly;
+    }
+
+    public void setDeptCheckStrictly(boolean deptCheckStrictly) {
+        isDeptCheckStrictly = deptCheckStrictly;
+    }
+
     public SysUser()
     {
 

+ 4 - 0
ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysDeptMapper.java

@@ -19,6 +19,8 @@ public interface SysDeptMapper
      */
     public List<SysDept> selectDeptList(SysDept dept);
 
+    public List<SysDept> selectAllDeptList(SysDept dept);
+
     /**
      * 根据角色ID查询部门树信息
      * 
@@ -28,6 +30,8 @@ public interface SysDeptMapper
      */
     public List<Long> selectDeptListByRoleId(@Param("roleId") Long roleId, @Param("deptCheckStrictly") boolean deptCheckStrictly);
 
+    public List<Integer> selectDeptListByUserId(@Param("userId") Long userId, @Param("deptCheckStrictly") boolean deptCheckStrictly);
+
     /**
      * 根据部门ID查询信息
      * 

+ 4 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDeptService.java

@@ -19,6 +19,8 @@ public interface ISysDeptService
      */
     public List<SysDept> selectDeptList(SysDept dept);
 
+    public List<SysDept> selectAllDeptList(SysDept dept);
+
     /**
      * 查询部门树结构信息
      * 
@@ -51,6 +53,8 @@ public interface ISysDeptService
      */
     public List<Long> selectDeptListByRoleId(Long roleId);
 
+    public List<Integer> selectDeptListByUserId(Long userId);
+
     /**
      * 根据部门ID查询信息
      * 

+ 19 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java

@@ -4,6 +4,8 @@ import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 import java.util.stream.Collectors;
+
+import com.ruoyi.system.mapper.SysUserMapper;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.ruoyi.common.annotation.DataScope;
@@ -21,6 +23,8 @@ import com.ruoyi.system.mapper.SysDeptMapper;
 import com.ruoyi.system.mapper.SysRoleMapper;
 import com.ruoyi.system.service.ISysDeptService;
 
+import javax.annotation.Resource;
+
 /**
  * 部门管理 服务实现
  * 
@@ -35,6 +39,9 @@ public class SysDeptServiceImpl implements ISysDeptService
     @Autowired
     private SysRoleMapper roleMapper;
 
+    @Autowired
+    private SysUserMapper userMapper;
+
     /**
      * 查询部门管理数据
      * 
@@ -48,6 +55,12 @@ public class SysDeptServiceImpl implements ISysDeptService
         return deptMapper.selectDeptList(dept);
     }
 
+    @Override
+    public List<SysDept> selectAllDeptList(SysDept dept)
+    {
+        return deptMapper.selectAllDeptList(dept);
+    }
+
     /**
      * 查询部门树结构信息
      * 
@@ -114,6 +127,12 @@ public class SysDeptServiceImpl implements ISysDeptService
         return deptMapper.selectDeptListByRoleId(roleId, role.isDeptCheckStrictly());
     }
 
+    @Override
+    public List<Integer> selectDeptListByUserId(Long userId) {
+        SysUser user = userMapper.selectUserById(userId);
+        return deptMapper.selectDeptListByUserId(userId, user.isDeptCheckStrictly());
+    }
+
     /**
      * 根据部门ID查询信息
      * 

+ 27 - 0
ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml

@@ -46,6 +46,21 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 		${params.dataScope}
 		order by d.parent_id, d.order_num
     </select>
+
+	<select id="selectAllDeptList" parameterType="SysDept" resultMap="SysDeptResult">
+		<include refid="selectDeptVo"/>
+		where d.del_flag = '0'
+		<if test="parentId != null and parentId != 0">
+			AND parent_id = #{parentId}
+		</if>
+		<if test="deptName != null and deptName != ''">
+			AND dept_name like concat(concat('%',#{deptName}),'%')
+		</if>
+		<if test="status != null and status != ''">
+			AND status = #{status}
+		</if>
+		order by d.parent_id, d.order_num
+	</select>
     
     <select id="selectDeptListByRoleId" resultType="Long">
 		select d.dept_id
@@ -57,6 +72,18 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             </if>
 		order by d.parent_id, d.order_num
 	</select>
+
+	<select id="selectDeptListByUserId" resultType="Integer">
+		select d.dept_id
+		from sys_dept d
+		left join sys_user_dept rd on d.dept_id = rd.dept_id
+		where rd.user_id = #{userId}
+		<if test="deptCheckStrictly">
+			and d.dept_id not in (select d.parent_id from sys_dept d inner join sys_user_dept rd on d.dept_id =
+			rd.dept_id and rd.user_id = #{userId})
+		</if>
+		order by d.parent_id, d.order_num
+	</select>
     
     <select id="selectDeptById" parameterType="Long" resultMap="SysDeptResult">
 		select d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.phone, d.email, d.status,

+ 33 - 1
ruoyi-ui/src/api/system/dept.js

@@ -1,5 +1,37 @@
 import request from '@/utils/request'
 
+// 查询部门下拉树结构
+export function treeselect() {
+  return request({
+    url: '/system/dept/treeselect',
+    method: 'get'
+  })
+}
+
+// 查询部门下拉树结构(全部)
+export function alltreeselect() {
+  return request({
+    url: '/system/dept/alltreeselect',
+    method: 'get'
+  })
+}
+
+// 根据角色ID查询部门树结构
+export function roleDeptTreeselect(roleId) {
+  return request({
+    url: '/system/dept/roleDeptTreeselect/' + roleId,
+    method: 'get'
+  })
+}
+
+// 根据角色ID查询部门树结构
+export function userDeptTreeselect(userId) {
+  return request({
+    url: '/system/dept/userDeptTreeselect/' + userId,
+    method: 'get'
+  })
+}
+
 // 查询部门列表
 export function listDept(query) {
   return request({
@@ -49,4 +81,4 @@ export function delDept(deptId) {
     url: '/system/dept/' + deptId,
     method: 'delete'
   })
-}
+}