<?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.ebts.system.dao.FileDao">
    
    <resultMap type="com.ebts.system.entity.SysFile" id="FileResult">
        <result property="fileId"    column="file_id"    />
        <result property="pId"    column="p_id"    />
        <result property="unionId"    column="union_id"    />
        <result property="roleIds"    column="role_ids"    />
        <result property="fileName"    column="file_name"    />
        <result property="mapping"    column="mapping"    />
        <result property="fileAddr"    column="file_addr"    />
        <result property="fileType"    column="file_type"    />
        <result property="fileSize"    column="file_size"    />
        <result property="isPublic"    column="is_public"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectFileVo">
        select file_id, p_id, union_id, role_ids,inherit, file_name, mapping, file_addr, file_type, file_size, is_public, create_by, create_time, update_by, update_time from sys_file
    </sql>
    <select id="selectFileList" parameterType="SysFile" resultMap="FileResult">
        <include refid="selectFileVo"/>
        <where>
            and is_public != '3'
            <if test="fileName != null  and fileName != ''"> and file_name like concat('%', #{fileName}, '%')</if>
            <if test="fileAddr != null  and fileAddr != ''"> and file_addr like concat('%', #{fileAddr}, '%')</if>
            <if test="fileType != null  and fileType != ''"> and file_type = #{fileType}</if>
            <if test="isPublic != null  and isPublic != ''"> and is_public = #{isPublic}</if>
            <if test="params.beginCreateTime != null and params.beginCreateTime != '' and params.endCreateTime != null and params.endCreateTime != ''"> and create_time between #{params.beginCreateTime} and #{params.endCreateTime}</if>
        </where>
    </select>
    
    <select id="selectFileFolder" resultMap="FileResult">
        <include refid="selectFileVo"/>
        where is_public = '3'
    </select>
    <select id="selectFileById" parameterType="Long" resultMap="FileResult">
        <include refid="selectFileVo"/>
        where file_id = #{fileId}
    </select>
    

    <insert id="insertFile" parameterType="SysFile" useGeneratedKeys="true" keyProperty="fileId">
        insert into sys_file
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="pId != null">p_id,</if>
            <if test="unionId != null">union_id,</if>
            <if test="roleIds != null">role_ids,</if>
            <if test="inherit != null">inherit,</if>
            <if test="fileName != null">file_name,</if>
            <if test="mapping != null">mapping,</if>
            <if test="fileAddr != null">file_addr,</if>
            <if test="fileType != null">file_type,</if>
            <if test="fileSize != null">file_size,</if>
            <if test="isPublic != null">is_public,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="pId != null">#{pId},</if>
            <if test="unionId != null">#{unionId},</if>
            <if test="roleIds != null">#{roleIds},</if>
            <if test="inherit != null">#{inherit},</if>
            <if test="fileName != null">#{fileName},</if>
            <if test="mapping != null">#{mapping},</if>
            <if test="fileAddr != null">#{fileAddr},</if>
            <if test="fileType != null">#{fileType},</if>
            <if test="fileSize != null">#{fileSize},</if>
            <if test="isPublic != null">#{isPublic},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
         </trim>
    </insert>

    <update id="updateFile" parameterType="SysFile">
        update sys_file
        <trim prefix="SET" suffixOverrides=",">
            <if test="roleIds != null">role_ids = #{roleIds},</if>
        </trim>
        where file_id = #{fileId}
    </update>

    <delete id="deleteFileById" parameterType="Long">
        delete from sys_file where file_id = #{fileId}
    </delete>

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