2025-10-15 13:11:19 +08:00
|
|
|
|
<?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.ai.mapper.AiUploadFileMapper">
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 基础结果映射 -->
|
|
|
|
|
|
<resultMap id="BaseResultMap" type="org.xyzh.common.dto.ai.TbAiUploadFile">
|
|
|
|
|
|
<id column="id" property="id" jdbcType="VARCHAR"/>
|
|
|
|
|
|
<result column="user_id" property="userID" jdbcType="VARCHAR"/>
|
2025-11-04 18:49:37 +08:00
|
|
|
|
<result column="knowledge_id" property="knowledgeId" jdbcType="VARCHAR"/>
|
2025-10-15 13:11:19 +08:00
|
|
|
|
<result column="conversation_id" property="conversationID" jdbcType="VARCHAR"/>
|
|
|
|
|
|
<result column="file_name" property="fileName" jdbcType="VARCHAR"/>
|
|
|
|
|
|
<result column="file_path" property="filePath" 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="extracted_text" property="extractedText" jdbcType="LONGVARCHAR"/>
|
2025-11-04 18:49:37 +08:00
|
|
|
|
<result column="dify_document_id" property="difyDocumentId" jdbcType="VARCHAR"/>
|
|
|
|
|
|
<result column="dify_batch_id" property="difyBatchId" jdbcType="VARCHAR"/>
|
|
|
|
|
|
<result column="vector_status" property="vectorStatus" jdbcType="INTEGER"/>
|
|
|
|
|
|
<result column="chunk_count" property="chunkCount" jdbcType="INTEGER"/>
|
2025-10-15 13:11:19 +08:00
|
|
|
|
<result column="status" property="status" jdbcType="INTEGER"/>
|
2025-11-04 18:49:37 +08:00
|
|
|
|
<result column="error_message" property="errorMessage" jdbcType="VARCHAR"/>
|
|
|
|
|
|
<result column="creator" property="creator" jdbcType="VARCHAR"/>
|
|
|
|
|
|
<result column="updater" property="updater" jdbcType="VARCHAR"/>
|
2025-10-15 13:11:19 +08:00
|
|
|
|
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
|
|
|
|
|
|
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
|
2025-11-04 18:49:37 +08:00
|
|
|
|
<result column="delete_time" property="deleteTime" jdbcType="TIMESTAMP"/>
|
|
|
|
|
|
<result column="deleted" property="deleted" jdbcType="BOOLEAN"/>
|
2025-10-15 13:11:19 +08:00
|
|
|
|
</resultMap>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 基础字段 -->
|
|
|
|
|
|
<sql id="Base_Column_List">
|
2025-11-04 18:49:37 +08:00
|
|
|
|
id, user_id, knowledge_id, conversation_id, file_name, file_path, file_size,
|
|
|
|
|
|
file_type, mime_type, extracted_text, dify_document_id, dify_batch_id,
|
|
|
|
|
|
vector_status, chunk_count, status, error_message, creator, updater,
|
|
|
|
|
|
create_time, update_time, delete_time, deleted
|
2025-10-15 13:11:19 +08:00
|
|
|
|
</sql>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 通用条件 -->
|
2025-11-04 18:49:37 +08:00
|
|
|
|
<sql id="Filter_Clause">
|
2025-10-15 13:11:19 +08:00
|
|
|
|
<where>
|
2025-11-04 18:49:37 +08:00
|
|
|
|
deleted = 0
|
|
|
|
|
|
<if test="filter != null">
|
|
|
|
|
|
<if test="filter.userID != null and filter.userID != ''">
|
|
|
|
|
|
AND user_id = #{filter.userID}
|
|
|
|
|
|
</if>
|
|
|
|
|
|
<if test="filter.knowledgeId != null and filter.knowledgeId != ''">
|
|
|
|
|
|
AND knowledge_id = #{filter.knowledgeId}
|
|
|
|
|
|
</if>
|
|
|
|
|
|
<if test="filter.conversationID != null and filter.conversationID != ''">
|
|
|
|
|
|
AND conversation_id = #{filter.conversationID}
|
|
|
|
|
|
</if>
|
|
|
|
|
|
<if test="filter.fileName != null and filter.fileName != ''">
|
|
|
|
|
|
AND file_name LIKE CONCAT('%', #{filter.fileName}, '%')
|
|
|
|
|
|
</if>
|
|
|
|
|
|
<if test="filter.fileType != null and filter.fileType != ''">
|
|
|
|
|
|
AND file_type = #{filter.fileType}
|
|
|
|
|
|
</if>
|
|
|
|
|
|
<if test="filter.vectorStatus != null">
|
|
|
|
|
|
AND vector_status = #{filter.vectorStatus}
|
|
|
|
|
|
</if>
|
|
|
|
|
|
<if test="filter.status != null">
|
|
|
|
|
|
AND status = #{filter.status}
|
|
|
|
|
|
</if>
|
2025-10-15 13:11:19 +08:00
|
|
|
|
</if>
|
|
|
|
|
|
</where>
|
|
|
|
|
|
</sql>
|
|
|
|
|
|
|
2025-11-04 18:49:37 +08:00
|
|
|
|
<!-- insertUploadFile(插入文件记录) -->
|
|
|
|
|
|
<insert id="insertUploadFile" parameterType="org.xyzh.common.dto.ai.TbAiUploadFile">
|
|
|
|
|
|
INSERT INTO tb_ai_upload_file (
|
|
|
|
|
|
id, user_id, knowledge_id, conversation_id, file_name, file_path, file_size,
|
|
|
|
|
|
file_type, mime_type, extracted_text, dify_document_id, dify_batch_id,
|
|
|
|
|
|
vector_status, chunk_count, status, error_message, creator, updater,
|
|
|
|
|
|
create_time, update_time, deleted
|
|
|
|
|
|
) VALUES (
|
|
|
|
|
|
#{ID}, #{userID}, #{knowledgeId}, #{conversationID}, #{fileName}, #{filePath}, #{fileSize},
|
|
|
|
|
|
#{fileType}, #{mimeType}, #{extractedText}, #{difyDocumentId}, #{difyBatchId},
|
|
|
|
|
|
#{vectorStatus}, #{chunkCount}, #{status}, #{errorMessage}, #{creator}, #{updater},
|
|
|
|
|
|
#{createTime}, #{updateTime}, #{deleted}
|
|
|
|
|
|
)
|
|
|
|
|
|
</insert>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- updateUploadFile(更新文件记录) -->
|
|
|
|
|
|
<update id="updateUploadFile" parameterType="org.xyzh.common.dto.ai.TbAiUploadFile">
|
|
|
|
|
|
UPDATE tb_ai_upload_file
|
|
|
|
|
|
<set>
|
|
|
|
|
|
<if test="userID != null">user_id = #{userID},</if>
|
|
|
|
|
|
<if test="knowledgeId != null">knowledge_id = #{knowledgeId},</if>
|
|
|
|
|
|
<if test="conversationID != null">conversation_id = #{conversationID},</if>
|
|
|
|
|
|
<if test="fileName != null">file_name = #{fileName},</if>
|
|
|
|
|
|
<if test="filePath != null">file_path = #{filePath},</if>
|
|
|
|
|
|
<if test="fileSize != null">file_size = #{fileSize},</if>
|
|
|
|
|
|
<if test="fileType != null">file_type = #{fileType},</if>
|
|
|
|
|
|
<if test="mimeType != null">mime_type = #{mimeType},</if>
|
|
|
|
|
|
<if test="extractedText != null">extracted_text = #{extractedText},</if>
|
|
|
|
|
|
<if test="difyDocumentId != null">dify_document_id = #{difyDocumentId},</if>
|
|
|
|
|
|
<if test="difyBatchId != null">dify_batch_id = #{difyBatchId},</if>
|
|
|
|
|
|
<if test="vectorStatus != null">vector_status = #{vectorStatus},</if>
|
|
|
|
|
|
<if test="chunkCount != null">chunk_count = #{chunkCount},</if>
|
|
|
|
|
|
<if test="status != null">status = #{status},</if>
|
|
|
|
|
|
<if test="errorMessage != null">error_message = #{errorMessage},</if>
|
|
|
|
|
|
<if test="updater != null">updater = #{updater},</if>
|
|
|
|
|
|
<if test="updateTime != null">update_time = #{updateTime},</if>
|
|
|
|
|
|
</set>
|
|
|
|
|
|
WHERE id = #{ID} AND deleted = 0
|
|
|
|
|
|
</update>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- deleteUploadFile(逻辑删除文件记录) -->
|
|
|
|
|
|
<update id="deleteUploadFile" parameterType="org.xyzh.common.dto.ai.TbAiUploadFile">
|
|
|
|
|
|
UPDATE tb_ai_upload_file
|
|
|
|
|
|
SET deleted = 1,
|
|
|
|
|
|
delete_time = NOW(),
|
|
|
|
|
|
updater = #{updater}
|
|
|
|
|
|
WHERE id = #{ID} AND deleted = 0
|
|
|
|
|
|
</update>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- selectUploadFileById(根据ID查询文件) -->
|
|
|
|
|
|
<select id="selectUploadFileById" resultMap="BaseResultMap">
|
|
|
|
|
|
SELECT
|
|
|
|
|
|
<include refid="Base_Column_List"/>
|
|
|
|
|
|
FROM tb_ai_upload_file
|
|
|
|
|
|
WHERE id = #{fileId} AND deleted = 0
|
|
|
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- selectAllUploadFiles(查询所有文件) -->
|
|
|
|
|
|
<select id="selectAllUploadFiles" resultMap="BaseResultMap">
|
|
|
|
|
|
SELECT
|
|
|
|
|
|
<include refid="Base_Column_List"/>
|
|
|
|
|
|
FROM tb_ai_upload_file
|
|
|
|
|
|
<include refid="Filter_Clause"/>
|
|
|
|
|
|
ORDER BY create_time DESC
|
|
|
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- selectFilesByKnowledgeId(根据知识库ID查询文件列表) -->
|
|
|
|
|
|
<select id="selectFilesByKnowledgeId" resultMap="BaseResultMap">
|
|
|
|
|
|
SELECT
|
|
|
|
|
|
<include refid="Base_Column_List"/>
|
|
|
|
|
|
FROM tb_ai_upload_file
|
|
|
|
|
|
WHERE knowledge_id = #{knowledgeId}
|
|
|
|
|
|
AND deleted = 0
|
|
|
|
|
|
ORDER BY create_time DESC
|
|
|
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- selectUploadFilesPage(分页查询文件) -->
|
|
|
|
|
|
<select id="selectUploadFilesPage" resultMap="BaseResultMap">
|
|
|
|
|
|
SELECT
|
|
|
|
|
|
<include refid="Base_Column_List"/>
|
|
|
|
|
|
FROM tb_ai_upload_file
|
|
|
|
|
|
<include refid="Filter_Clause"/>
|
|
|
|
|
|
ORDER BY create_time DESC
|
|
|
|
|
|
LIMIT #{pageParam.offset}, #{pageParam.pageSize}
|
|
|
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- countUploadFiles(统计文件总数) -->
|
|
|
|
|
|
<select id="countUploadFiles" resultType="java.lang.Long">
|
|
|
|
|
|
SELECT COUNT(1)
|
|
|
|
|
|
FROM tb_ai_upload_file
|
|
|
|
|
|
<include refid="Filter_Clause"/>
|
|
|
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- selectAiUploadFiles(原有方法保留兼容性) -->
|
2025-10-15 13:11:19 +08:00
|
|
|
|
<select id="selectAiUploadFiles" resultMap="BaseResultMap">
|
|
|
|
|
|
SELECT
|
|
|
|
|
|
<include refid="Base_Column_List"/>
|
|
|
|
|
|
FROM tb_ai_upload_file
|
2025-11-04 18:49:37 +08:00
|
|
|
|
WHERE deleted = 0
|
|
|
|
|
|
<if test="userID != null and userID != ''">
|
|
|
|
|
|
AND user_id = #{userID}
|
|
|
|
|
|
</if>
|
|
|
|
|
|
<if test="knowledgeId != null and knowledgeId != ''">
|
|
|
|
|
|
AND knowledge_id = #{knowledgeId}
|
|
|
|
|
|
</if>
|
|
|
|
|
|
<if test="conversationID != null and conversationID != ''">
|
|
|
|
|
|
AND conversation_id = #{conversationID}
|
|
|
|
|
|
</if>
|
|
|
|
|
|
<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="status != null">
|
|
|
|
|
|
AND status = #{status}
|
|
|
|
|
|
</if>
|
2025-10-15 13:11:19 +08:00
|
|
|
|
ORDER BY create_time DESC
|
|
|
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
|
|
</mapper>
|