<?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.RouterRoleMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="cn.bunny.dao.entity.system.RouterRole">
        <id column="id" property="id"/>
        <result column="router_id" property="routerId"/>
        <result column="role_id" property="roleId"/>
        <result column="create_user" property="createUser"/>
        <result column="update_time" property="updateTime"/>
        <result column="update_user" property="updateUser"/>
        <result column="create_time" property="createTime"/>
        <result column="is_deleted" property="isDeleted"/>
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, router_id, role_id, create_user, update_time, update_user, create_time, is_deleted
    </sql>

    <!-- 根据路由id删除所有角色和路由信息 -->
    <delete id="deleteBatchIdsByRouterIdsWithPhysics">
        delete
        from sys_router_role
        where router_id in
        <foreach collection="routerIds" item="id" open="(" close=")" separator=",">
            #{id}
        </foreach>
    </delete>

    <!-- 根据角色id列表删除角色和路由相关 -->
    <delete id="deleteBatchIdsByRoleIdsWithPhysics">
        delete
        from sys_router_role
        where role_id in
        <foreach collection="roleIds" item="id" open="(" close=")" separator=",">
            #{id}
        </foreach>
    </delete>

    <!-- 查看所有路由的角色 -->
    <select id="viewRouterRolesWithAll" resultType="cn.bunny.dao.view.ViewRouterRole">
        SELECT rr.router_id,
               router.parent_id,
               router.path,
               router.component,
               router.frame_src,
               router.route_name,
               router.title,
               router.menu_type,
               router.icon,
               router.router_rank,
               router.visible,
               rr.role_id,
               role.role_code,
               role.description
        FROM sys_router_role rr
                 LEFT JOIN sys_router router ON rr.router_id = router.id
                 LEFT JOIN sys_role role ON rr.role_id = role.id
    </select>

</mapper>
