<?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.zxdmy.excite.system.mapper.cloud.space.CloudFileMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.zxdmy.excite.system.entity.cloud.space.CloudFile">
        <id column="id" property="id" />
        <result column="file_name" property="fileName" />
        <result column="file_size" property="fileSize" />
        <result column="file_format" property="fileFormat" />
        <result column="file_oss" property="fileOss" />
        <result column="file_image" property="fileImage" />
        <result column="file_sort" property="fileSort" />
        <result column="file_folder" property="fileFolder" />
        <result column="file_parent_id" property="fileParentId" />
        <result column="file_top_id" property="fileTopId" />
        <result column="file_folder_path" property="fileFolderPath" />
        <result column="create_time" property="createTime" />
        <result column="creator_id" property="creatorId" />
        <result column="creator_name" property="creatorName" />
        <result column="update_time" property="updateTime" />
        <result column="updater_id" property="updaterId" />
        <result column="updater_name" property="updaterName" />
        <result column="delete_time" property="deleteTime" />
        <result column="delete_id" property="deleteId" />
        <result column="delete_name" property="deleteName" />
        <result column="file_top" property="fileTop" />

    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, file_name, file_size, file_format, file_oss, file_image, file_sort, file_folder, file_parent_id, file_top_id, file_folder_path, create_time, creator_id, creator_name, update_time, updater_id, updater_name, delete_time, delete_id, delete_name,file_top
    </sql>


    <select id="queryByPage" resultType="com.zxdmy.excite.system.entity.vo.space.CloudFileVo" >
        select <include refid="Base_Column_List"/>
        from cloud_file
        <trim prefix="WHERE" prefixOverrides="AND">
            delete_time is null
            <if test="data.fileName != null and data.fileName != ''">
                AND file_name LIKE CONCAT('%' ,#{data.fileName}, '%')
            </if>
            <if test="data.fileTopId != null and data.fileTopId != ''">
                AND file_top_id = #{data.fileTopId}
            </if>
            <if test="data.fileParentId != null and data.fileParentId != ''">
                AND file_parent_id = #{data.fileParentId}
            </if>
            <if test="data.creatorName != null and data.creatorName != ''">
                AND creator_name = #{data.creatorName}
            </if>
            <if test="data.creatorId != null and data.creatorId != ''">
                AND creator_id = #{data.creatorId}
            </if>
            <if test="data.fileFolder != null and data.fileFolder != ''">
                AND file_folder = #{data.fileFolder}
            </if>
            <if test="data.fileTop != null and data.fileTop != ''">
                AND file_top = #{data.fileTop}
            </if>
        </trim>
        ORDER BY file_folder ASC,file_sort desc
        LIMIT #{page},#{size};
    </select>

    <select id="queryByPageCount" resultType="java.lang.Integer">
        select count(*)
        from cloud_file
        <trim prefix="WHERE" prefixOverrides="AND">
            delete_time is null
            <if test="data.fileName != null and data.fileName != ''">
                AND file_name LIKE CONCAT('%' ,#{data.fileName}, '%')
            </if>
            <if test="data.fileTopId != null and data.fileTopId != ''">
                AND file_top_id = #{data.fileTopId}
            </if>
            <if test="data.fileParentId != null and data.fileParentId != ''">
                AND file_parent_id = #{data.fileParentId}
            </if>
            <if test="data.creatorName != null and data.creatorName != ''">
                AND creator_name = #{data.creatorName}
            </if>
            <if test="data.creatorId != null and data.creatorId != ''">
                AND creator_id = #{data.creatorId}
            </if>
            <if test="data.fileFolder != null and data.fileFolder != ''">
                AND file_folder = #{data.fileFolder}
            </if>
        </trim>
    </select>




    <select id="queryByRecyclePage" resultType="com.zxdmy.excite.system.entity.vo.space.CloudFileVo" >
        select <include refid="Base_Column_List"/>
        from cloud_file
        <trim prefix="WHERE" prefixOverrides="AND">
            delete_time is not null
            <if test="data.fileName != null and data.fileName != ''">
                AND file_name LIKE CONCAT('%' ,#{data.fileName}, '%')
            </if>
            <if test="data.fileTopId != null and data.fileTopId != ''">
                AND file_top_id = #{data.fileTopId}
            </if>
            <if test="data.fileParentId != null and data.fileParentId != ''">
                AND file_parent_id = #{data.fileParentId}
            </if>
            <if test="data.creatorName != null and data.creatorName != ''">
                AND creator_name = #{data.creatorName}
            </if>
            <if test="data.creatorId != null and data.creatorId != ''">
                AND creator_id = #{data.creatorId}
            </if>
            <if test="data.fileFolder != null and data.fileFolder != ''">
                AND file_folder = #{data.fileFolder}
            </if>
        </trim>
        LIMIT #{page},#{size};
    </select>

    <select id="queryByRecyclePageCount" resultType="java.lang.Integer">
        select count(*)
        from cloud_file
        <trim prefix="WHERE" prefixOverrides="AND">
            delete_time is null
            <if test="data.fileName != null and data.fileName != ''">
                AND file_name LIKE CONCAT('%' ,#{data.fileName}, '%')
            </if>
            <if test="data.fileTopId != null and data.fileTopId != ''">
                AND file_top_id = #{data.fileTopId}
            </if>
            <if test="data.fileParentId != null and data.fileParentId != ''">
                AND file_parent_id = #{data.fileParentId}
            </if>
            <if test="data.creatorName != null and data.creatorName != ''">
                AND creator_name = #{data.creatorName}
            </if>
            <if test="data.creatorId != null and data.creatorId != ''">
                AND creator_id = #{data.creatorId}
            </if>
            <if test="data.fileFolder != null and data.fileFolder != ''">
                AND file_folder = #{data.fileFolder}
            </if>
        </trim>
    </select>





    <select id="getData" resultType="com.zxdmy.excite.system.entity.vo.space.CloudFileVo" >
        select <include refid="Base_Column_List"/>
        from cloud_file
        <trim prefix="WHERE" prefixOverrides="AND">
            delete_time is null
            <if test="data.fileName != null and data.fileName != ''">
                AND file_name  = #{data.fileName}
            </if>
            <if test="data.fileTopId != null and data.fileTopId != ''">
                AND file_top_id = #{data.fileTopId}
            </if>
            <if test="data.fileParentId != null and data.fileParentId != ''">
                AND file_parent_id = #{data.fileParentId}
            </if>
            <if test="data.creatorName != null and data.creatorName != ''">
                AND creator_name = #{data.creatorName}
            </if>
        </trim>
    </select>





    <select id="queryByIndexPage" resultType="com.zxdmy.excite.system.entity.vo.space.CloudFileVo" >
        select <include refid="Base_Column_List"/>
        from cloud_file
        <trim prefix="WHERE" prefixOverrides="AND">
            delete_time is null AND file_folder = 1 AND file_top = 1
            <if test="data.fileIds != null and data.fileIds != ''">
                AND file_parent_id in
                <foreach collection="data.fileIds" index="index" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
        </trim>
        ORDER BY file_folder ASC,file_sort desc
        LIMIT #{page},#{size};
    </select>

    <select id="queryByIndexPageCount" resultType="java.lang.Integer">
        select count(*)
        from cloud_file
        <trim prefix="WHERE" prefixOverrides="AND">
            delete_time is null AND file_folder = 1
            <if test="data.fileIds != null and data.fileIds != ''">
                AND file_parent_id in
                <foreach collection="data.fileIds" index="index" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
        </trim>
    </select>

    <select id="queryFileByData" resultType="com.zxdmy.excite.system.entity.vo.space.CloudFileVo" >
        select
        id, file_name as title, file_size, file_format, file_oss, file_image, file_sort, file_folder, file_parent_id, file_top_id, file_folder_path,
        create_time, creator_id, creator_name, update_time, updater_id, updater_name, delete_time, delete_id, delete_name,file_top
        from cloud_file
        <trim prefix="WHERE" prefixOverrides="AND">
            delete_time is null AND file_folder = 0
            <if test="data.fileIds != null and data.fileIds != ''">

            </if>
        </trim>
    </select>

</mapper>
