<?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="org.springblade.modules.guosen.useragenter.mapper.UserAgenterMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="userAgenterResultMap" type="org.springblade.modules.guosen.useragenter.entity.UserAgenter">
        <id column="id" property="id"/>
        <result column="user_id" property="userId"/>
        <result column="agenter_id" property="agenterId"/>
    </resultMap>

    <resultMap id="userAgenterVOResultMap" type="org.springblade.modules.guosen.useragenter.vo.UserAgenterVO">
        <id column="id" property="id"/>
        <result column="user_id" property="userId"/>
        <result column="agenter_id" property="agenterId"/>

        <result column="nick_name" property="nickName"/>
        <result column="avatar" property="avatar"/>
        <result column="phone" property="phone"/>
        <result column="gender" property="gender"/>
        <result column="province" property="province"/>
        <result column="city" property="city"/>
    </resultMap>


    <select id="selectUserAgenterPage" resultMap="userAgenterVOResultMap">
        select id as user_id,nick_name,avatar,phone,gender,province,city from cyzh_login_user where is_deleted = 0
        <if test="userAgenter != null">
            <if test="userAgenter.province != null">
                and province = "${userAgenter.province}"
            </if>
            <if test="userAgenter.city != null">
                and city = "${userAgenter.city}"
            </if>
            <if test="userAgenter.gender != null">
                and gender = ${userAgenter.gender}
            </if>
            <if test="userAgenter.nickName != null">
                and nick_name like "%${userAgenter.nickName}%"
            </if>
            <if test="userAgenter.phone != null">
                and phone like "%${userAgenter.phone}%"
            </if>
        </if>

        and id in( select user_id from cyzh_user_agenter where 1=1
        <if test="userAgenter != null">
            <if test="userAgenter.agenterId != null">
                and agenter_id = ${userAgenter.agenterId}
            </if>
        </if>
        )
    </select>

</mapper>
