<?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.advertise.mapper.ByteDanceVideoInfoMapper">
    <insert id="replaceBatch">
        replace into ctop_bytedance_video_info(
        id,
        vid,
        advertiser_id,
        account_id,
        material_id,
        url,
        material_upload_time,
        filename,
        format,
        poster_url,
        bit_rate,
        source,
        file_id,
        width,
        height,
        duration,
        size,
        video_url,
        status,
        create_time,
        update_time,
        signature)
        values
        <foreach collection="videoList" item="video" separator=",">
            (
            #{video.id},
            #{video.vid},
            #{video.advertiserId},
            #{video.accountId},
            #{video.materialId},
            #{video.url},
            #{video.materialUploadTime},
            #{video.filename},
            #{video.format},
            #{video.posterUrl},
            #{video.bitRate},
            #{video.source},
            #{video.fileId},
            #{video.width},
            #{video.height},
            #{video.duration},
            #{video.size},
            #{video.videoUrl},
            #{video.status},
            #{video.createTime},
            #{video.updateTime},
            #{video.signature}
            )
        </foreach>
    </insert>
    <update id="updateVideoVerticalType">
        update
            ctop_bytedance_video_info
        set type = 2
        where height &gt; width and type is null
        and (height between 1280 and 2560)  and (width between 720 and 1440)
    </update>
    <update id="updateVideoHorizonType">
        update ctop_bytedance_video_info
            set type = 1
        where height &lt; width and type is null
        and (width between 1280 and 2560)  and (height between 720 and 1440)
    </update>
    <select id="getNewVideoByParams"
            resultType="org.jeecg.modules.bytedance.advertise.entity.ByteDanceVideoInfo">
        select video.*,
        (select count(1)
        from ctop_bytedance_creative c
        where c.video_id = video.vid and c.account_id = '${accountId}') as creativeCnt
        from ctop_bytedance_video_info video
        where account_id = #{accountId}
        and material_upload_time &gt;= #{startTime}
        and material_upload_time &lt;= #{endTime}
        having creativeCnt &lt;= #{creativeCnt}
        order by material_upload_time desc
        limit #{videoCnt}
    </select>
    <select id="topMatByParams" resultType="org.jeecg.modules.bytedance.advertise.entity.ByteDanceVideoInfo">
        select video.*
        from (select report.material_id, sum(cost) as totalCost, report.account_id
        from ctop_bytedance_report_material_daily report
        left join ctop_user_allocation cua on report.account_id = cua.account_id
        where cua.project_id = #{projectId}
        and report.stat_datetime &gt;= #{startTime}
        and report.stat_datetime &lt;= #{endTime}
        group by report.material_id
        order by sum(report.cost) desc) a
        left join ctop_bytedance_video_info video
        on a.material_id = video.material_id and video.account_id = a.account_id
        left join ctop_material_info cmi on cmi.code = video.signature
        where video.account_id = #{accountId}
        and cmi.id is not null
        limit #{videoCnt}
    </select>
</mapper>
