完成了第一版
This commit is contained in:
@ -25,4 +25,26 @@
|
||||
userRole,parentUserId,superUserList,
|
||||
isDelete,createTime,updateTime
|
||||
</sql>
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- 查询从 userId 一路到根节点的所有 id,按 depth 倒序(根先出)-->
|
||||
<select id="findPathToRoot" resultType="java.lang.Long">
|
||||
WITH RECURSIVE user_path AS (
|
||||
SELECT id, parentUserId, 1 AS depth
|
||||
FROM user_info
|
||||
WHERE id = #{userId}
|
||||
|
||||
UNION ALL
|
||||
|
||||
SELECT u.id, u.parentUserId, up.depth + 1
|
||||
FROM user_info u
|
||||
JOIN user_path up ON u.id = up.parentUserId
|
||||
WHERE up.depth < 50000
|
||||
)
|
||||
SELECT id
|
||||
FROM user_path
|
||||
ORDER BY depth DESC
|
||||
</select>
|
||||
</mapper>
|
||||
|
Reference in New Issue
Block a user