分段数量同步
This commit is contained in:
@@ -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());
|
||||
|
||||
@@ -89,4 +89,12 @@ public interface AiUploadFileMapper extends BaseMapper<TbAiUploadFile> {
|
||||
* @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);
|
||||
}
|
||||
|
||||
@@ -224,4 +224,12 @@
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
<!-- chunkSync -->
|
||||
|
||||
<update id="chunkSync">
|
||||
UPDATE tb_ai_upload_file
|
||||
SET chunk_count = chunk_count + #{action}
|
||||
WHERE dify_document_id = #{difyDocumentId}
|
||||
AND deleted = 0
|
||||
</update>
|
||||
</mapper>
|
||||
|
||||
@@ -179,33 +179,6 @@
|
||||
placeholder="请输入分段内容"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="关键词">
|
||||
<el-tag
|
||||
v-for="keyword in newSegmentForm.keywords"
|
||||
:key="keyword"
|
||||
closable
|
||||
@close="removeKeyword(keyword)"
|
||||
style="margin-right: 8px;"
|
||||
>
|
||||
{{ keyword }}
|
||||
</el-tag>
|
||||
<el-input
|
||||
v-if="keywordInputVisible"
|
||||
ref="keywordInputRef"
|
||||
v-model="keywordInputValue"
|
||||
size="small"
|
||||
style="width: 120px;"
|
||||
@keyup.enter="handleKeywordInputConfirm"
|
||||
@blur="handleKeywordInputConfirm"
|
||||
/>
|
||||
<el-button
|
||||
v-else
|
||||
size="small"
|
||||
@click="showKeywordInput"
|
||||
>
|
||||
+ 添加关键词
|
||||
</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="showAddSegmentDialog = false">取消</el-button>
|
||||
@@ -455,9 +428,8 @@ async function handleCreateSegment() {
|
||||
props.datasetId,
|
||||
props.documentId,
|
||||
[{
|
||||
content,
|
||||
keywords: newSegmentForm.value.keywords.length > 0 ? newSegmentForm.value.keywords : undefined
|
||||
}]
|
||||
content
|
||||
}]
|
||||
);
|
||||
|
||||
if (result.success) {
|
||||
|
||||
@@ -137,7 +137,7 @@
|
||||
</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="chunkCount" label="字数" width="100" />
|
||||
<el-table-column prop="chunkCount" label="分段数" width="100" />
|
||||
<el-table-column prop="createTime" label="上传时间" width="180">
|
||||
<template #default="{ row }">
|
||||
{{ formatDate(row.createTime) }}
|
||||
|
||||
Reference in New Issue
Block a user