<?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="org.dromara.member.mapper.AppFileMapper">

    <resultMap type="org.dromara.member.domain.AppFile" id="AppFileResult">
        <result property="fileId" column="file_id"/>
        <result property="userId" column="user_id"/>
        <result property="fileName" column="file_name"/>
        <result property="originalName" column="original_name"/>
        <result property="filePath" column="file_path"/>
        <result property="fileUrl" column="file_url"/>
        <result property="fileSize" column="file_size"/>
        <result property="fileType" column="file_type"/>
        <result property="fileSuffix" column="file_suffix"/>
        <result property="fileCategory" column="file_category"/>
        <result property="storageService" column="storage_service"/>
        <result property="status" column="status"/>
        <result property="downloadCount" column="download_count"/>
        <result property="isPublic" column="is_public"/>
        <result property="fileMd5" column="file_md5"/>
        <result property="remark" column="remark"/>
        <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="selectAppFileVo">
        select file_id,
               user_id,
               file_name,
               original_name,
               file_path,
               file_url,
               file_size,
               file_type,
               file_suffix,
               file_category,
               storage_service,
               status,
               download_count,
               is_public,
               file_md5,
               remark,
               create_by,
               create_time,
               update_by,
               update_time
        from app_file
    </sql>

    <select id="selectAppFileList" parameterType="org.dromara.member.domain.AppFile" resultMap="AppFileResult">
        <include refid="selectAppFileVo"/>
        <where>
            <if test="userId != null ">and user_id = #{userId}</if>
            <if test="fileName != null  and fileName != ''">and file_name like concat('%', #{fileName}, '%')</if>
            <if test="originalName != null  and originalName != ''">and original_name like concat('%', #{originalName},
                '%')
            </if>
            <if test="filePath != null  and filePath != ''">and file_path = #{filePath}</if>
            <if test="fileUrl != null  and fileUrl != ''">and file_url = #{fileUrl}</if>
            <if test="fileSize != null ">and file_size = #{fileSize}</if>
            <if test="fileType != null  and fileType != ''">and file_type = #{fileType}</if>
            <if test="fileSuffix != null  and fileSuffix != ''">and file_suffix = #{fileSuffix}</if>
            <if test="fileCategory != null ">and file_category = #{fileCategory}</if>
            <if test="storageService != null  and storageService != ''">and storage_service = #{storageService}</if>
            <if test="status != null  and status != ''">and status = #{status}</if>
            <if test="downloadCount != null ">and download_count = #{downloadCount}</if>
            <if test="isPublic != null  and isPublic != ''">and is_public = #{isPublic}</if>
            <if test="fileMd5 != null  and fileMd5 != ''">and file_md5 = #{fileMd5}</if>
        </where>
        order by create_time desc
    </select>

    <select id="selectAppFileByFileId" parameterType="Long" resultMap="AppFileResult">
        <include refid="selectAppFileVo"/>
        where file_id = #{fileId}
    </select>

    <insert id="insertAppFile" parameterType="org.dromara.member.domain.AppFile" useGeneratedKeys="true"
            keyProperty="fileId">
        insert into app_file
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="fileName != null and fileName != ''">file_name,</if>
            <if test="originalName != null and originalName != ''">original_name,</if>
            <if test="filePath != null and filePath != ''">file_path,</if>
            <if test="fileUrl != null and fileUrl != ''">file_url,</if>
            <if test="fileSize != null">file_size,</if>
            <if test="fileType != null and fileType != ''">file_type,</if>
            <if test="fileSuffix != null and fileSuffix != ''">file_suffix,</if>
            <if test="fileCategory != null">file_category,</if>
            <if test="storageService != null and storageService != ''">storage_service,</if>
            <if test="status != null and status != ''">status,</if>
            <if test="downloadCount != null">download_count,</if>
            <if test="isPublic != null and isPublic != ''">is_public,</if>
            <if test="fileMd5 != null and fileMd5 != ''">file_md5,</if>
            <if test="remark != null">remark,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="fileName != null and fileName != ''">#{fileName},</if>
            <if test="originalName != null and originalName != ''">#{originalName},</if>
            <if test="filePath != null and filePath != ''">#{filePath},</if>
            <if test="fileUrl != null and fileUrl != ''">#{fileUrl},</if>
            <if test="fileSize != null">#{fileSize},</if>
            <if test="fileType != null and fileType != ''">#{fileType},</if>
            <if test="fileSuffix != null and fileSuffix != ''">#{fileSuffix},</if>
            <if test="fileCategory != null">#{fileCategory},</if>
            <if test="storageService != null and storageService != ''">#{storageService},</if>
            <if test="status != null and status != ''">#{status},</if>
            <if test="downloadCount != null">#{downloadCount},</if>
            <if test="isPublic != null and isPublic != ''">#{isPublic},</if>
            <if test="fileMd5 != null and fileMd5 != ''">#{fileMd5},</if>
            <if test="remark != null">#{remark},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
        </trim>
    </insert>

    <update id="updateAppFile" parameterType="org.dromara.member.domain.AppFile">
        update app_file
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="fileName != null and fileName != ''">file_name = #{fileName},</if>
            <if test="originalName != null and originalName != ''">original_name = #{originalName},</if>
            <if test="filePath != null and filePath != ''">file_path = #{filePath},</if>
            <if test="fileUrl != null and fileUrl != ''">file_url = #{fileUrl},</if>
            <if test="fileSize != null">file_size = #{fileSize},</if>
            <if test="fileType != null and fileType != ''">file_type = #{fileType},</if>
            <if test="fileSuffix != null and fileSuffix != ''">file_suffix = #{fileSuffix},</if>
            <if test="fileCategory != null">file_category = #{fileCategory},</if>
            <if test="storageService != null and storageService != ''">storage_service = #{storageService},</if>
            <if test="status != null and status != ''">status = #{status},</if>
            <if test="downloadCount != null">download_count = #{downloadCount},</if>
            <if test="isPublic != null and isPublic != ''">is_public = #{isPublic},</if>
            <if test="fileMd5 != null and fileMd5 != ''">file_md5 = #{fileMd5},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where file_id = #{fileId}
    </update>

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

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

</mapper>