<?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.zfire.mall.manager.commonmapper.engin.deposit.CusEnginDepositeMapper">

    <select id="listPage" resultType="com.zfire.mall.manager.bean.engin.deposit.CustomerEnginDepositBean">
        SELECT *
            FROM (
                 SELECT * FROM
                     customer_engin_deposit a
        <where>

            <if test="companyIds != null and companyIds.size > 0">
                AND a.admin_company_id in
                <foreach item="item" index="index" collection="companyIds" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>

            <if test="customerId != null and customerId != ''">
                AND a.customer_id = #{customerId}
            </if>

            <if test="keyword != null and keyword != ''">
                AND a.customer_name LIKE CONCAT('%', #{keyword}, '%')
            </if>

            <if test="currentStatus != null  and currentStatus == 1">
                    AND a.start_time &gt; now()
            </if>

            <if test="currentStatus != null  and currentStatus == 2">
                    AND a.start_time &lt;= now()  AND  a.end_time &gt; now()
            </if>

            <if test="currentStatus != null and currentStatus == 3">
                    AND a.end_time &lt; now()
            </if>

        </where>

                 ORDER BY
                    a.create_time DESC
                  LIMIT
                    100000
            ) as t
        GROUP BY
            t.customer_number
        ORDER BY
            t.create_time DESC;
    </select>

    <insert id="insertWithTime" parameterType="com.zfire.mall.manager.bean.engin.deposit.CustomerEnginDeposit">
        INSERT INTO
        customer_engin_deposit
            (id, admin_user_id, customer_number,
             customer_id, customer_name, rate,
             amount,start_time, end_time,
             remark, admin_company_id, create_time,
             create_by, update_time, update_by)
        VALUES
            (#{id}, #{adminUserId}, #{customerNumber},
             #{customerId}, #{customerName}, #{rate},
             #{amount}, #{startTime}, #{endTime},
             #{remark},#{adminCompanyId}, #{createTime}, #{createBy},
             #{updateTime}, #{updateBy});

    </insert>

</mapper>