<?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="com.tzld.piaoquan.api.dao.mapper.wecom.thirdpart.ext.ThirdPartWeComVideoMapperExt">

    <insert id="batchInsertThirdPartWeComVideo">
        insert into third_part_we_com_video (dt, video_id, category, title, cover, video, score, create_timestamp)
        values
        <foreach collection="records" item="item" separator=",">
            (#{item.dt}, #{item.videoId}, #{item.category}, #{item.title}, #{item.cover}, #{item.video}, #{item.score},
            #{item.createTimestamp})
        </foreach>
    </insert>

    <select id="getVideoMaxDt" resultType="java.lang.String">
        select max(dt)
        from third_part_we_com_video
    </select>

    <update id="updateOtherVideoStatus">
        update third_part_we_com_video
        set status = 0,
            update_timestamp = #{now}
        where dt = #{dt} and video_id not in
        <foreach collection="videoIdList" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
    </update>

    <update id="updateVideoStatusWithOldStatus">
        update third_part_we_com_video
        set status = #{status},
            update_timestamp = #{now}
        where video_id = #{videoId}
          and status = #{oldStatus}
    </update>

    <select id="getVideoMinScoreList" resultType="com.tzld.piaoquan.api.model.po.contentplatform.ContentPlatformVideo">
        select *
        from third_part_we_com_video video
        where video.dt = #{dt} and video.status = 1
          and video.video_id not in (select video_id from third_part_we_com_msg where send_userid = #{roomId} and video_id is not null)
        order by ${sort}
        limit #{offset}, #{pageSize}
    </select>

</mapper>