<?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.BytedanceReportMaterialDailyMapper">

    <insert id="replaceIntoBatch">
        REPLACE INTO ctop_bytedance_report_material_daily
        (
        account_id,
        stat_datetime,
        click,
        cost,
        active,
        download_finish,
        download_start,
        install_finish,
        register,
        pay_count,
        in_app_uv,
        in_app_detail_uv,
        in_app_cart,
        in_app_order,
        in_app_pay,
        phone,
        form,
        map_search,
        button,
        view_material,
        qq,
        lottery,
        vote,
        redirect,
        shopping,
        consult,
        wechat,
        phone_confirm,
        phone_connect,
        consult_effective,
        total_play,
        valid_play,
        wifi_play,
        play_duration_sum,
        play25_feed_break,
        play50_feed_break,
        play75_feed_break,
        play100_feed_break,
        advanced_creative_phone_click,
        advanced_creative_counsel_click,
        advanced_creative_form_click,
        share_material,
        comment_material,
        follow,
        home_visited,
        ies_challenge_click,
        ies_music_click,
        next_day_open,
        next_day_open_rate,
        next_day_open_cost,
        image_mode,
        material_id,
        inventory,
        active_pay_amount,
        valid_play_cost,
        advanced_creative_coupon_addition,
        convert_material,
        active_pay_cost,
        download,
        cpa,
        cpc,
        location_click,
        play_over_rate,
        ctr,
        cpm,
        wifi_play_rate,
        like_material,
        active_pay_rate,
        active_cost,
        game_addiction_cost,
        game_addiction,
        active_rate,
        play_duration_10s,
        phone_effective,
        game_addiction_rate,
        active_register_rate,
        average_video_play,
        download_finish_cost,
        play_duration_3s,
        active_register_cost,
        show_material,
        convert_rate,
        download_finish_rate,
        install_finish_rate,
        coupon,
        coupon_single_page,
        play_over,
        download_start_cost,
        message,
        play_duration,
        valid_play_rate,
        average_play_time_per_play,
        convert_cost,
        convert_show_rate,
        install_finish_cost,
        download_start_rate
        )
        VALUES
        <foreach collection="infos" item="info" separator=",">
      (
        #{info.accountId},
        #{info.statDatetime},
        #{info.click},
        #{info.cost},
        #{info.active},
        #{info.downloadFinish},
        #{info.downloadStart},
        #{info.installFinish},
        #{info.register},
        #{info.payCount},
        #{info.inAppUv},
        #{info.inAppDetailUv},
        #{info.inAppCart},
        #{info.inAppOrder},
        #{info.inAppPay},
        #{info.phone},
        #{info.form},
        #{info.mapSearch},
        #{info.button},
        #{info.viewMaterial},
        #{info.qq},
        #{info.lottery},
        #{info.vote},
        #{info.redirect},
        #{info.shopping},
        #{info.consult},
        #{info.wechat},
        #{info.phoneConfirm},
        #{info.phoneConnect},
        #{info.consultEffective},
        #{info.totalPlay},
        #{info.validPlay},
        #{info.wifiPlay},
        #{info.playDurationSum},
        #{info.play25FeedBreak},
        #{info.play50FeedBreak},
        #{info.play75FeedBreak},
        #{info.play100FeedBreak},
        #{info.advancedCreativePhoneClick},
        #{info.advancedCreativeCounselClick},
        #{info.advancedCreativeFormClick},
        #{info.shareMaterial},
        #{info.commentMaterial},
        #{info.follow},
        #{info.homeVisited},
        #{info.iesChallengeClick},
        #{info.iesMusicClick},
        #{info.nextDayOpen},
        #{info.nextDayOpenRate},
        #{info.nextDayOpenCost},
        #{info.imageMode},
        #{info.materialId},
        #{info.inventory},
        #{info.activePayAmount},
        #{info.validPlayCost},
        #{info.advancedCreativeCouponAddition},
        #{info.convertMaterial},
        #{info.activePayCost},
        #{info.download},
        #{info.cpa},
        #{info.cpc},
        #{info.locationClick},
        #{info.playOverRate},
        #{info.ctr},
        #{info.cpm},
        #{info.wifiPlayRate},
        #{info.likeMaterial},
        #{info.activePayRate},
        #{info.activeCost},
        #{info.gameAddictionCost},
        #{info.gameAddiction},
        #{info.activeRate},
        #{info.playDuration_10s},
        #{info.phoneEffective},
        #{info.gameAddictionRate},
        #{info.activeRegisterRate},
        #{info.averageVideoPlay},
        #{info.downloadFinishCost},
        #{info.playDuration_3s},
        #{info.activeRegisterCost},
        #{info.showMaterial},
        #{info.convertRate},
        #{info.downloadFinishRate},
        #{info.installFinishRate},
        #{info.coupon},
        #{info.couponSinglePage},
        #{info.playOver},
        #{info.downloadStartCost},
        #{info.message},
        #{info.playDuration},
        #{info.validPlayRate},
        #{info.averagePlayTimePerPlay},
        #{info.convertCost},
        #{info.convertShowRate},
        #{info.installFinishCost},
        #{info.downloadStartRate}
         )
        </foreach>
    </insert>

    <insert id="replaceMaterialRetry">
        REPLACE INTO ctop_bytedance_report_material_retry
        (
            account_id,
            start_date,
            end_date,
            status,
            status_code,
            type
        )
        VALUES
        (
            #{retry.accountId},
            #{retry.startDate},
            #{retry.endDate},
            #{retry.status},
            #{retry.statusCode},
            #{retry.type}
        )

    </insert>

    <select id="getRetryList" resultType="cn.com.ctop.toutiao.modules.report.entity.BytedanceReportMaterialRetry">
            select
            account_id,
            start_date,
            end_date,
            status,
            type
        from
        ctop_bytedance_report_material_retry
        where status = 0
    </select>
    <select id="getVideoVoByDate" resultType="cn.com.ctop.toutiao.modules.material.vo.BytedanceVideoVo">
        select
            distinct video.signature as 'code',video.video_url as 'url',report.stat_datetime as 'initial_cost_date'
        from
            ctop_bytedance_report_material_daily report
        left join ctop_bytedance_video_info video on video.material_id = report.material_id
        where
            report.stat_datetime = #{date}
        and
            video.signature is not null
        and
            report.image_mode in ('CREATIVE_IMAGE_MODE_VIDEO','CREATIVE_IMAGE_MODE_VIDEO_VERTICAL')
        and
            video.signature not in (select distinct code from ctop_bytedance_effect_video_info)
    </select>

    <update id="updateRetry">
        update
        ctop_bytedance_report_material_retry
        set
        status = 1
        where
        account_id = #{retry.accountId}
        and start_date = #{retry.startDate}
        and end_date = #{retry.endDate}
    </update>

    <insert id="replaceIntoVideoMaterialBatch">
        REPLACE INTO ctop_bytedance_report_video_material_daily
        (
        account_id,
        material_id,
        stat_datetime,
        click,
        cost,
        avg_click_cost,
        deep_convert,
        deep_convert_cost,
        deep_convert_rate,
        dislike,
        report,
        play_duration_2s_rate,
        play_duration_3s_rate,
        play_duration_5s_rate,
        play_duration_10s_rate,
        play_25_feed_break_rate,
        play_50_feed_break_rate,
        play_75_feed_break_rate,
        play_100_feed_break_rate,
        avg_show_cost,
        total_play,
        valid_play,
        share_material,
        comment_material,
        follow,
        valid_play_cost,
        convert_material,
        play_over_rate,
        ctr,
        like_material,
        show_material,
        convert_rate,
        play_over,
        message_action,
        valid_play_rate,
        average_play_time_per_play,
        convert_cost,
        convert_show_rate
        )
        VALUES
        <foreach collection="infos" item="info" separator=",">
            (
            #{info.accountId},
            #{info.materialId},
            #{info.statDatetime},
            #{info.click},
            #{info.cost},
            #{info.avgClickCost},
            #{info.deepConvert},
            #{info.deepConvertCost},
            #{info.deepConvertRate},
            #{info.dislike},
            #{info.report},
            #{info.playDuration2sRate},
            #{info.playDuration3sRate},
            #{info.playDuration5sRate},
            #{info.playDuration10sRate},
            #{info.play25FeedBreakRate},
            #{info.play50FeedBreakRate},
            #{info.play75FeedBreakRate},
            #{info.play100FeedBreakRate},
            #{info.avgShowCost},
            #{info.totalPlay},
            #{info.validPlay},
            #{info.shareMaterial},
            #{info.commentMaterial},
            #{info.follow},
            #{info.validPlayCost},
            #{info.convertMaterial},
            #{info.playOverRate},
            #{info.ctr},
            #{info.likeMaterial},
            #{info.showMaterial},
            #{info.convertRate},
            #{info.playOver},
            #{info.messageAction},
            #{info.validPlayRate},
            #{info.averagePlayTimePerPlay},
            #{info.convertCost},
            #{info.convertShowRate}
            )
        </foreach>
    </insert>










</mapper>
