<?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.xxl.job.executor.report.mapper.BytedanceVideoReportMapper">

    <select id="queryVideoReportBy" resultType="com.alibaba.fastjson.JSONObject">
        SELECT * from (SELECT
        t1.signature,
        t1.video_url as url,
        IFNULL((SELECT u.realname FROM ctop_material_ascription t3 LEFT JOIN sys_user u on t3.clip_id=u.id where t3.material_id=t1.signature limit 1),'') AS clip,
        IFNULL((SELECT u.realname FROM ctop_material_ascription t3 LEFT JOIN sys_user u on t3.shot_id=u.id where t3.material_id=t1.signature limit 1),'') AS shot,
        IFNULL((SELECT u.realname FROM ctop_material_ascription t3 LEFT JOIN sys_user u on t3.plan_id=u.id where t3.material_id=t1.signature limit 1),'') AS plan,
        (select t2.cover_url from ctop_material_info t2 where t2.code=t1.signature limit 1) AS converUrl,
        (select t2.material_name from ctop_material_info t2 where t2.code=t1.signature limit 1) AS materialName,
        (SELECT project_name FROM ctop_project t4 WHERE t4.id = t3.project_id) AS projectName,
        (select t2.create_time from ctop_material_info t2 where t2.code=t1.signature limit 1) as createTime,
        ${filed}
        FROM
        ctop_bytedance_video_report_daily t1
        LEFT JOIN ctop_user_allocation t3 ON t3.account_id=t1.account_id
        WHERE
        t1.stat_datetime >= #{startDate}
        AND t1.stat_datetime &lt;= #{endDate}
        <if test="accountIds != null">
            AND t1.account_id in
            <foreach item="item" index="index" collection="accountIds"
                     open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        AND t1.video_url is not null
        GROUP BY t1.signature
        ) t
        WHERE (t.clip LIKE '%${clip}%')
        AND (t.shot LIKE '%${shot}%')
        AND (t.plan LIKE '%${plan}%')
        ORDER BY ${target} ${order}
    </select>

    <select id="queryVideoDetailBy" resultType="com.alibaba.fastjson.JSONObject">
        SELECT
        t1.stat_datetime as statDate,
        t1.signature,
        t1.video_url as url,
        (select t2.cover_url from ctop_material_info t2 where t2.code=t1.signature limit 1) AS converUrl,
        (select t2.material_name from ctop_material_info t2 where t2.code=t1.signature limit 1) AS materialName,
        (
        SELECT
        project_name
        FROM
        ctop_project t4
        WHERE
        t4.id = t3.project_id
        ) AS projectName,
        (
        SELECT
        advertiser_name
        FROM
        ctop_project t4
        WHERE
        t4.id = t3.project_id limit 1
        ) AS advertiserName,
        (select t2.create_time from ctop_material_info t2 where t2.code=t1.signature limit 1) as createTime,
        ${filed}
        FROM
        ctop_bytedance_video_report_daily t1
        LEFT JOIN ctop_user_allocation t3 ON t3.account_id=t1.account_id
        WHERE t1.signature=#{signature}
        AND t1.stat_datetime >= #{startDate}
        AND t1.stat_datetime &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_datetime
    </select>
</mapper>
