<?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.reghao.tnb.content.app.vod.db.mapper.VideoFileMapper">
    <insert id="save" useGeneratedKeys="true" keyProperty="id">
        insert into vod_video_file
        (`video_id`,`object_id`,`channel_code`,`video_codec`,`vbit_rate`,`audio_codec`,`abit_rate`,`format_name`,`url_type`,`url`,`quality`,`width`,`height`,`horizontal`,`duration`,`size`)
        values
        (#{videoId},#{objectId},#{channelCode},#{videoCodec},#{vbitRate},#{audioCodec},#{abitRate},#{formatName},#{urlType},#{url},#{quality},#{width},#{height},#{horizontal},#{duration},#{size})
    </insert>
    <insert id="saveAll" useGeneratedKeys="true" keyProperty="id">
        insert into vod_video_file
        (`video_id`,`object_id`,`channel_code`,`video_codec`,`vbit_rate`,`audio_codec`,`abit_rate`,`format_name`,`url_type`,`url`,`quality`,`width`,`height`,`horizontal`,`duration`,`size`)
        values
        <foreach collection="list" item="item" index="index" separator=",">
            (#{item.videoId},#{item.objectId},#{item.channelCode},#{item.videoCodec},#{item.vbitRate},#{item.audioCodec},#{item.abitRate},#{item.formatName},#{item.urlType},#{item.url},#{item.quality},#{item.width},#{item.height},#{item.horizontal},#{item.duration},#{size})
        </foreach>
    </insert>

    <update id="updateDeleteByObjectId">
        update vod_video_file
        set deleted=1
        where object_id=#{objectId}
    </update>

    <select id="findAll" resultType="cn.reghao.tnb.content.app.vod.model.po.VideoFile">
        select *
        from vod_video_file
    </select>
    <select id="findVideoInfo" resultType="cn.reghao.oss.api.dto.media.VideoInfo">
        select object_id,duration,horizontal,quality,video_codec,audio_codec,url_type,url
        from vod_video_file
        where `deleted`=0 and object_id=#{objectId}
    </select>
    <select id="findByVideoId" resultType="cn.reghao.tnb.content.app.vod.model.po.VideoFile">
        select *
        from vod_video_file
        where `deleted`=0 and video_id=#{videoId}
    </select>
    <select id="findByVideoFileId" resultType="cn.reghao.tnb.content.app.vod.model.po.VideoFile">
        select *
        from vod_video_file
        where `deleted`=0 and object_id=#{objectId}
    </select>
    <select id="findVideoUrls" resultType="cn.reghao.oss.api.dto.media.VideoUrlDto">
        select object_id,channel_code,url_type as type,url,width,height,quality
        from vod_video_file
        where `deleted`=0 and video_id=#{videoId}
        order by id desc
    </select>
</mapper>
