<?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.kuaishou.modules.batch.mapper.KuaiShouVideoGetMapper">
    <insert id="replaceBatch">
        replace into ctop_kuaishou_video_get(
        id,
        account_id,
        photo_id,
        width,
        height,
        url,
        cover_url,
        material_type,
        signature,
        update_time
        )
        values
        <foreach collection="videos" item="video" separator=",">
            (
            #{video.id},
            #{video.accountId},
            #{video.photoId},
            #{video.width},
            #{video.height},
            #{video.url},
            #{video.coverUrl},
            #{video.materialType},
            #{video.signature},
            #{video.updateTime}

            )
        </foreach>
    </insert>


    <select id="getVideoList" parameterType="java.util.Map"
            resultType="cn.com.ctop.kuaishou.modules.batch.entity.vo.KuaiShouVideoGetVo">
        select
        stat_date as 'statDate',
        photo_id as 'photoId',
        url as 'url',
        cover_url as 'coverUrl',
        signature as 'signature',
        material_type as 'materialType'
        from ctop_kuaishou_video_get
        where account_id = #{accountId}
        and channel_type = #{channelType}
        and material_type = #{materialType}
        and status = 0
        <if test="startDate != null and startDate != '' ">
            and stat_date &gt;= #{startDate}
        </if>
        <if test="endDate != null and endDate != '' ">
            and stat_date &lt;= #{endDate}
        </if>
        group by signature
        order by stat_date desc
    </select>


    <select id="getHighQualityVideo" parameterType="java.util.Map"
            resultType="cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouVideoGet">
        select * from ctop_kuaishou_video_get
        where account_id = #{accountId}
        and signature in
        (
        select
            daily_material.signature
        from
        ctop_kuaishou_report_daily_material daily_material
        inner join
        ctop_user_allocation allocation
        on daily_material.account_id = allocation.account_id
        where  allocation.project_id in (select project_id from ctop_user_allocation where account_id = #{accountId})
        and  to_days(now()) - to_days(daily_material.stat_date) &lt;= #{days}
        and daily_material.signature is not null
        GROUP BY daily_material.signature
        order by sum(daily_material.charge) desc
        limit #{num}
        )
    </select>

    <select id="selectPhotoIdsByAccountId" parameterType="java.lang.Long"
            resultType="cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouVideoGet">
        select * from ctop_kuaishou_video_get
        where account_id = #{accountId}
        and status = 0
    </select>

    <select id="getVideoListByMap" resultType="com.alibaba.fastjson.JSONObject">
        select
        photo_id as 'photo_id',
        signature as 'signature',
        stat_date as 'stat_date',
        material_type as 'material_type',
        channel_type as 'channel_type',
        url as 'video_url'
        from ctop_kuaishou_video_get
        where 1 = 1
        <if test="accountId != null and accountId != '' ">
            and account_id = #{accountId}
        </if>
        <if test="startTime != null and startTime != '' ">
            and stat_date &gt;= #{startTime}
        </if>
        <if test="endTime != null and endTime != '' ">
            and stat_date &lt;= #{endTime}
        </if>
        group by signature
        order by stat_date desc
    </select>


</mapper>
