<?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.example.mapper.VideoMapper">

    <sql id="Base_Column_List">
        id,video_name,video_url,video_uuid
    </sql>

    <select id="selectAll" resultType="com.example.entity.Video">
        select
        <include refid="Base_Column_List" />
        from video
        <where>
            <if test="id != null"> and id = #{id}</if>
            <if test="videoName != null"> and video_name like concat('%', #{videoName}, '%')</if>
            <if test="videoUrl != null"> and video_url like concat('%', #{videoUrl}, '%')</if>
            <if test="videoUuid != null"> and video_uuid like concat('%', #{videoUuid}, '%')</if>
        </where>
        order by id desc
    </select>

    <select id="selectById" resultType="com.example.entity.Video">
        select
        <include refid="Base_Column_List" />
        from video
        where id = #{id}
    </select>

    <delete id="deleteById">
        delete from video
        where  id = #{id}
    </delete>

    <insert id="insert" parameterType="com.example.entity.Video" useGeneratedKeys="true">
        insert into video
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="videoName != null">video_name,</if>
            <if test="videoUrl != null">video_url,</if>
            <if test="videoUuid != null">video_uuid,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="videoName != null">#{videoName},</if>
            <if test="videoUrl != null">#{videoUrl},</if>
            <if test="videoUuid != null">#{videoUuid},</if>
        </trim>
    </insert>

    <update id="updateById" parameterType="com.example.entity.Video">
        update video
        <set>
            <if test="videoName != null">
                video_name = #{videoName},
            </if>
            <if test="videoUrl != null">
                video_url = #{videoUrl},
            </if>
            <if test="videoUuid != null">
                video_uuid = #{videoUuid},
            </if>
        </set>
        where id = #{id} 
    </update>

</mapper>