<?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.xlk.mapper.ChannelCustomerMapper">

    <select id="getProfileList" resultType="com.yunzhi.marketing.xlk.entity.ChannelCustomer">
        SELECT
            t.*,
            s.building_name,
            m.nickname AS recommend_person_name,
            m.phone AS recommend_person_phone
        FROM
            xlk_channel_customer t
                LEFT JOIN ta_building s ON t.building_id = s.building_id
                INNER JOIN ta_person m ON t.recommend_person = m.person_id
        WHERE
            t.org_id = #{orgId}
          <if test="buildingId != null and buildingId != ''">
              AND t.building_id = #{buildingId}
          </if>
          <if test="name != null and name != ''">
              AND t.`name` LIKE CONCAT( '%', #{name}, '%' )
          </if>
          <if test="phone != null and phone != ''">
            AND t.phone LIKE CONCAT( '%', #{phone}, '%' )
          </if>
          <if test="recommendPersonName != null and recommendPersonName != ''">
            AND m.nickname LIKE CONCAT( '%', #{recommendPersonName}, '%' )
          </if>
          <if test="recommendPhone != null and recommendPhone != ''">
            AND m.phone LIKE CONCAT( '%', #{recommendPhone}, '%' )
          </if>
          <if test="status != null and status != ''">
            AND t.`status` = #{status}
          </if>
          <if test="status == null or status == ''">
            AND t.`status` &gt; -1
          </if>
            ORDER BY
                t.create_date DESC
    </select>
</mapper>
