完成了第一版

This commit is contained in:
2025-05-14 10:40:17 +08:00
parent 1a9822350a
commit 26f9fe2a20
11 changed files with 129 additions and 73 deletions

View File

@ -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 &lt; 50000
)
SELECT id
FROM user_path
ORDER BY depth DESC
</select>
</mapper>