<?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.gxwebsoft.ai.mapper.AiCloudFileMapper">

    <!-- 关联查询sql -->
    <sql id="selectSql">
        SELECT a.*
        FROM ai_cloud_file a
        <where>
            <if test="param.id != null">
                AND a.id = #{param.id}
            </if>
            <if test="param.docId != null">
                AND a.doc_id = #{param.docId}
            </if>
            <if test="param.fileName != null and param.fileName != ''">
                AND a.file_name LIKE CONCAT('%', #{param.fileName}, '%')
            </if>
            <if test="param.fileSize != null">
                AND a.file_size = #{param.fileSize}
            </if>
            <if test="param.fileType != null and param.fileType != ''">
                AND a.file_type = #{param.fileType}
            </if>
            <if test="param.workspaceId != null">
                AND a.workspace_id = #{param.workspaceId}
            </if>
            <if test="param.fileId != null and param.fileId != ''">
                AND a.file_id = #{param.fileId}
            </if>
            <if test="param.fileExt != null and param.fileExt != ''">
                AND a.file_ext = #{param.fileExt}
            </if>
            <if test="param.uploadTimeStart != null">
                AND a.upload_time &gt;= #{param.uploadTimeStart}
            </if>
            <if test="param.uploadTimeEnd != null">
                AND a.upload_time &lt;= #{param.uploadTimeEnd}
            </if>
            <if test="param.sortNumber != null">
                AND a.sort_number = #{param.sortNumber}
            </if>
            <if test="param.status != null">
                AND a.status = #{param.status}
            </if>
            <if test="param.deleted != null">
                AND a.deleted = #{param.deleted}
            </if>
            <if test="param.deleted == null">
                AND a.deleted = 0
            </if>
            <if test="param.userId != null">
                AND a.user_id = #{param.userId}
            </if>
            <if test="param.keywords != null and param.keywords != ''">
                AND (a.file_name LIKE CONCAT('%', #{param.keywords}, '%')
                OR a.file_type LIKE CONCAT('%', #{param.keywords}, '%')
                OR a.file_ext LIKE CONCAT('%', #{param.keywords}, '%'))
            </if>
        </where>
    </sql>

    <!-- 分页查询 -->
    <select id="selectPageRel" resultType="com.gxwebsoft.ai.entity.AiCloudFile">
        <include refid="selectSql"></include>
    </select>

    <!-- 查询全部 -->
    <select id="selectListRel" resultType="com.gxwebsoft.ai.entity.AiCloudFile">
        <include refid="selectSql"></include>
    </select>

</mapper>