auth-server-java/service/src/main/resources/mapper/RouterMapper.xml

82 lines
3.2 KiB
XML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.bunny.services.mapper.RouterMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="cn.bunny.dao.entity.system.Router">
<id column="id" property="id"/>
<result column="parent_id" property="parentId"/>
<result column="path" property="path"/>
<result column="component" property="component"/>
<result column="frame_src" property="frameSrc"/>
<result column="route_name" property="routeName"/>
<result column="title" property="title"/>
<result column="menu_type" property="menuType"/>
<result column="icon" property="icon"/>
<result column="router_rank" property="routerRank"/>
<result column="visible" property="visible"/>
<result column="create_user" property="createUser"/>
<result column="update_user" property="updateUser"/>
<result column="update_time" property="updateTime"/>
<result column="create_time" property="createTime"/>
<result column="is_deleted" property="isDeleted"/>
</resultMap>
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
id, parent_id, path, component, frame_src, route_name, title, menuType, icon, router_rank, visible, create_user, update_user, update_time, create_time, is_deleted
</sql>
<!-- 物理删除路由菜单 -->
<delete id="deleteBatchIdsWithPhysics">
delete
from sys_router
where id in
<foreach collection="ids" item="id" open="(" close=")" separator=",">
#{id}
</foreach>
</delete>
<!-- 根据用户ID查找路由列表 -->
<select id="selectListByUserId" resultType="java.lang.Long">
SELECT router.id
FROM sys_user_role user_role
LEFT JOIN sys_user user ON user_role.user_id = user.id
LEFT JOIN sys_router_role router_role ON user_role.role_id = router_role.role_id
LEFT JOIN sys_router router ON router_role.router_id = router.id
WHERE user.id = #{userId}
</select>
<!-- 递归查询所有父级Id直到查询到父级Id为0 -->
<select id="selectParentListByRouterId" resultType="cn.bunny.dao.entity.system.Router">
WITH RECURSIVE ParentChain AS (
SELECT * FROM sys_router
WHERE id IN
<foreach collection="ids" item="id" open="(" close=")" separator=",">
#{id}
</foreach>
UNION ALL
SELECT r.* FROM sys_router r
INNER JOIN ParentChain pc ON r.id = pc.parent_id
)
SELECT
<include refid="Base_Column_List"/>
FROM ParentChain;
</select>
<!-- 管理菜单列表 -->
<select id="selectListByPage" resultType="cn.bunny.dao.entity.system.Router">
select *
from sys_router
<where>
<if test="dto.title != null and dto.title != ''">
and title like CONCAT('%',#{dto.title},'%')
</if>
<if test="dto.visible != null">
and visible = #{dto.visible}
</if>
</where>
order by router_rank
</select>
</mapper>