<?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.pay.dao.mapper.CustomFundHistoryMapper">

    <select id="countList" resultType="integer"
            parameterType="com.crm.rely.backend.model.entity.custom.fund.history.CustomFundHistorySearchListEntity">

        select count(*)
        from custom_fund_history
        <if test="stamp != null">
            left join user_info agent on finance_deposit.agent_id = agent.id
        </if>
        <where>
                <if test="stamp != null">
                    and agent.stamp like binary concat(#{stamp},'%')
                </if>
                <if test="cId != null">
                    and custom_fund_history.c_id =#{cId}
                </if>
                <if test="customId != null ">
                    and custom_fund_history.custom_id=#{customId}
                </if>
                <if test="sourceType != null ">
                    and custom_fund_history.source_type=#{sourceType}
                </if>
                <if test="startDate != null">
                    and custom_fund_history.add_time <![CDATA[ >= ]]> #{startDate}
                </if>
                <if test="endDate != null">
                    and custom_fund_history.add_time <![CDATA[ < ]]> #{endDate}
                </if>
        </where>

    </select>

    <select id="searchList" resultType="com.crm.rely.backend.model.pojo.view.CustomFundHistoryView"
            parameterType="com.crm.rely.backend.model.entity.custom.fund.history.CustomFundHistorySearchListEntity">

        select custom_fund_history.* ,
        agent.ib_no as agent_ib_no,
        sales.ib_no sales_ib_no
        from custom_fund_history
        left join user_info agent on agent.id=custom_fund_history.agent_id
        left join user_info sales on agent.sales_id=sales.id
        <where>
            <if test="stamp != null">
                and agent.stamp like binary concat(#{stamp},'%')
            </if>
            <if test="cId != null">
                and custom_fund_history.c_id =#{cId}
            </if>
            <if test="customId != null ">
                and custom_fund_history.custom_id=#{customId}
            </if>
            <if test="sourceType != null ">
                and custom_fund_history.source_type=#{sourceType}
            </if>
            <if test="startDate != null">
                and custom_fund_history.add_time <![CDATA[ >= ]]> #{startDate}
            </if>
            <if test="endDate != null">
                and custom_fund_history.add_time <![CDATA[ < ]]> #{endDate}
            </if>
        </where>
        order by custom_fund_history.add_time desc
        <if test="page != null">
            limit #{page.offset},#{page.row}
        </if>

    </select>

</mapper>