serv-资源修改
This commit is contained in:
@@ -245,9 +245,69 @@
|
||||
WHERE user_id = #{userInfo.userID} AND deleted = 0
|
||||
</update>
|
||||
|
||||
<!-- selectUserInfoTotal -->
|
||||
<!-- 获取用户完整部门路径 -->
|
||||
<select id="getUserDeptPath" resultType="java.lang.String">
|
||||
WITH RECURSIVE dept_hierarchy AS (
|
||||
-- 基础查询:获取用户直接所属的部门
|
||||
SELECT
|
||||
tsd.dept_id,
|
||||
tsd.name,
|
||||
tsd.parent_id,
|
||||
tsd.name as dept_path,
|
||||
1 as level
|
||||
FROM tb_sys_user_info tsui
|
||||
INNER JOIN tb_sys_user_dept_role tsudr ON tsui.user_id = tsudr.user_id
|
||||
INNER JOIN tb_sys_dept tsd ON tsudr.dept_id = tsd.dept_id
|
||||
WHERE tsui.user_id = #{userId} AND tsui.deleted = 0
|
||||
|
||||
UNION ALL
|
||||
|
||||
-- 递归查询:向上查找父部门
|
||||
SELECT
|
||||
p.dept_id,
|
||||
p.name,
|
||||
p.parent_id,
|
||||
CONCAT(p.name, '/', dh.dept_path) as dept_path,
|
||||
dh.level + 1 as level
|
||||
FROM tb_sys_dept p
|
||||
INNER JOIN dept_hierarchy dh ON p.dept_id = dh.parent_id
|
||||
WHERE p.deleted = 0
|
||||
)
|
||||
SELECT dh.dept_path
|
||||
FROM dept_hierarchy dh
|
||||
WHERE dh.parent_id IS NULL -- 只取最顶层的部门路径
|
||||
LIMIT 1
|
||||
</select>
|
||||
|
||||
<select id="selectUserInfoTotal" resultMap="UserInfoTotalResultMap">
|
||||
<!-- selectUserInfoTotal -->
|
||||
|
||||
<select id="selectUserInfoTotal" resultMap="UserInfoTotalResultMap">
|
||||
WITH RECURSIVE dept_hierarchy AS (
|
||||
-- 基础查询:获取用户直接所属的部门
|
||||
SELECT
|
||||
tsd.dept_id,
|
||||
tsd.name,
|
||||
tsd.parent_id,
|
||||
tsd.name as dept_path,
|
||||
1 as level
|
||||
FROM tb_sys_user_info tsui
|
||||
INNER JOIN tb_sys_user_dept_role tsudr ON tsui.user_id = tsudr.user_id
|
||||
INNER JOIN tb_sys_dept tsd ON tsudr.dept_id = tsd.dept_id
|
||||
WHERE tsui.user_id = #{userId} AND tsui.deleted = 0
|
||||
|
||||
UNION ALL
|
||||
|
||||
-- 递归查询:向上查找父部门
|
||||
SELECT
|
||||
p.dept_id,
|
||||
p.name,
|
||||
p.parent_id,
|
||||
CONCAT(p.name, '/', dh.dept_path) as dept_path,
|
||||
dh.level + 1 as level
|
||||
FROM tb_sys_dept p
|
||||
INNER JOIN dept_hierarchy dh ON p.dept_id = dh.parent_id
|
||||
WHERE p.deleted = 0
|
||||
)
|
||||
SELECT
|
||||
tus.id as user_id,
|
||||
tus.username,
|
||||
@@ -255,7 +315,7 @@
|
||||
tus.email,
|
||||
tsui.avatar,
|
||||
tsui.gender,
|
||||
tsd.name as dept_name,
|
||||
dh.dept_path as dept_name,
|
||||
tsr.name as role_name,
|
||||
tsui.level,
|
||||
tsui.id_card,
|
||||
@@ -263,8 +323,10 @@
|
||||
FROM tb_sys_user_info tsui
|
||||
INNER JOIN tb_sys_user tus ON tsui.user_id = tus.id
|
||||
INNER JOIN tb_sys_user_dept_role tsudr ON tsui.user_id = tsudr.user_id
|
||||
INNER JOIN tb_sys_dept tsd ON tsudr.dept_id = tsd.dept_id
|
||||
INNER JOIN dept_hierarchy dh ON tsudr.dept_id = dh.dept_id
|
||||
INNER JOIN tb_sys_role tsr ON tsudr.role_id = tsr.role_id
|
||||
WHERE tsui.user_id = #{userId} AND tsui.deleted = 0
|
||||
WHERE tsui.user_id = #{userId}
|
||||
AND tsui.deleted = 0
|
||||
AND dh.parent_id IS NULL -- 只取最顶层的部门路径
|
||||
</select>
|
||||
</mapper>
|
||||
|
||||
Reference in New Issue
Block a user