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

    <select id="checkRoleNameUnique" parameterType="String" resultType="string">
        select role_id from sys_role
        where role_name = #{roleName}
        <if test="roleId != null and roleId != 0">
            and role_id != #{roleId}
        </if>
    </select>

    <select id="checkRoleKeyUnique" parameterType="String" resultType="string">
        select role_id from sys_role
        where role_key = #{roleKey}
        <if test="roleId != null and roleId != 0">
            and role_id != #{roleId}
        </if>
    </select>

    <select id="selectBindUserByRoleId" resultType="string">
        SELECT t2.nickname
        FROM sys_user_role t1
        left join sys_user t2
        on t1.user_id = t2.user_id
        where t1.role_id in
        <foreach collection="list" item="roleId" open="(" separator="," close=")">
            #{roleId}
        </foreach>
    </select>
</mapper>
