<?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.bonus.sgzb.system.mapper.FileInfoMapper">
    
    <resultMap type="com.bonus.sgzb.system.domain.FileInfo" id="SysFileInfoResult">
        <result property="id"    column="id"    />
        <result property="modelId"    column="model_id"    />
        <result property="fileName"    column="file_name"    />
        <result property="fileUrl"    column="file_url"    />
        <result property="dicId"    column="dic_id"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectSysFileInfoVo">
        select id, model_id, file_name, file_url, dic_id, create_by, create_time from sys_file_info
    </sql>

    <select id="selectSysFileInfoList" parameterType="com.bonus.sgzb.system.domain.FileInfo" resultMap="SysFileInfoResult">
        <include refid="selectSysFileInfoVo"/>
        <where>  
            <if test="modelId != null "> and model_id = #{modelId}</if>
            <if test="fileName != null  and fileName != ''"> and file_name like concat('%', #{fileName}, '%')</if>
            <if test="fileUrl != null  and fileUrl != ''"> and file_url = #{fileUrl}</if>
            <if test="dicId != null "> and dic_id = #{dicId}</if>
        </where>
    </select>
    
    <select id="selectSysFileInfoById" parameterType="Long" resultMap="SysFileInfoResult">
        <include refid="selectSysFileInfoVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertFileInfo" parameterType="com.bonus.sgzb.system.domain.FileInfo" useGeneratedKeys="true" keyProperty="id">
        insert into sys_file_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="modelId != null">model_id,</if>
            <if test="fileName != null">file_name,</if>
            <if test="fileUrl != null">file_url,</if>
            <if test="dicId != null">dic_id,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="modelId != null">#{modelId},</if>
            <if test="fileName != null">#{fileName},</if>
            <if test="fileUrl != null">#{fileUrl},</if>
            <if test="dicId != null">#{dicId},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
         </trim>
    </insert>

    <update id="updateSysFileInfo" parameterType="com.bonus.sgzb.system.domain.FileInfo">
        update sys_file_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="modelId != null">model_id = #{modelId},</if>
            <if test="fileName != null">file_name = #{fileName},</if>
            <if test="fileUrl != null">file_url = #{fileUrl},</if>
            <if test="dicId != null">dic_id = #{dicId},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSysFileInfoById" parameterType="Long">
        delete from sys_file_info where id = #{id}
    </delete>

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