<?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.tongran.rocketmq.mapper.RmFileInfoMapper">
    
    <resultMap type="RmFileInfo" id="RmFileInfoResult">
        <result property="id"    column="id"    />
        <result property="name"    column="name"    />
        <result property="type"    column="type"    />
        <result property="description"    column="description"    />
        <result property="fileSize"    column="file_size"    />
        <result property="md5"    column="md5"    />
        <result property="path"    column="path"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateBy"    column="update_by"    />
    </resultMap>

    <sql id="selectRmFileInfoVo">
        select id, name, type, description, file_size, md5, path, create_time, update_time, create_by, update_by from rm_file_info
    </sql>

    <select id="selectRmFileInfoList" parameterType="RmFileInfo" resultMap="RmFileInfoResult">
        <include refid="selectRmFileInfoVo"/>
        <where>  
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="type != null  and type != ''"> and type = #{type}</if>
            <if test="description != null  and description != ''"> and description = #{description}</if>
            <if test="fileSize != null "> and file_size = #{fileSize}</if>
            <if test="md5 != null  and md5 != ''"> and md5 = #{md5}</if>
            <if test="path != null  and path != ''"> and path = #{path}</if>
        </where>
    </select>
    
    <select id="selectRmFileInfoById" parameterType="Long" resultMap="RmFileInfoResult">
        <include refid="selectRmFileInfoVo"/>
        where id = #{id}
    </select>

    <insert id="insertRmFileInfo" parameterType="RmFileInfo" useGeneratedKeys="true" keyProperty="id">
        insert into rm_file_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null and name != ''">name,</if>
            <if test="type != null and type != ''">type,</if>
            <if test="description != null">description,</if>
            <if test="fileSize != null">file_size,</if>
            <if test="md5 != null and md5 != ''">md5,</if>
            <if test="path != null and path != ''">path,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null and name != ''">#{name},</if>
            <if test="type != null and type != ''">#{type},</if>
            <if test="description != null">#{description},</if>
            <if test="fileSize != null">#{fileSize},</if>
            <if test="md5 != null and md5 != ''">#{md5},</if>
            <if test="path != null and path != ''">#{path},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
         </trim>
    </insert>

    <update id="updateRmFileInfo" parameterType="RmFileInfo">
        update rm_file_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="type != null and type != ''">type = #{type},</if>
            <if test="description != null">description = #{description},</if>
            <if test="fileSize != null">file_size = #{fileSize},</if>
            <if test="md5 != null and md5 != ''">md5 = #{md5},</if>
            <if test="path != null and path != ''">path = #{path},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteRmFileInfoById" parameterType="Long">
        delete from rm_file_info where id = #{id}
    </delete>

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