<?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="cn.stylefeng.roses.kernel.file.modular.mapper.SysFileInfoMapper">

    <!--文件列表sql-->
    <sql id="file_list_mysql">
        SELECT fileinfo.file_id        AS fileId,
            fileinfo.file_code         AS fileCode,
            fileinfo.secret_flag       AS secretFlag,
            fileinfo.file_bucket       AS fileBucket,
            fileinfo.file_object_name  AS fileObjectName,
            fileinfo.file_location     AS fileLocation,
            fileinfo.file_origin_name  AS fileOriginName,
            fileinfo.file_suffix       AS fileSuffix,
            fileinfo.file_size_info    AS fileSizeInfo,
            fileinfo.file_version      AS fileVersion,
            suser.real_name            AS createUserName,
            fileinfo.create_time       AS createTime,
            fileinfo.del_flag          AS delFlag
        FROM sys_file_info fileinfo
        LEFT JOIN sys_user suser ON suser.user_id = fileinfo.create_user
        <where>
            <if test="sysFileInfoRequest.fileOriginName != null and sysFileInfoRequest.fileOriginName != '' ">
                AND fileinfo.file_origin_name LIKE CONCAT('%', #{sysFileInfoRequest.fileOriginName}, '%')
            </if>
            <if test="sysFileInfoRequest.fileLocation != null and sysFileInfoRequest.fileLocation != '' ">
                AND fileinfo.file_location = #{sysFileInfoRequest.fileLocation}
            </if>
        </where>
    </sql>

    <!--文件列表sql oracle版本-->
    <sql id="file_list_oracle">
        SELECT fileinfo.file_id        AS fileId,
            fileinfo.file_code         AS fileCode,
            fileinfo.secret_flag       AS secretFlag,
            fileinfo.file_bucket       AS fileBucket,
            fileinfo.file_object_name  AS fileObjectName,
            fileinfo.file_location     AS fileLocation,
            fileinfo.file_origin_name  AS fileOriginName,
            fileinfo.file_suffix       AS fileSuffix,
            fileinfo.file_size_info    AS fileSizeInfo,
            fileinfo.file_version      AS fileVersion,
            suser.real_name            AS createUserName,
            fileinfo.create_time       AS createTime,
            fileinfo.del_flag          AS delFlag
        FROM sys_file_info fileinfo
        LEFT JOIN sys_user suser ON suser.user_id = fileinfo.create_user
        <where>
            <if test="sysFileInfoRequest.fileOriginName != null and sysFileInfoRequest.fileOriginName != '' ">
                AND fileinfo.file_origin_name like '%' || #{sysFileInfoRequest.fileOriginName} || '%'
            </if>
            <if test="sysFileInfoRequest.fileLocation != null and sysFileInfoRequest.fileLocation != '' ">
                AND fileinfo.file_location = #{sysFileInfoRequest.fileLocation}
            </if>
        </where>
    </sql>

    <!--  附件列表 mysql版本、pgsql、sqlserver -->
    <select id="fileInfoList" resultType="cn.stylefeng.roses.kernel.file.api.pojo.response.SysFileInfoListResponse">
        <include refid="file_list_mysql"></include>
    </select>

    <!--  附件列表 oracle -->
    <select id="fileInfoList" resultType="cn.stylefeng.roses.kernel.file.api.pojo.response.SysFileInfoListResponse" databaseId="oracle">
        <include refid="file_list_oracle"></include>
    </select>

</mapper>
