<?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.crm.custom.dao.mapper.CustomLoginDemoMapper">

    <select id="countList"
            parameterType="com.crm.rely.backend.model.entity.custom.login.demo.CustomLoginDemoSearchListEntity"
            resultType="java.lang.Integer">

        SELECT
        count(*)
        FROM
        custom_login_demo custom_login
        <if test="stamp != null or stamp!=null">
            left join user_info agent on agent.id=custom_login.agent_id
        </if>
        left join custom_info on custom_info.id=custom_login.custom_id
        <where>
            <if test="stamp != null and stamp!=''">
                and agent.stamp like binary concat(#{stamp},'%')
            </if>
            <if test="customId!=null">
                and custom_login.`custom_id` =#{customId}
            </if>
            <if test="login != null">
                and custom_login.login =#{login}
            </if>
            <if test="cId != null">
                and custom_login.c_id =#{cId}
            </if>
            <if test="status != null">
                and custom_login.`status` =#{status}
            </if>
            <if test="startDate != null">
                and custom_login.add_time <![CDATA[ >= ]]> #{startDate}
            </if>
            <if test="endDate != null">
                and custom_login.add_time <![CDATA[ < ]]> #{endDate}
            </if>
            <if test="lastIp != null and lastIp !=''">
                and custom_info.last_ip like binary concat(#{lastIp},'%')
            </if>

        </where>
    </select>

    <select id="pageList"
            parameterType="com.crm.rely.backend.model.entity.custom.login.demo.CustomLoginDemoSearchListEntity"
            resultType="com.crm.rely.backend.model.pojo.view.CustomLoginDemoView">

        SELECT
        custom_login.*,account.`BALANCE`,EQUITY,floating,CREDIT,agent.ib_no as agent_ib_no,custom_info.last_ip
        FROM
        custom_login_demo custom_login
        left join account_view_mt4 account on account.login=custom_login.login
        left join user_info agent on agent.id=custom_login.agent_id
        left join custom_info on custom_info.id=custom_login.custom_id
        <where>
            <if test="stamp != null and stamp!=''">
                and agent.stamp like binary concat(#{stamp},'%')
            </if>
            <if test="customId!=null">
                and custom_login.`custom_id` =#{customId}
            </if>
            <if test="login != null">
                and custom_login.login =#{login}
            </if>
            <if test="cId != null">
                and custom_login.c_id =#{cId}
            </if>
            <if test="status != null">
                and custom_login.`status` =#{status}
            </if>
            <if test="startDate != null">
                and custom_login.add_time <![CDATA[ >= ]]> #{startDate}
            </if>
            <if test="endDate != null">
                and custom_login.add_time <![CDATA[ < ]]> #{endDate}
            </if>
            <if test="lastIp != null and lastIp !=''">
                and custom_info.last_ip like binary concat(#{lastIp},'%')
            </if>
        </where>
        order by
        <if test="sortType!=null and sortName!=null and sortName !=''">
            <if test="sortName == 'last_ip'">
                custom_info
            </if>
            <if test="sortName != 'last_ip'">
                custom_login
            </if>
            <if test="sortType==1">
                .${sortName},
            </if>
            <if test="sortType==2">
                .${sortName} desc,
            </if>
        </if>
        custom_login.add_time desc
        <if test="page!=null">
            limit #{page.offset},#{page.row}
        </if>
    </select>

</mapper>