<?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.kiisoo.ic.generalize.mapper.PoiCustomerContactDataStatMapper">
    <!--拉黑-->
    <select id="selectDeleteCustomer" resultType="com.kiisoo.ic.generalize.entity.PoiCustomerContactDataStat">
        select id as id, store_id as storeId, negative_feedback_cnt as negativeFeedbackCnt,
        new_contact_cnt as newContactCnt, stat_time as statTime, create_time as createTime
        from poi_customer_contact_data_stat t1 where t1.store_id in
        <foreach collection="shopIds" separator="," item="item" index="index" close=")" open="(">
            #{item}
        </foreach>
    </select>
    <select id="selectSumAddCustomer" resultType="java.math.BigDecimal">
        select
        sum(new_contact_cnt) as newContactCnt
        from poi_customer_contact_data_stat t1 where stat_time between
        DATE_FORMAT(#{startDate},'%Y-%m-%d')
        and DATE_FORMAT(#{endDate},'%Y-%m-%d')
        and t1.store_id in
        <foreach collection="shopIds" separator="," item="item" index="index" close=")" open="(">
            #{item}
        </foreach>
    </select>
    <select id="selectSumApplyCustomer" resultType="com.kiisoo.ic.analysis.bean.TableAnalysisDTO">
        select
        SUM(new_apply_cnt) as applyCustomer,
        store_id as storeId
        from poi_customer_contact_data_stat t1 where stat_time
        between DATE_FORMAT(#{startDate},'%Y-%m-%d')
        and DATE_FORMAT(#{endDate},'%Y-%m-%d')
        and t1.store_id in
        <foreach collection="shopIds" separator="," item="item" index="index" close=")" open="(">
            #{item}
        </foreach>
        group by store_id having sum(new_contact_cnt) &lt;= #{count}
    </select>

    <select id="sumNegativeFeedbackCntByStoreIds" resultType="java.lang.Integer">
        select
        SUM(negative_feedback_cnt)
        from poi_customer_contact_data_stat t1 where
        t1.store_id in
        <foreach collection="storeIds" separator="," item="item" index="index" close=")" open="(">
            #{item}
        </foreach>
    </select>
    <select id="selectSumDataByShopIds" resultType="com.kiisoo.ic.generalize.entity.PoiCustomerContactDataStat">
        select
        store_id as storeId,
        IFNULL(SUM(negative_feedback_cnt),0) as negativeFeedbackCnt,
        IFNULL(SUM(new_apply_cnt),0) as newApplyCnt,
        IFNULL(SUM(chat_cnt),0) as chatCnt,
        IFNULL(SUM(message_cnt),0) as messageCnt,
        IFNULL(AVG(avg_reply_time),0) as avgReplyTime,
        IFNULL(AVG(reply_percentage),0) as replyPercentage,
        IFNULL(SUM(new_contact_cnt),0) as newContactCnt
        from poi_customer_contact_data_stat where
        store_id in
        <foreach collection="storeIds" separator="," item="item" index="index" close=")" open="(">
            #{item}
        </foreach>
        and stat_time
        between DATE_FORMAT(#{startDate},'%Y-%m-%d')
        and DATE_FORMAT(#{endDate},'%Y-%m-%d')
        group by store_id
    </select>
</mapper>
