<?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.fs.course.mapper.FsUserVideoTagsMapper">

    <resultMap type="FsUserVideoTags" id="FsUserVideoTagsResult">
        <result property="tagId"    column="tag_id"    />
        <result property="pid"    column="pid"    />
        <result property="tagName"    column="tag_name"    />
        <result property="sort"    column="sort"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="isDel"    column="is_del"    />
    </resultMap>

    <sql id="selectFsUserVideoTagsVo">
        select tag_id, pid, tag_name, sort, create_time, update_time, is_del from fs_user_video_tags
    </sql>

    <select id="selectFsUserVideoTagsList" parameterType="FsUserVideoTags" resultMap="FsUserVideoTagsResult">
        <include refid="selectFsUserVideoTagsVo"/>
        <where>
            <if test="pid != null "> and pid = #{pid}</if>
            <if test="tagName != null  and tagName != ''"> and tag_name like concat('%', #{tagName}, '%')</if>
            <if test="sort != null "> and sort = #{sort}</if>
            <if test="isDel != null  and isDel != ''"> and is_del = #{isDel}</if>
        </where>
    </select>

<!--    <select id="selectFsUserVideoTagsSubList" parameterType="FsUserVideoTags" resultMap="FsUserVideoTagsResult">-->
<!--        <include refid="selectFsUserVideoTagsVo"/>-->
<!--        where pid !=0 and is_del = 0-->
<!--            <if test="tagName != null  and tagName != ''"> and tag_name like concat('%', #{tagName}, '%')</if>-->
<!--    </select>-->

    <select id="selectFsUserVideoTagsByTagId" parameterType="Long" resultMap="FsUserVideoTagsResult">
        <include refid="selectFsUserVideoTagsVo"/>
        where tag_id = #{tagId}
    </select>

    <insert id="insertFsUserVideoTags" parameterType="FsUserVideoTags" useGeneratedKeys="true" keyProperty="tagId">
        insert into fs_user_video_tags
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="pid != null">pid,</if>
            <if test="tagName != null and tagName != ''">tag_name,</if>
            <if test="sort != null">sort,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="isDel != null">is_del,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="pid != null">#{pid},</if>
            <if test="tagName != null and tagName != ''">#{tagName},</if>
            <if test="sort != null">#{sort},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="isDel != null">#{isDel},</if>
         </trim>
    </insert>

    <update id="updateFsUserVideoTags" parameterType="FsUserVideoTags">
        update fs_user_video_tags
        <trim prefix="SET" suffixOverrides=",">
            <if test="pid != null">pid = #{pid},</if>
            <if test="tagName != null and tagName != ''">tag_name = #{tagName},</if>
            <if test="sort != null">sort = #{sort},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="isDel != null">is_del = #{isDel},</if>
        </trim>
        where tag_id = #{tagId}
    </update>

    <update id="deleteFsUserVideoTagsByTagId" parameterType="Long">
        update fs_user_video_tags set is_del = 1 where tag_id = #{tagId}
    </update>

    <update id="deleteFsUserVideoTagsByTagIds" parameterType="String">
        update fs_user_video_tags set is_del = 1 where tag_id in
        <foreach item="tagId" collection="array" open="(" separator="," close=")">
            #{tagId}
        </foreach>
    </update>
</mapper>
