<?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.manager.dao.mapper.AgentBalanceRecordDao">

    <select id="getList"
            parameterType="com.crm.rely.backend.core.entity.ib.balance.AgentBalanceRecordListEntity"
            resultType="com.crm.rely.backend.core.pojo.view.AgentBalanceRecordView">
        select abr.*,agent.ib_no,agent.c_id
        from agent_balance_record abr
        left join user_info agent on abr.agent_id=agent.id
        <where>
            <if test="ibNo != null and ibNo != ''">
                and agent.ib_no like concat(#{ibNo},'%')
            </if>
            <if test="startDate != null">
                and abr.add_time <![CDATA[>=]]]>#{startDate}
            </if>
            <if test="endDate != null">
                and abr.add_time <![CDATA[<=]]]>#{endDate}
            </if>
        </where>
        order by abr.id desc
        <if test="page != null">
            limit #{page.offset},#{page.row}
        </if>
    </select>

    <select id="countList"
            parameterType="com.crm.rely.backend.core.entity.ib.balance.AgentBalanceRecordListEntity"
            resultType="Integer">
        select count(*)
        from agent_balance_record abr
        left join user_info agent on abr.agent_id=agent.id
        <where>
            <if test="ibNo != null and ibNo != ''">
                and agent.ib_no like concat(#{ibNo},'%')
            </if>
            <if test="startDate != null">
                and abr.add_time <![CDATA[>=]]]>#{startDate}
            </if>
            <if test="endDate != null">
                and abr.add_time <![CDATA[<=]]]>#{endDate}
            </if>
        </where>
    </select>

</mapper>