<?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.ruoyi.system.mapper.TblUploadFileMapper">
    
    <resultMap type="TblUploadFile" id="TblUploadFileResult">
        <result property="id"    column="id"    />
        <result property="relType"    column="rel_type"    />
        <result property="relId"    column="rel_id"    />
        <result property="fileName"    column="file_name"    />
        <result property="filePath"    column="file_path"    />
        <result property="fileExt"    column="file_ext"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectTblUploadFileVo">
        select id, rel_type, rel_id, file_name, file_path, file_ext, del_flag, create_by, create_time from tbl_upload_file
    </sql>

    <select id="selectTblUploadFileList" parameterType="TblUploadFile" resultMap="TblUploadFileResult">
        <include refid="selectTblUploadFileVo"/>
        <where>  
            <if test="relType != null  and relType != ''"> and rel_type = #{relType}</if>
            <if test="relId != null  and relId != ''"> and rel_id = #{relId}</if>
            <if test="fileName != null  and fileName != ''"> and file_name like concat('%', #{fileName}, '%')</if>
            <if test="filePath != null  and filePath != ''"> and file_path = #{filePath}</if>
            <if test="fileExt != null  and fileExt != ''"> and file_ext = #{fileExt}</if>
            and (del_flag is null or del_flag = '0')
        </where>
    </select>
    
    <select id="selectTblUploadFileById" parameterType="String" resultMap="TblUploadFileResult">
        <include refid="selectTblUploadFileVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTblUploadFile" parameterType="TblUploadFile">
        insert into tbl_upload_file
        <trim prefix="(" suffix=")" suffixOverrides=",">
            id,
            <if test="relType != null and relType != ''">rel_type,</if>
            <if test="relId != null and relId != ''">rel_id,</if>
            <if test="fileName != null and fileName != ''">file_name,</if>
            <if test="filePath != null and filePath != ''">file_path,</if>
            <if test="fileExt != null and fileExt != ''">file_ext,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            (select REPLACE(UUID(),'-','')),
            <if test="relType != null and relType != ''">#{relType},</if>
            <if test="relId != null and relId != ''">#{relId},</if>
            <if test="fileName != null and fileName != ''">#{fileName},</if>
            <if test="filePath != null and filePath != ''">#{filePath},</if>
            <if test="fileExt != null and fileExt != ''">#{fileExt},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
         </trim>
    </insert>

    <update id="updateTblUploadFile" parameterType="TblUploadFile">
        update tbl_upload_file
        <trim prefix="SET" suffixOverrides=",">
            <if test="relType != null and relType != ''">rel_type = #{relType},</if>
            <if test="relId != null and relId != ''">rel_id = #{relId},</if>
            <if test="fileName != null and fileName != ''">file_name = #{fileName},</if>
            <if test="filePath != null and filePath != ''">file_path = #{filePath},</if>
            <if test="fileExt != null and fileExt != ''">file_ext = #{fileExt},</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>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTblUploadFileById" parameterType="String">
        update tbl_upload_file set del_flag = '2'
        where id = #{id}
    </delete>

    <delete id="deleteTblUploadFileByIds" parameterType="String">
        update tbl_upload_file set del_flag = '2'
        where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

</mapper>