<?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.toutiao.modules.report.mapper.BytedanceVideoReportMapper">

    <select id="queryVideoReportBy" resultType="com.alibaba.fastjson.JSONObject">
        SELECT
        t1.signature,
        t1.video_url AS url,
        t1.cover_url AS converUrl,
        IFNULL(t1.clip_name,'-') AS clip,
        IFNULL(t1.shot_name,'-') AS shot,
        IFNULL(t1.plan_name,'-') AS plan,
        IFNULL(t1.leader_name,'-') AS leader,
        t1.video_name AS materialName,
        t1.project_name AS projectName,
        DATE_FORMAT(stat_datetime,'%Y-%m-%d') AS createTime,
        sum( t1.SHOW ) AS showMaterial,
        IFNULL(t1.leader_name,'-') AS 'teamLeader',
        CASE WHEN t1.convert != 0 THEN concat( CAST( round(sum(t1.in_app_pay)/sum(t1.convert)* 100, 2 ) AS CHAR ), '%' ) ELSE '0.00%' end AS 'firstPurchase',
        ${filed}
        FROM
        application.bytedance_material_video_report_daily_dw t1
        WHERE
        t1.stat_datetime >= DATE_FORMAT(#{startDate}, '%Y%m%d' )
        AND t1.stat_datetime &lt;= DATE_FORMAT(#{endDate}, '%Y%m%d' )
        <if test="accountIds != null">
            AND t1.account_id in
            <foreach item="item" index="index" collection="accountIds"
                     open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="clip!= null and clip!='' ">
            AND (t1.clip_name LIKE '%${clip}%')
        </if>
        <if test="shot!= null and shot!='' ">
            AND (t1.shot_name LIKE '%${shot}%')
        </if>
        <if test="plan!= null and plan!='' ">
            AND (t1.plan_name LIKE '%${plan}%')
        </if>
        <if test="leader!= null and leader!='' ">
            AND t1.leader_name LIKE '%${leader}%'
        </if>
        GROUP BY t1.signature
        ORDER BY ${target} ${order}
    </select>

    <select id="queryVideoDetailBy" resultType="com.alibaba.fastjson.JSONObject">
        SELECT
        DATE_FORMAT(stat_datetime,'%Y-%m-%d') as statDate,
        t1.signature,
        IFNULL(t1.video_url, '') AS url,
        t1.cover_url AS converUrl,
        t1.video_name AS materialName,
        t1.project_name AS projectName,
        t1.account_name as advertiserName,
        DATE_FORMAT(stat_datetime,'%Y-%m-%d') AS createTime,
        ${filed}
        FROM
        application.bytedance_material_video_report_daily_dw t1
        WHERE t1.signature=#{signature}
        AND t1.stat_datetime >= DATE_FORMAT(#{startDate}, '%Y%m%d' )
        AND t1.stat_datetime &lt;= DATE_FORMAT(#{endDate}, '%Y%m%d' )
        <if test="accountIds != null">
            AND t1.account_id in
            <foreach item="item" index="index" collection="accountIds"
                     open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        GROUP BY t1.signature,t1.stat_datetime
        order by t1.stat_datetime desc
    </select>
</mapper>