<?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.VideoTagMapper">
    <insert id="save" useGeneratedKeys="true" keyProperty="id">
        insert into vod_video_tag
        (`video_id`,`scope`,`tag_id`)
        values
        (#{videoId},#{scope},#{tagId})
    </insert>
    <insert id="saveAll" useGeneratedKeys="true" keyProperty="id">
        insert ignore into vod_video_tag
        (`video_id`,`scope`,`tag_id`)
        values
        <foreach collection="list" item="item" index="index" separator=",">
            (#{item.videoId},#{item.scope},#{item.tagId})
        </foreach>
    </insert>

    <update id="updateSetScope">
        update vod_video_tag
        set `scope`=#{scope}
        where video_id=#{videoId}
    </update>

    <select id="findAll" resultType="cn.reghao.tnb.content.app.vod.model.po.VideoTag">
        select *
        from vod_video_tag
        limit 1000
    </select>
    <select id="countVideosByTag" resultType="java.lang.Integer">
        select count(*)
        from vod_video_tag
        where tag_id=#{tagId} and scope in
        <foreach collection="scopes" item="id" index="index" open="(" close=")" separator=",">
            #{id}
        </foreach>
    </select>
    <select id="findVideosByPage" resultType="java.lang.String">
        select video_id
        from vod_video_tag
        where tag_id=#{tagId} and scope in
        <foreach collection="scopes" item="id" index="index" open="(" close=")" separator=",">
            #{id}
        </foreach>
    </select>
    <select id="findVideoTags" resultType="java.lang.String">
        select tag_name
        from vod_post_tag
        inner join vod_video_tag
        on vod_post_tag.tag_id=vod_video_tag.tag_id and vod_video_tag.video_id=#{videoId}
    </select>
    <select id="findByGroupBy" resultType="java.lang.String">
        select video_id
        from vod_video_tag
        group by video_id
    </select>
</mapper>
