<?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.ktg.system.mapper.SysUploadFileMapper">
    
    <resultMap type="SysUploadFile" id="SysUploadFileResult">
        <result property="id"    column="id"    />
        <result property="name"    column="name"    />
        <result property="path"    column="path"    />
        <result property="url"    column="url"    />
        <result property="type"    column="type"    />
        <result property="size"    column="size"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectSysUploadFileVo">
        select id, name, path, url, type, size, del_flag, create_by, create_time, update_time, update_by, remark from sys_upload_file
    </sql>

    <select id="selectSysUploadFileList" parameterType="SysUploadFile" resultMap="SysUploadFileResult">
        <include refid="selectSysUploadFileVo"/>
        <where>  
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="path != null  and path != ''"> and path = #{path}</if>
            <if test="url != null  and url != ''"> and url = #{url}</if>
            <if test="type != null  and type != ''"> and type = #{type}</if>
            <if test="size != null "> and size = #{size}</if>
        </where>
    </select>
    
    <select id="selectSysUploadFileById" parameterType="Long" resultMap="SysUploadFileResult">
        <include refid="selectSysUploadFileVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertSysUploadFile" parameterType="SysUploadFile" useGeneratedKeys="true" keyProperty="id">
        insert into sys_upload_file
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null">name,</if>
            <if test="path != null and path != ''">path,</if>
            <if test="url != null and url != ''">url,</if>
            <if test="type != null">type,</if>
            <if test="size != null">size,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null">#{name},</if>
            <if test="path != null and path != ''">#{path},</if>
            <if test="url != null and url != ''">#{url},</if>
            <if test="type != null">#{type},</if>
            <if test="size != null">#{size},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateSysUploadFile" parameterType="SysUploadFile">
        update sys_upload_file
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null">name = #{name},</if>
            <if test="path != null and path != ''">path = #{path},</if>
            <if test="url != null and url != ''">url = #{url},</if>
            <if test="type != null">type = #{type},</if>
            <if test="size != null">size = #{size},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSysUploadFileById" parameterType="Long">
        delete from sys_upload_file where id = #{id}
    </delete>

    <delete id="deleteSysUploadFileByIds" parameterType="String">
        delete from sys_upload_file where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>