<?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="org.jeecg.modules.bytedance.report.mapper.BytedanceReportMaterialDailyMapper">

    <!-- 查询账户花费-->
    <select id="selectMaterialDailyReportByAccountId" resultType="java.util.HashMap">
        SELECT
            video.video_url as videoUrl,
            concat(report.material_id,'') as materialId,
            sum(report.cost) as cost,
            sum(report.show_material) as showMaterial,
            sum(report.click) as click,
            sum(report.convert_material) as convertMaterial,
            creative.count,
            video.material_upload_time as materialUploadTime,
            video.poster_url as posterUrl,
            report.update_time as updateTime
        FROM
            ctop_bytedance_report_material_daily report
        LEFT JOIN ctop_bytedance_video_info video ON video.material_id = report.material_id AND video.account_id = report.account_id
        LEFT JOIN (SELECT video_id,account_id,count(*) AS count FROM ctop_bytedance_creative t WHERE t.account_id = #{accountId} GROUP BY video_id,account_id) creative ON creative.video_id = video.vid
        WHERE
            video.account_id = #{accountId}
        <if test="startTime!=null and startTime!=''">and STR_TO_DATE(report.stat_datetime,'%Y-%m-%d') &gt;= STR_TO_DATE(#{startTime},'%Y-%m-%d')</if>
        <if test="endTime!=null and endTime!=''">and STR_TO_DATE(report.stat_datetime,'%Y-%m-%d') &lt;= STR_TO_DATE(#{endTime},'%Y-%m-%d')</if>
        GROUP BY
            report.material_id
        order by report.cost desc

    </select>
</mapper>
