<?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.auth.dao.base.mapper.v1.FileMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.auth.dao.base.entity.FileEntity">
        <id column="id" property="id"/>
        <id column="file_uid" property="fileUid"/>
        <id column="original_name" property="originalName"/>
        <id column="storage_name" property="storageName"/>
        <id column="file_path" property="filePath"/>
        <id column="full_url" property="fullUrl"/>
        <id column="file_size" property="fileSize"/>
        <id column="file_type" property="fileType"/>
        <id column="file_extension" property="fileExtension"/>
        <id column="file_hash" property="fileHash"/>
        <id column="download_count" property="downloadCount"/>
        <id column="storage_type" property="storageType"/>
        <id column="file_status" property="fileStatus"/>
        <id column="business_type" property="businessType"/>
        <id column="business_id" property="businessId"/>
        <id column="is_deleted" property="isDeleted"/>
        <id column="create_time" property="createTime"/>
        <id column="update_time" property="updateTime"/>
        <id column="create_user" property="createUser"/>
        <id column="update_user" property="updateUser"/>
        <id column="is_deleted" property="isDeleted"/>
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id,
        file_uid,original_name,storage_name,file_path,full_url,file_size,file_type,file_extension,file_hash,download_count,storage_type,file_status,business_type,business_id,is_deleted,
        create_time, update_time, create_user, update_user, is_deleted
    </sql>

    <!-- 分页查询系统文件存储内容 -->
    <select id="selectListByPage" resultType="com.auth.model.base.vo.FileVo">
        select
        base.*,
        create_user.username as create_username,
        update_user.username as update_username
        from sys_file base
        left join sys_user create_user on create_user.id = base.create_user
        left join sys_user update_user on update_user.id = base.update_user
        <where>
            base.is_deleted = 0
            <if test="dto.fileUid != null and dto.fileUid != ''">
                and base.file_uid like CONCAT('%',#{dto.fileUid},'%')
            </if>
            <if test="dto.originalName != null and dto.originalName != ''">
                and base.original_name like CONCAT('%',#{dto.originalName},'%')
            </if>
            <if test="dto.storageName != null and dto.storageName != ''">
                and base.storage_name like CONCAT('%',#{dto.storageName},'%')
            </if>
            <if test="dto.filePath != null and dto.filePath != ''">
                and base.file_path like CONCAT('%',#{dto.filePath},'%')
            </if>
            <if test="dto.fullUrl != null and dto.fullUrl != ''">
                and base.full_url like CONCAT('%',#{dto.fullUrl},'%')
            </if>
            <if test="dto.fileSize != null and dto.fileSize != ''">
                and base.file_size like CONCAT('%',#{dto.fileSize},'%')
            </if>
            <if test="dto.fileType != null and dto.fileType != ''">
                and base.file_type like CONCAT('%',#{dto.fileType},'%')
            </if>
            <if test="dto.fileExtension != null and dto.fileExtension != ''">
                and base.file_extension like CONCAT('%',#{dto.fileExtension},'%')
            </if>
            <if test="dto.fileHash != null and dto.fileHash != ''">
                and base.file_hash like CONCAT('%',#{dto.fileHash},'%')
            </if>
            <if test="dto.downloadCount != null and dto.downloadCount != ''">
                and base.download_count like CONCAT('%',#{dto.downloadCount},'%')
            </if>
            <if test="dto.storageType != null and dto.storageType != ''">
                and base.storage_type like CONCAT('%',#{dto.storageType},'%')
            </if>
            <if test="dto.fileStatus != null and dto.fileStatus != ''">
                and base.file_status like CONCAT('%',#{dto.fileStatus},'%')
            </if>
            <if test="dto.businessType != null and dto.businessType != ''">
                and base.business_type like CONCAT('%',#{dto.businessType},'%')
            </if>
            <if test="dto.businessId != null and dto.businessId != ''">
                and base.business_id like CONCAT('%',#{dto.businessId},'%')
            </if>
            <if test="dto.isDeleted != null and dto.isDeleted != ''">
                and base.is_deleted like CONCAT('%',#{dto.isDeleted},'%')
            </if>
        </where>
    </select>

</mapper>
