<?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.ctop.mapper.KuaishouEffectVideoInfoMapper">

    <update id="updateInitialCostDateBySignature">
        update ctop_kuaishou_effect_video_info a
        set a.initial_cost_date = (select min(report.stat_date)
                           from ctop_kuaishou_report_daily_creative report
                                    left join ctop_kuaishou_creative creative
                                              on creative.creative_id = report.creative_id
                                    left join ctop_kuaishou_video_get video on video.photo_id = creative.photo_id
                           where video.signature = #{signature})
        where a.signature = #{signature}
    </update>
    <update id="updateFinalCostDateBySignature">
        update ctop_kuaishou_effect_video_info a
        set a.final_cost_date = (select max(report.stat_date)
                           from ctop_kuaishou_report_daily_creative report
                                    left join ctop_kuaishou_creative creative
                                              on creative.creative_id = report.creative_id
                                    left join ctop_kuaishou_video_get video on video.photo_id = creative.photo_id
                           where video.signature = #{signature})
        where a.signature = #{signature}
    </update>
    <update id="updateTotalCostBySignature">
        update ctop_kuaishou_effect_video_info a
        set a.total_cost = (select sum(report.charge)
                           from ctop_kuaishou_report_daily_creative report
                                    left join ctop_kuaishou_creative creative
                                              on creative.creative_id = report.creative_id
                                    left join ctop_kuaishou_video_get video on video.photo_id = creative.photo_id
                           where video.signature = #{signature})
        where a.signature = #{signature}
    </update>
    <update id="updateTowWeekCostBySignature">
        update ctop_kuaishou_effect_video_info a
        set a.two_week_cost = (select sum(report.charge)
                from ctop_kuaishou_report_daily_creative report
                left join ctop_kuaishou_creative creative
                    on creative.creative_id = report.creative_id
        left join ctop_kuaishou_video_get video on video.photo_id = creative.photo_id
        where video.signature = #{signature} and report.stat_date &gt; DATE_ADD(a.initial_cost_date,INTERVAL 14 DAY))
        where a.signature = #{signature}
    </update>
</mapper>
