<?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.report.mapper.KuaishouMaterialVideoReportDailyDwMapper">

    <select id="getTotalByMap" resultType="java.lang.Long">
        SELECT
        count(1)
        FROM
        (select
        t1.signature
        from kuaishou_material_video_report_daily_dw t1
        where 1 = 1
        <if test="accountIds !=null and accountIds != ''">
            and t1.account_id in
            <foreach item="item" index="index" collection="accountIds"
                     open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="startDate !=null and startDate != ''">
            AND t1.stat_date &gt;= #{startDate}
        </if>
        <if test="endDate !=null and endDate != ''">
            AND t1.stat_date &lt;= #{endDate}
        </if>
        <if test="leaderId !=null and leaderId != ''">
            AND t1.leader_id = #{leaderId}
        </if>
        <if test="channelType != null">
            AND t1.channel_type = #{channelType}
        </if>
        <if test="clipId !=null and clipId != ''">
            AND t1.clip_id = #{clipId}
        </if>
        <if test="planId !=null and planId != ''">
            AND t1.plan_id = #{planId}
        </if>
        <if test="shotId !=null and shotId != ''">
            AND t1.shot_id = #{shotId}
        </if>
        <if test="companyId !=null and companyId != ''">
            AND t1.company_id = #{companyId}
        </if>
        GROUP BY t1.signature
        ) t2
    </select>
    <select id="getKuaiShouVideoReportByMap" resultType="com.alibaba.fastjson.JSONObject" parameterType="map">
        SELECT
        t1.*
        FROM
        (select
        IFNULL( clip_name, '-' ) AS clip,
        IFNULL( plan_name, '-' ) AS plan,
        IFNULL( shot_name, '-' ) AS shot,
        IFNULL( leader_name, '-' ) AS designLeader,
        IFNULL( video_name, '-' ) AS materialName,
        IFNULL( cover_url, '-' ) AS coverUrl,
        IFNULL( photo_url, '-' ) AS url,
        IFNULL( channel_name, '-' ) AS channel,
        IFNULL( stat_date, '-' ) AS createTime,
                ${filed}
        from kuaishou_material_video_report_daily_dw
        where 1 = 1
        <if test="accountIds !=null and accountIds != ''">
            and account_id in
            <foreach item="item" index="index" collection="accountIds"
                     open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="startDate !=null and startDate != ''">
            AND stat_date &gt;= #{startDate}
        </if>
        <if test="endDate !=null and endDate != ''">
            AND stat_date &lt;= #{endDate}
        </if>
        <if test="leaderId !=null and leaderId != ''">
            AND leader_id = #{leaderId}
        </if>
        <if test="channelType != null">
            AND channel_type = #{channelType}
        </if>
        <if test="clipId !=null and clipId != ''">
            AND clip_id = #{clipId}
        </if>
        <if test="planId !=null and planId != ''">
            AND plan_id = #{planId}
        </if>
        <if test="shotId !=null and shotId != ''">
            AND shot_id = #{shotId}
        </if>
        <if test="companyId !=null and companyId != ''">
            AND clip_company_id = #{companyId}
        </if>
        GROUP BY signature
        ORDER BY ${target} ${order}
        ) t1



    </select>
    <select id="queryVideoDetailBy" resultType="com.alibaba.fastjson.JSONObject">
        SELECT
        t1.stat_date as statDate,
        t1.signature,
        t1.photo_url as url,
        t1.cover_url as converUrl,
        (select t2.material_name from ctop_material_info t2 where t2.code=t1.signature limit 1) AS materialName,
        t1.project_name AS projectName,
        t1.advertiser_name AS advertiserName,
        (select t2.create_time from ctop_material_info t2 where t2.code=t1.signature limit 1) as createTime,
        ${filed}
        FROM
        kuaishou_material_video_report_daily_dw t1
        WHERE t1.signature=#{signature}
        AND t1.stat_date >= #{startDate}
        AND t1.stat_date &lt;= #{endDate}
        <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_date
        order by t1.stat_date desc
    </select>
</mapper>