<?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.mosty.common.core.business.mapper.SysUserRoleMapper">

    <resultMap id="BaseResultMap" type="com.mosty.common.core.business.entity.SysUserRole">
            <id property="id" column="id" jdbcType="BIGINT"/>
            <result property="userId" column="user_id" jdbcType="BIGINT"/>
            <result property="roleId" column="role_id" jdbcType="BIGINT"/>
    </resultMap>

    <sql id="Base_Column_List">
        id,user_id,role_id
    </sql>

    <select id="roleUserList" resultType="com.mosty.common.core.business.entity.vo.SysUserVO">
        select * from
            sys_user_role a
        inner join
            sys_user b on a.user_id = b.id
        inner join
            sys_dept c on b.dept_id = c.id and b.root_path like concat(#{roleUserPage.rootPath}, '%') and b.xt_zxbz = 0
        where
            a.role_id = #{roleUserPage.roleId}
        <if test="roleUserPage.loginName != null and roleUserPage.loginName != '' ">
            and b.login_name like concat('%', #{roleUserPage.loginName}, '%')
        </if>
        <if test="roleUserPage.phone != null and roleUserPage.phone != '' ">
            and b.mobile = #{roleUserPage.mobile}
        </if>
        limit #{roleUserPage.current}, #{roleUserPage.size}

    </select>

    <select id="getRoleUserList" resultType="com.mosty.common.core.business.entity.vo.SysUserVO">
        select * from sys_user_role a inner join
        sys_user b on a.user_id = b.id and b.xt_zxbz = 0
        where a.role_id = #{roleId}
        <if test="userName != null and userName != ''">
            and (
                b.user_name like concat('%',#{userName},'%')
                or b.login_name like concat('%',#{userName},'%')
            )
        </if>
        <if test="phone != null and phone != ''">
            and (
            b.mobile like concat('%',#{phone},'%')
            or b.tele_phone like concat('%',#{phone},'%')
            )
        </if>
    </select>

</mapper>
