<?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.manage.take.TakerRecordReserveMapper">

    <select id="listPage" resultType="com.zfire.mall.manager.bean.manage.take.TakerRecordBean">
        SELECT
            a.*,
            b.`name` AS customerName
        FROM
            taker_record a
                LEFT JOIN king_dee_customer b ON a.customer_id = b.id
        <where>
            <if test="adminCompanyIds != null and adminCompanyIds.size > 0">
                AND a.admin_company_id in
                <foreach item="item" index="index" collection="adminCompanyIds" open="(" separator=","
                         close=")">
                    #{item}
                </foreach>
            </if>
            <if test="customerId != null and customerId != ''">
                AND a.customer_id = #{customerId}
            </if>
            <if test="customerName != null and customerName != ''">
                AND b.`name` like concat('%',#{customerName},'%')
            </if>
            <if test="takerName != null and takerName != ''">
                AND a.taker_name like concat('%',#{takerName},'%')
            </if>
            <if test="phoneKeyword != null and phoneKeyword != ''">
                AND (a.phone like concat('%',#{phoneKeyword},'%') OR a.spare_phone like concat('%',#{phoneKeyword},'%'))
            </if>
            AND a.expire_time <![CDATA[ >= ]]> #{curDate}
            AND a.del = 0
        </where>
        ORDER BY a.create_time desc, a.id DESC
    </select>
    <select id="v2ListPage" resultType="com.zfire.mall.manager.bean.manage.v2.take.TakerRecordVO">
        SELECT
            a.*,
            b.`name` AS customerName
        FROM
            taker_record a
                LEFT JOIN king_dee_customer b ON a.customer_id = b.id
        ${ex.query}
        AND a.del = 0
        <if test="ex.orderBy == null or ex.orderBy ==''">
            ORDER BY a.create_time desc, a.id DESC
        </if>
        ${ex.orderBy}
    </select>
</mapper>