组织人员树
This commit is contained in:
parent
0a7fd633d9
commit
a8adc42f4b
|
|
@ -449,26 +449,12 @@ public class SysUserController extends BaseController {
|
||||||
return error("系统异常,请联系管理员");
|
return error("系统异常,请联系管理员");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取部门人员树列表
|
|
||||||
*/
|
|
||||||
@RequiresPermissionsOrInnerAuth(innerAuth = @InnerAuth, requiresPermissions = @RequiresPermissions("system:user:list"))
|
|
||||||
@GetMapping("/deptUserTree")
|
|
||||||
public AjaxResult deptUserTree(SysDept dept) {
|
|
||||||
try {
|
|
||||||
return success(deptService.selectDeptUserTreeList(dept));
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.error(e.toString(), e);
|
|
||||||
}
|
|
||||||
return error("系统异常,请联系管理员");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据角色列表获取部门人员树列表
|
* 根据角色列表获取部门人员树列表
|
||||||
*/
|
*/
|
||||||
@RequiresPermissionsOrInnerAuth(innerAuth = @InnerAuth, requiresPermissions = @RequiresPermissions("system:user:list"))
|
@RequiresPermissionsOrInnerAuth(innerAuth = @InnerAuth, requiresPermissions = @RequiresPermissions("system:user:list"))
|
||||||
@PostMapping("/deptUserTreeInRoleIds")
|
@PostMapping("/deptUserTree")
|
||||||
public AjaxResult deptUserTreeInRoleIds(@RequestBody SysUser sysUser) {
|
public AjaxResult deptUserTree(@RequestBody SysUser sysUser) {
|
||||||
try {
|
try {
|
||||||
return success(deptService.selectDeptUserTree(sysUser.getRoleIds()));
|
return success(deptService.selectDeptUserTree(sysUser.getRoleIds()));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
|
||||||
|
|
@ -157,11 +157,4 @@ public interface SysUserMapper {
|
||||||
|
|
||||||
Integer approvalStatus(Long userId);
|
Integer approvalStatus(Long userId);
|
||||||
|
|
||||||
/**
|
|
||||||
* 组织人员树
|
|
||||||
* @param dept
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
List<SysDept> getTree(SysDept dept);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,23 +27,12 @@ public interface ISysDeptService
|
||||||
*/
|
*/
|
||||||
public List<TreeSelect> selectDeptTreeList(SysDept dept);
|
public List<TreeSelect> selectDeptTreeList(SysDept dept);
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询部门人员树结构信息
|
|
||||||
*
|
|
||||||
* @param dept 部门信息
|
|
||||||
* @return 部门树信息集合
|
|
||||||
*/
|
|
||||||
public List<TreeSelect> selectDeptUserTreeList(SysDept dept);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据角色列表查询部门人员树结构信息
|
* 根据角色列表查询部门人员树结构信息
|
||||||
*
|
*
|
||||||
* @param dept 部门信息
|
|
||||||
* @param roleIds 角色列表
|
* @param roleIds 角色列表
|
||||||
* @return 部门树信息集合
|
* @return 部门树信息集合
|
||||||
*/
|
*/
|
||||||
public List<TreeSelect> selectDeptUserTree(SysDept dept, List<Long> roleIds);
|
|
||||||
|
|
||||||
public List<TreeSelect> selectDeptUserTree(Long[] roleIds);
|
public List<TreeSelect> selectDeptUserTree(Long[] roleIds);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -78,18 +78,9 @@ public class SysDeptServiceImpl implements ISysDeptService
|
||||||
/**
|
/**
|
||||||
* 根据角色列表查询部门人员树结构信息
|
* 根据角色列表查询部门人员树结构信息
|
||||||
*
|
*
|
||||||
* @param dept 部门信息
|
|
||||||
* @param roleIds 角色列表
|
* @param roleIds 角色列表
|
||||||
* @return 部门树信息集合
|
* @return 部门树信息集合
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
@DataScope(deptAlias = "d")
|
|
||||||
public List<TreeSelect> selectDeptUserTree(SysDept dept, List<Long> roleIds)
|
|
||||||
{
|
|
||||||
List<SysDept> depts = deptMapper.selectDeptUserList(dept, roleIds);
|
|
||||||
return buildDeptTreeSelect(depts);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@DataScope(deptAlias = "d")
|
@DataScope(deptAlias = "d")
|
||||||
public List<TreeSelect> selectDeptUserTree(Long[] roleIds)
|
public List<TreeSelect> selectDeptUserTree(Long[] roleIds)
|
||||||
|
|
@ -98,38 +89,6 @@ public class SysDeptServiceImpl implements ISysDeptService
|
||||||
return buildDeptTreeSelect(depts);
|
return buildDeptTreeSelect(depts);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询部门人员树结构信息
|
|
||||||
*
|
|
||||||
* @param dept 部门信息
|
|
||||||
* @return 部门树信息集合
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public List<TreeSelect> selectDeptUserTreeList(SysDept dept)
|
|
||||||
{
|
|
||||||
if (dept != null && dept.getDeptId() != null && dept.getDeptId() == 0L) {
|
|
||||||
List<SysDept> userList = userMapper.getTree(dept);
|
|
||||||
return buildDeptTreeSelect(userList);
|
|
||||||
}
|
|
||||||
List<SysDept> depts = SpringUtils.getAopProxy(this).selectDeptList(dept);
|
|
||||||
// for (SysDept sysDept : depts) {
|
|
||||||
// SysUser paramUser = new SysUser();
|
|
||||||
// paramUser.setDeptId(sysDept.getDeptId());
|
|
||||||
// List<SysUser> users = userMapper.selectUserList(paramUser);
|
|
||||||
//
|
|
||||||
// List<SysUser> sysUsers = new ArrayList<>();
|
|
||||||
// for (SysUser user : users) {
|
|
||||||
// SysUser userResult = userMapper.selectUserById(user.getUserId());
|
|
||||||
// user.setRoles(userResult.getRoles());
|
|
||||||
// if (user.getDeptId().equals(sysDept.getDeptId())) {
|
|
||||||
// sysUsers.add(user);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// sysDept.setSysUsers(sysUsers);
|
|
||||||
// }
|
|
||||||
return buildDeptTreeSelect(depts);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构建前端所需要树结构
|
* 构建前端所需要树结构
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -202,71 +202,6 @@
|
||||||
and del_flag = '0' limit 1
|
and del_flag = '0' limit 1
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="getTree" resultType="com.bonus.system.api.domain.SysDept">
|
|
||||||
WITH RECURSIVE DeptHierarchy AS (
|
|
||||||
SELECT
|
|
||||||
deptId,
|
|
||||||
parentId,
|
|
||||||
deptName,
|
|
||||||
0 AS level -- 初始级别为 0
|
|
||||||
FROM (
|
|
||||||
SELECT
|
|
||||||
d.dept_id AS deptId,
|
|
||||||
d.parent_id AS parentId,
|
|
||||||
d.dept_name AS deptName
|
|
||||||
FROM sys_dept d
|
|
||||||
WHERE d.del_flag = '0'
|
|
||||||
AND d.STATUS = '0'
|
|
||||||
|
|
||||||
UNION
|
|
||||||
|
|
||||||
SELECT
|
|
||||||
su.user_id AS deptId,
|
|
||||||
su.dept_id AS parentId,
|
|
||||||
su.nick_name AS deptName
|
|
||||||
FROM sys_user su
|
|
||||||
LEFT JOIN sys_dept sd ON su.dept_id = sd.dept_id
|
|
||||||
WHERE su.del_flag = '0'
|
|
||||||
) AS combined_results
|
|
||||||
WHERE parentId = 0 -- 选择根级别(parentId 为 0)
|
|
||||||
|
|
||||||
UNION ALL
|
|
||||||
|
|
||||||
SELECT
|
|
||||||
cr.deptId,
|
|
||||||
cr.parentId,
|
|
||||||
cr.deptName,
|
|
||||||
ch.level + 1 -- 级别递增
|
|
||||||
FROM DeptHierarchy ch
|
|
||||||
JOIN (
|
|
||||||
SELECT
|
|
||||||
d.dept_id AS deptId,
|
|
||||||
d.parent_id AS parentId,
|
|
||||||
d.dept_name AS deptName
|
|
||||||
FROM sys_dept d
|
|
||||||
WHERE d.del_flag = '0'
|
|
||||||
AND d.STATUS = '0'
|
|
||||||
|
|
||||||
UNION
|
|
||||||
|
|
||||||
SELECT
|
|
||||||
su.user_id AS deptId,
|
|
||||||
su.dept_id AS parentId,
|
|
||||||
su.nick_name AS deptName
|
|
||||||
FROM sys_user su
|
|
||||||
LEFT JOIN sys_dept sd ON su.dept_id = sd.dept_id
|
|
||||||
WHERE su.del_flag = '0'
|
|
||||||
) AS cr ON cr.parentId = ch.deptId -- 根据父级进行连接
|
|
||||||
)
|
|
||||||
|
|
||||||
SELECT * FROM DeptHierarchy
|
|
||||||
WHERE level <= 3 -- 只选择前 3 级
|
|
||||||
ORDER BY level, deptId; -- 根据级别和部门ID排序
|
|
||||||
|
|
||||||
</select>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<insert id="insertUser" parameterType="SysUser" useGeneratedKeys="true" keyProperty="userId">
|
<insert id="insertUser" parameterType="SysUser" useGeneratedKeys="true" keyProperty="userId">
|
||||||
insert into sys_user(
|
insert into sys_user(
|
||||||
<if test="userId != null and userId != 0">user_id,</if>
|
<if test="userId != null and userId != 0">user_id,</if>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue