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 }} - - - - + 添加关键词 - - - +