<?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.yunzhi.marketing.mapper.TaPointsExchangeMapper">

    <select id="selectListByParams" resultType="com.yunzhi.marketing.entity.TaPointsExchange">
        SELECT
            t.rec_id,
            t.person_id,
            t.person_name,
            t.phone,
            t.avatar,
            t.target_id,
            t.target_name,
            t.image,
            t.points,
            t.address,
            t.`status`,
            t.expired_date,
            t.create_date,
            t.org_id,
            t.building_id,
            t.verify_date,
            p.person_type
        FROM
            ta_points_exchange t
            LEFT JOIN ta_person p ON t.person_id = p.person_id
        where 1=1
        <if test="taPointsExchange.status != null and taPointsExchange.status != '' or taPointsExchange.status ==0">
            and  t.`status` = #{taPointsExchange.status}
        </if>
        <if test="taPointsExchange.orgId != null and taPointsExchange.orgId != ''">
            and  t.org_id = #{taPointsExchange.orgId}
        </if>
        <if test="taPointsExchange.personName != null and taPointsExchange.personName != ''">
            and  t.person_name like concat('%',#{taPointsExchange.personName},'%')
        </if>
        <if test="taPointsExchange.phone != null and taPointsExchange.phone != ''">
            and  t.phone like concat('%',#{taPointsExchange.phone},'%')
        </if>
        <if test="taPointsExchange.tel != null and taPointsExchange.tel != ''">
            and  t.phone = #{taPointsExchange.tel}
        </if>
        <if test="taPointsExchange.personType != null and taPointsExchange.personType != ''">
            and  p.person_type = #{taPointsExchange.personType}
        </if>
        <if test="taPointsExchange.targetName != null and taPointsExchange.targetName != ''">
            and  t.target_name like concat('%',#{taPointsExchange.targetName},'%')
        </if>
        <if test="taPointsExchange.startCreateDate != null and taPointsExchange.startCreateDate != ''">
            and  date_format(t.create_date,'%Y-%m-%d') >= date_format(#{taPointsExchange.startCreateDate},'%Y-%m-%d')
        </if>
        <if test="taPointsExchange.endCreateDate != null and taPointsExchange.endCreateDate != ''">
            and  date_format(t.create_date,'%Y-%m-%d') &lt;= date_format(#{taPointsExchange.endCreateDate},'%Y-%m-%d')
        </if>
        <if test="taPointsExchange.startVerifyDate != null and taPointsExchange.startVerifyDate != ''">
            and  date_format(t.verify_date,'%Y-%m-%d') >= date_format(#{taPointsExchange.startVerifyDate},'%Y-%m-%d')
        </if>
        <if test="taPointsExchange.endVerifyDate != null and taPointsExchange.endVerifyDate != ''">
            and  date_format(t.verify_date,'%Y-%m-%d') &lt;= date_format(#{taPointsExchange.endVerifyDate},'%Y-%m-%d')
        </if>
        <if test="personBuildingList != null and personBuildingList.size > 0">
            AND t.building_id in
            <foreach collection="personBuildingList" item="personBuilding" open="(" close=")" separator=",">
                #{personBuilding.buildingId}
            </foreach>
        </if>
        order by t.create_date desc
    </select>
</mapper>
