<?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.FinanceDepositMapper">

    <select id="countList" resultType="integer"
            parameterType="com.crm.rely.backend.model.entity.finance.deposit.FinanceDepositSearchListEntity">

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

    </select>

    <select id="searchList" resultType="com.crm.rely.backend.model.pojo.view.FinanceDepositView"
            parameterType="com.crm.rely.backend.model.entity.finance.deposit.FinanceDepositSearchListEntity">

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

    </select>
    <select id="getOne" resultType="com.crm.rely.backend.model.pojo.view.FinanceDepositView">

        select finance_deposit.*,
               agent.ib_no as p_ib_no,
               sales.ib_no    sales_ib_no
        from finance_deposit
                 left join user_info agent on agent.id = finance_deposit.agent_id
                 left join user_info sales on agent.sales_id = sales.id
        where finance_deposit.id = #{id}
    </select>


</mapper>