<?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.ho.filecenter.mapper.MediaFileMapper">


    <sql id="Base_Column_List">
        id
        ,user_id,group_id,
        dept_id,file_suffix,file_path,
        file_name,create_time
    </sql>

    <select id="selectByPrimaryKey" resultType="com.ho.filecenter.entity.MediaFile">
        select
        <include refid="Base_Column_List"/>
        from media_file
        where id = #{id,jdbcType=BIGINT}
    </select>


    <select id="selectByInfo" resultType="com.ho.filecenter.entity.MediaFile">
        select
        <include refid="Base_Column_List"/>
        from media_file
        <where>
            <if test="groupId != null">
                and group_id = #{groupId}
            </if>
            <if test="vo.fileName != null">
                and file_name LIKE concat('%',#{vo.fileName},'%')
            </if>
        </where>
        order by
        create_time desc
    </select>
    <select id="selectByPath" resultType="com.ho.filecenter.entity.MediaFile">
        select
        <include refid="Base_Column_List"/>
        from media_file
        <where>
            <if test="directory != null ">
                file_path = #{directory}
            </if>
        </where>
    </select>
    <select id="selectAll" resultType="com.ho.filecenter.entity.MediaFile">
        select
        <include refid="Base_Column_List"/>
        from media_file
        <where>
            <if test="fileName != null">
                file_name LIKE concat('%',#{fileName},'%')
            </if>
        </where>
        order by
        create_time desc
    </select>
    <select id="selectByIds" resultType="com.ho.filecenter.entity.MediaFile">
        select
        <include refid="Base_Column_List"/>
        from media_file
        <where>
            <if test="ids != null and ids.size != 0 ">
                id in
                <foreach collection="ids" open="(" close=")" separator="," item="item">
                    #{item}
                </foreach>
            </if>
        </where>
    </select>

    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
        delete
        from media_file
        where id = #{id,jdbcType=BIGINT}
    </delete>

    <delete id="deleteByIds">
        delete
        from media_file
        <where>
            <if test="ids != null and ids.size != 0">
                id in
                <foreach collection="ids" open="(" close=")" separator="," item="item">
                    #{item}
                </foreach>
            </if>
        </where>
    </delete>


    <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.ho.filecenter.entity.MediaFile"
            useGeneratedKeys="true">
        insert into media_file
        ( id, user_id, group_id
        , dept_id, file_suffix, file_path
        , file_name, create_time)
        values ( #{id,jdbcType=BIGINT}, #{userId,jdbcType=VARCHAR}, #{groupId,jdbcType=INTEGER}
               , #{deptId,jdbcType=INTEGER}, #{fileSuffix,jdbcType=VARCHAR}, #{filePath,jdbcType=VARCHAR}
               , #{fileName,jdbcType=VARCHAR}, #{createTime})
    </insert>
    <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.ho.filecenter.entity.MediaFile"
            useGeneratedKeys="true">
        insert into media_file
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="userId != null">user_id,</if>
            <if test="groupId != null">group_id,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="fileSuffix != null">file_suffix,</if>
            <if test="filePath != null">file_path,</if>
            <if test="fileName != null">file_name,</if>
            <if test="createTime != null">create_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id,jdbcType=BIGINT},</if>
            <if test="userId != null">#{userId,jdbcType=VARCHAR},</if>
            <if test="groupId != null">#{groupId,jdbcType=INTEGER},</if>
            <if test="deptId != null">#{deptId,jdbcType=INTEGER},</if>
            <if test="fileSuffix != null">#{fileSuffix,jdbcType=VARCHAR},</if>
            <if test="filePath != null">#{filePath,jdbcType=VARCHAR},</if>
            <if test="fileName != null">#{fileName,jdbcType=VARCHAR},</if>
            <if test="createTime != null">#{createTime},</if>
        </trim>
    </insert>
    <update id="updateByPrimaryKeySelective" parameterType="com.ho.filecenter.entity.MediaFile">
        update media_file
        <set>
            <if test="userId != null">
                user_id = #{userId,jdbcType=VARCHAR},
            </if>
            <if test="groupId != null">
                group_id = #{groupId,jdbcType=INTEGER},
            </if>
            <if test="deptId != null">
                dept_id = #{deptId,jdbcType=INTEGER},
            </if>
            <if test="fileSuffix != null">
                file_suffix = #{fileSuffix,jdbcType=VARCHAR},
            </if>
            <if test="filePath != null">
                file_path = #{filePath,jdbcType=VARCHAR},
            </if>
            <if test="fileName != null">
                file_name = #{fileName,jdbcType=VARCHAR},
            </if>
            <if test="createTime != null">
                create_time = #{createTime,jdbcType=DATE},
            </if>
        </set>
        where id = #{id,jdbcType=BIGINT}
    </update>
    <update id="updateByPrimaryKey" parameterType="com.ho.filecenter.entity.MediaFile">
        update media_file
        set user_id     = #{userId,jdbcType=VARCHAR},
            group_id    = #{groupId,jdbcType=INTEGER},
            dept_id     = #{deptId,jdbcType=INTEGER},
            file_suffix = #{fileSuffix,jdbcType=VARCHAR},
            file_path   = #{filePath,jdbcType=VARCHAR},
            file_name   = #{fileName,jdbcType=VARCHAR},
            create_time = #{createTime,jdbcType=DATE}
        where id = #{id,jdbcType=BIGINT}
    </update>
</mapper>
