From 7edc4f3a354e2f3df2be9a525cf2d32c1b536da3 Mon Sep 17 00:00:00 2001 From: wangys <3401275564@qq.com> Date: Fri, 7 Nov 2025 15:26:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E6=AE=B5=E6=95=B0=E9=87=8F=E5=90=8C?= =?UTF-8?q?=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ai/controller/DifyProxyController.java | 22 +++++++++---- .../xyzh/ai/mapper/AiUploadFileMapper.java | 8 +++++ .../resources/mapper/AiUploadFileMapper.xml | 8 +++++ .../ai/components/DocumentSegmentDialog.vue | 32 ++----------------- .../manage/ai/components/KnowledgeInfo.vue | 2 +- 5 files changed, 35 insertions(+), 37 deletions(-) diff --git a/schoolNewsServ/ai/src/main/java/org/xyzh/ai/controller/DifyProxyController.java b/schoolNewsServ/ai/src/main/java/org/xyzh/ai/controller/DifyProxyController.java index 31d4eaa..0162279 100644 --- a/schoolNewsServ/ai/src/main/java/org/xyzh/ai/controller/DifyProxyController.java +++ b/schoolNewsServ/ai/src/main/java/org/xyzh/ai/controller/DifyProxyController.java @@ -159,9 +159,14 @@ public class DifyProxyController { // 调用Dify API(使用默认配置的API Key) String path = "/datasets/" + datasetId + "/documents/" + documentId + "/segments"; String response = difyApiClient.post(path, requestBody, null); - - result.success("创建分段成功", response); - return result; + int i = uploadFileMapper.chunkSync(documentId, 1); + if (i>0) { + result.success("创建分段成功", response); + return result; + } else { + result.fail("创建分段失败: 分段同步失败"); + return result; + } } catch (Exception e) { log.error("创建分段失败", e); result.fail("创建分段失败: " + e.getMessage()); @@ -193,9 +198,14 @@ public class DifyProxyController { String path = "/datasets/" + datasetId + "/documents/" + documentId + "/segments/" + segmentId; String response = difyApiClient.delete(path, null); - - result.success("删除分段成功", response); - return result; + int i = uploadFileMapper.chunkSync(documentId, -1); + if (i>0) { + result.success("删除分段成功", response); + return result; + } else { + result.fail("删除分段失败: 分段同步失败"); + return result; + } } catch (Exception e) { log.error("删除分段失败", e); result.fail("删除分段失败: " + e.getMessage()); diff --git a/schoolNewsServ/ai/src/main/java/org/xyzh/ai/mapper/AiUploadFileMapper.java b/schoolNewsServ/ai/src/main/java/org/xyzh/ai/mapper/AiUploadFileMapper.java index c76731b..8593222 100644 --- a/schoolNewsServ/ai/src/main/java/org/xyzh/ai/mapper/AiUploadFileMapper.java +++ b/schoolNewsServ/ai/src/main/java/org/xyzh/ai/mapper/AiUploadFileMapper.java @@ -89,4 +89,12 @@ public interface AiUploadFileMapper extends BaseMapper { * @return TbAiUploadFile 文件记录 */ TbAiUploadFile selectFileByDifyDocumentId(@Param("difyDocumentId") String difyDocumentId); + + /** + * 同步分段 + * @param difyDocumentId Dify文档ID + * @param action 操作类型: 1-创建, -1-删除 + * @return 影响行数 + */ + int chunkSync(@Param("difyDocumentId") String difyDocumentId, @Param("action") int action); } diff --git a/schoolNewsServ/ai/src/main/resources/mapper/AiUploadFileMapper.xml b/schoolNewsServ/ai/src/main/resources/mapper/AiUploadFileMapper.xml index b7bc23f..2b2d225 100644 --- a/schoolNewsServ/ai/src/main/resources/mapper/AiUploadFileMapper.xml +++ b/schoolNewsServ/ai/src/main/resources/mapper/AiUploadFileMapper.xml @@ -224,4 +224,12 @@ + + + + UPDATE tb_ai_upload_file + SET chunk_count = chunk_count + #{action} + WHERE dify_document_id = #{difyDocumentId} + AND deleted = 0 + diff --git a/schoolNewsWeb/src/views/admin/manage/ai/components/DocumentSegmentDialog.vue b/schoolNewsWeb/src/views/admin/manage/ai/components/DocumentSegmentDialog.vue index 576570a..6671c11 100644 --- a/schoolNewsWeb/src/views/admin/manage/ai/components/DocumentSegmentDialog.vue +++ b/schoolNewsWeb/src/views/admin/manage/ai/components/DocumentSegmentDialog.vue @@ -179,33 +179,6 @@ placeholder="请输入分段内容" /> - - - {{ keyword }} - - - - + 添加关键词 - - - +