<?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="cn.com.ctop.kuaishou.modules.report.mapper.EtlKuaiShouNewlyMapper">

    <insert id="replaceBatch">
        replace into ctop_etl_kuaishou_newly(
        project_id,
        project_name,
        account_id,
        oauth_name,
        user_id,
        user_name,
        new_count,
        new_type,
        stat_date
        )
        values
        <foreach collection="addList" item="addList" separator=",">
            (
            #{addList.projectId},
            #{addList.projectName},
            #{addList.accountId},
            #{addList.oauthName},
            #{addList.userId},
            #{addList.userName},
            #{addList.newCount},
            #{addList.newType},
            #{addList.statDate}
            )
        </foreach>
    </insert>

    <select id="getNewlyCounts" resultType="com.alibaba.fastjson.JSONObject">
        SELECT stat_date as 'statDate', account_id as 'accountId', new_count as 'newCount', new_type as 'newType'
        FROM ctop_etl_kuaishou_newly
        WHERE stat_date &gt;= DATE_FORMAT(date_sub(now(), interval 7 day), '%Y-%m-%d')
          AND stat_date &lt;= DATE_FORMAT(date_sub(now(), interval 1 day), '%Y-%m-%d')
          AND account_id = #{accountId}
        group by stat_date, new_type
    </select>


</mapper>