<?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="com.qiaoba.module.system.mapper.SysUserRoleMapper">

    <select id="selectRoleIdsByUserId" resultType="string">
        select t1.role_id from sys_user_role t1
        left join sys_role t2 on t2.role_id = t1.role_id
        where t1.user_id = #{userId}
        <if test="status != null and status != ''">
            and t2.status = #{status}
        </if>
    </select>

    <select id="selectRoleDtoByUserId" resultType="com.qiaoba.api.auth.entity.dto.RoleDto">
        select t2.role_id,t2.role_key,t2.role_name,t2.data_scope from sys_user_role t1
        left join sys_role t2 on t2.role_id = t1.role_id
        where t1.user_id = #{userId}
        <if test="status != null and status != ''">
            and t2.status = #{status}
        </if>
    </select>

    <delete id="deleteByRoleIdAndUserIds">
        delete from sys_user_role where role_id = #{roleId} and user_id in
        <foreach collection="list" item="userId" open="(" separator="," close=")">
            #{userId}
        </foreach>
    </delete>

    <delete id="deleteByUserIds">
        delete from sys_user_role where user_id in
        <foreach collection="list" item="userId" open="(" separator="," close=")">
            #{userId}
        </foreach>
    </delete>
</mapper>
