<?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.ruoyi.web.modules.merchant.mapper.MerchantBindMapper">

    <select id="selectAdminUsersByKeyword" resultType="com.ruoyi.web.modules.merchant.vo.MerchantAdminUserOptionVO">
        select distinct u.user_id as userId,
               u.user_name as userName,
               u.nick_name as nickName,
               u.phonenumber as phonenumber
        from sys_user u
        inner join sys_user_role ur on u.user_id = ur.user_id
        inner join sys_role r on ur.role_id = r.role_id and r.del_flag = '0' and r.status = '0'
        where u.del_flag = '0' and u.status = '0'
          and (r.role_key = #{roleKey} or cast(r.role_id as char) = #{roleKey})
        <if test="keyword != null and keyword != ''">
            and (
                u.user_name like concat('%', #{keyword}, '%')
                or u.nick_name like concat('%', #{keyword}, '%')
                or u.phonenumber like concat('%', #{keyword}, '%')
            )
        </if>
        order by u.user_id desc
        limit 50
    </select>

    <select id="countUserHasRole" resultType="int">
        select count(1)
        from sys_user_role ur
        inner join sys_role r on ur.role_id = r.role_id and r.del_flag = '0'
        where ur.user_id = #{userId}
          and (r.role_key = #{roleKey} or cast(r.role_id as char) = #{roleKey})
    </select>
</mapper>
