<?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.file.mapper.FilesStorageMapper">
    
    <resultMap type="FilesStorage" id="FilesStorageResult">
        <result property="id"    column="id"    />
        <result property="storageAddress"    column="storage_address"    />
        <result property="administrator"    column="administrator"    />
        <result property="remark"    column="remark"    />
        <association property="user"    javaType="SysUser"         resultMap="SysUserResult" />
    </resultMap>

    <resultMap type="SysUser" id="SysUserResult">
        <result property="userId"    column="user_id"    />
        <result property="nickName"    column="nick_name"    />
    </resultMap>

    <sql id="selectFilesStorageVo">
        select s.id, s.storage_address, s.administrator, u.nick_name, s.remark from files_storage as s
        left join sys_user as u on u.user_id = s.administrator
    </sql>

    <select id="selectFilesStorageList" parameterType="FilesStorage" resultMap="FilesStorageResult">
        <include refid="selectFilesStorageVo"/>
        <where>  
            <if test="storageAddress != null  and storageAddress != ''"> and s.storage_address like concat('%', #{storageAddress}, '%')</if>
            <if test="administrator != null  and administrator != ''"> and s.administrator like concat('%', #{administrator}, '%')</if>
        </where>
    </select>

    <select id="selectFilesStorageListE" parameterType="FilesStorage" resultMap="FilesStorageResult">
        <include refid="selectFilesStorageVo"/>
        <where>
            <if test="storageAddress != null  and storageAddress != ''"> and s.storage_address = #{storageAddress}</if>
            <if test="administrator != null  and administrator != ''"> and s.administrator = #{administrator}</if>
        </where>
    </select>

    <select id="selectFilesStorageById" parameterType="String" resultMap="FilesStorageResult">
        <include refid="selectFilesStorageVo"/>
        where s.id = #{id}
    </select>
        
    <insert id="insertFilesStorage" parameterType="FilesStorage">
        insert into files_storage
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="storageAddress != null">storage_address,</if>
            <if test="administrator != null">administrator,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="storageAddress != null">#{storageAddress},</if>
            <if test="administrator != null">#{administrator},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateFilesStorage" parameterType="FilesStorage">
        update files_storage
        <trim prefix="SET" suffixOverrides=",">
            <if test="storageAddress != null">storage_address = #{storageAddress},</if>
            <if test="administrator != null">administrator = #{administrator},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteFilesStorageById" parameterType="String">
        delete from files_storage where id = #{id}
    </delete>

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