<?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.cpms.project.file.mapper.TFileMapper">

    <resultMap type="TFile" id="TFileResult">
        <result property="id"    column="id"    />
        <result property="fileUrl"    column="file_url"    />
        <result property="fileName"    column="file_name"    />
        <result property="fileSize"    column="file_size"    />
        <result property="type"    column="type"    />
        <result property="uploadDate"    column="upload_date"    />
        <result property="uploader"    column="uploader"    />
        <result property="remark"    column="remark"    />
        <result property="linkId"    column="link_id"    />
        <result property="linkName"    column="link_name"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="pId"    column="p_id"    />
    </resultMap>

    <sql id="selectTFileVo">
        select id, file_url, file_name, file_size, type, upload_date, uploader, remark, link_id, link_name, del_flag, p_id from t_file
    </sql>

    <select id="selectTFileList" parameterType="TFile" resultMap="TFileResult">
        <include refid="selectTFileVo"/>
        <where>
            <if test="fileUrl != null  and fileUrl != ''"> and file_url = #{fileUrl}</if>
            <if test="fileName != null  and fileName != ''"> and file_name like concat('%', #{fileName}, '%')</if>
            <if test="fileSize != null  and fileSize != ''"> and file_size = #{fileSize}</if>
            <if test="type != null  and type != ''"> and type = #{type}</if>
            <if test="uploadDate != null "> and upload_date = #{uploadDate}</if>
            <if test="uploader != null  and uploader != ''"> and uploader = #{uploader}</if>
            <if test="linkId != null "> and link_id = #{linkId}</if>
            <if test="linkName != null  and linkName != ''"> and link_name = #{linkName}</if>
            <if test="pId != null "> and p_id = #{pId}</if>
        </where>
    </select>

    <select id="selectTFileById" parameterType="Long" resultMap="TFileResult">
        <include refid="selectTFileVo"/>
        where id = #{id}
    </select>

    <insert id="insertTFile" parameterType="TFile" useGeneratedKeys="true" keyProperty="id">
        insert into t_file
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="fileUrl != null">file_url,</if>
            <if test="fileName != null">file_name,</if>
            <if test="fileSize != null">file_size,</if>
            <if test="type != null">type,</if>
            <if test="uploadDate != null">upload_date,</if>
            <if test="uploader != null">uploader,</if>
            <if test="remark != null">remark,</if>
            <if test="linkId != null">link_id,</if>
            <if test="linkName != null">link_name,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="pId != null">p_id,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="fileUrl != null">#{fileUrl},</if>
            <if test="fileName != null">#{fileName},</if>
            <if test="fileSize != null">#{fileSize},</if>
            <if test="type != null">#{type},</if>
            <if test="uploadDate != null">#{uploadDate},</if>
            <if test="uploader != null">#{uploader},</if>
            <if test="remark != null">#{remark},</if>
            <if test="linkId != null">#{linkId},</if>
            <if test="linkName != null">#{linkName},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="pId != null">#{pId},</if>
        </trim>
    </insert>

    <update id="updateTFile" parameterType="TFile">
        update t_file
        <trim prefix="SET" suffixOverrides=",">
            <if test="fileUrl != null">file_url = #{fileUrl},</if>
            <if test="fileName != null">file_name = #{fileName},</if>
            <if test="fileSize != null">file_size = #{fileSize},</if>
            <if test="type != null">type = #{type},</if>
            <if test="uploadDate != null">upload_date = #{uploadDate},</if>
            <if test="uploader != null">uploader = #{uploader},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="linkId != null">link_id = #{linkId},</if>
            <if test="linkName != null">link_name = #{linkName},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="pId != null">p_id = #{pId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTFileById" parameterType="Long">
        delete from t_file where id = #{id}
    </delete>

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