<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.pluss.platform.mapper.BusinessInfoMapper">

    <select id="selectPage" resultType="cn.pluss.platform.vo.BusinessInfoVo">
        SELECT ua.userId, ui.loginName, ui.phone, ui.status, ua.userName, ui.createTime, ui.updateTime,
        pup.userName AS agentName, pup.userId AS agentId
        FROM tb_pluss_user_app ua
        LEFT JOIN tb_pluss_user_info ui
        ON ua.userId = ui.id
        LEFT JOIN tb_pluss_user_app pup
        ON ua.parentId = pup.userId
        WHERE ua.userType = 'agent_staff'
        <include refid="commonWhere" />
    </select>

    <sql id="commonWhere">
        <if test="businessInfoVo.userId != null and businessInfoVo.userId != ''">
            AND ua.userId = #{businessInfoVo.userId}
        </if>
        <if test="businessInfoVo.loginName != null and businessInfoVo.loginName != ''">
            AND ui.loginName LIKE CONCAT("%", #{businessInfoVo.loginName}, "%")
        </if>
        <if test="businessInfoVo.phone != null and businessInfoVo.phone != ''">
            AND ui.phone LIKE CONCAT("%", #{businessInfoVo.phone}, "%")
        </if>
        <if test="businessInfoVo.userName != null and businessInfoVo.userName != ''">
            AND ua.userName LIKE CONCAT("%", #{businessInfoVo.userName}, "%")
        </if>
        <if test="businessInfoVo.agentName != null and businessInfoVo.agentName != ''">
            AND pup.userName LIKE concat('%',#{businessInfoVo.agentName},'%')
        </if>
        <if test="businessInfoVo.agentId != null">
            AND pup.userId = #{businessInfoVo.agentId}
        </if>
    </sql>

</mapper>