<?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.xyzh.system.mapper.SysFileMapper">

    <!-- 基础结果映射 -->
    <resultMap id="BaseResultMap" type="org.xyzh.common.dto.system.TbSysFile">
        <id column="id" property="id" jdbcType="VARCHAR"/>
        <result column="file_name" property="fileName" jdbcType="VARCHAR"/>
        <result column="original_name" property="originalName" jdbcType="VARCHAR"/>
        <result column="file_path" property="filePath" jdbcType="VARCHAR"/>
        <result column="file_url" property="fileUrl" jdbcType="VARCHAR"/>
        <result column="file_size" property="fileSize" jdbcType="BIGINT"/>
        <result column="file_type" property="fileType" jdbcType="VARCHAR"/>
        <result column="mime_type" property="mimeType" jdbcType="VARCHAR"/>
        <result column="module" property="module" jdbcType="VARCHAR"/>
        <result column="business_id" property="businessID" jdbcType="VARCHAR"/>
        <result column="uploader" property="uploader" jdbcType="VARCHAR"/>
        <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
    </resultMap>

    <!-- 基础字段 -->
    <sql id="Base_Column_List">
        id, file_name, original_name, file_path, file_url, file_size, 
        file_type, mime_type, module, business_id, uploader, create_time
    </sql>

    <!-- 通用条件 -->
    <sql id="Where_Clause">
        <where>
            <if test="fileName != null and fileName != ''">
                AND file_name LIKE CONCAT('%', #{fileName}, '%')
            </if>
            <if test="fileType != null and fileType != ''">
                AND file_type = #{fileType}
            </if>
            <if test="module != null and module != ''">
                AND module = #{module}
            </if>
            <if test="businessID != null and businessID != ''">
                AND business_id = #{businessID}
            </if>
            <if test="uploader != null and uploader != ''">
                AND uploader = #{uploader}
            </if>
        </where>
    </sql>

    <!-- selectSysFiles -->
    <select id="selectSysFiles" resultMap="BaseResultMap">
        SELECT 
        <include refid="Base_Column_List"/>
        FROM tb_sys_file
        <include refid="Where_Clause"/>
        ORDER BY create_time DESC
    </select>

</mapper>
