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

    <select id="getFollowCustomer" resultType="java.lang.Integer">
        SELECT
            COUNT(1)
        FROM
        xlk_channel_customer t
        INNER JOIN xlk_customer_visit v on t.customer_id = v.customer_id
        INNER JOIN ta_customer_follow_up_record f on t.customer_id = f.customer_id
        WHERE t.channel_id  = #{params.channelId}
        <if test="params.startDate != null or params.endDate != null">
            AND t.create_date BETWEEN #{params.startDate} and #{params.endDate}
        </if>
        <if test="params.startDate == null or params.endDate == null">
            AND t.create_date BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
        </if>
    </select>
    <select id="getFollowCustomerDetail" resultType="com.yunzhi.marketing.xlk.vo.CustomerDetailVO">
        SELECT
            <if test="params.type == 'day'">
                date_format( t.create_date, '%Y-%m-%d' ) as coordinate,
            </if>
            <if test="params.type == 'month'">
                date_format( t.create_date, '%Y-%m' ) as coordinate,
            </if>
            COUNT(1) as customerNum
        FROM
        xlk_channel_customer t
        INNER JOIN xlk_customer_visit v on t.customer_id = v.customer_id
        INNER JOIN ta_customer_follow_up_record f on t.customer_id = f.customer_id
        WHERE t.channel_id  = #{params.channelId}
        <if test="params.startDate != null or params.endDate != null">
            AND t.create_date BETWEEN #{params.startDate} and #{params.endDate}
        </if>
        <if test="params.startDate == null or params.endDate == null">
            AND t.create_date BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
        </if>
        <if test="params.type == 'day'">
            group by date_format( t.create_date, '%Y-%m-%d' )
        </if>
        <if test="params.type == 'month'">
            group by date_format( t.create_date, '%Y-%m' )
        </if>
    </select>
</mapper>
