分段数量同步
This commit is contained in:
@@ -159,9 +159,14 @@ public class DifyProxyController {
|
|||||||
// 调用Dify API(使用默认配置的API Key)
|
// 调用Dify API(使用默认配置的API Key)
|
||||||
String path = "/datasets/" + datasetId + "/documents/" + documentId + "/segments";
|
String path = "/datasets/" + datasetId + "/documents/" + documentId + "/segments";
|
||||||
String response = difyApiClient.post(path, requestBody, null);
|
String response = difyApiClient.post(path, requestBody, null);
|
||||||
|
int i = uploadFileMapper.chunkSync(documentId, 1);
|
||||||
|
if (i>0) {
|
||||||
result.success("创建分段成功", response);
|
result.success("创建分段成功", response);
|
||||||
return result;
|
return result;
|
||||||
|
} else {
|
||||||
|
result.fail("创建分段失败: 分段同步失败");
|
||||||
|
return result;
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("创建分段失败", e);
|
log.error("创建分段失败", e);
|
||||||
result.fail("创建分段失败: " + e.getMessage());
|
result.fail("创建分段失败: " + e.getMessage());
|
||||||
@@ -193,9 +198,14 @@ public class DifyProxyController {
|
|||||||
String path = "/datasets/" + datasetId + "/documents/" + documentId +
|
String path = "/datasets/" + datasetId + "/documents/" + documentId +
|
||||||
"/segments/" + segmentId;
|
"/segments/" + segmentId;
|
||||||
String response = difyApiClient.delete(path, null);
|
String response = difyApiClient.delete(path, null);
|
||||||
|
int i = uploadFileMapper.chunkSync(documentId, -1);
|
||||||
|
if (i>0) {
|
||||||
result.success("删除分段成功", response);
|
result.success("删除分段成功", response);
|
||||||
return result;
|
return result;
|
||||||
|
} else {
|
||||||
|
result.fail("删除分段失败: 分段同步失败");
|
||||||
|
return result;
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("删除分段失败", e);
|
log.error("删除分段失败", e);
|
||||||
result.fail("删除分段失败: " + e.getMessage());
|
result.fail("删除分段失败: " + e.getMessage());
|
||||||
|
|||||||
@@ -89,4 +89,12 @@ public interface AiUploadFileMapper extends BaseMapper<TbAiUploadFile> {
|
|||||||
* @return TbAiUploadFile 文件记录
|
* @return TbAiUploadFile 文件记录
|
||||||
*/
|
*/
|
||||||
TbAiUploadFile selectFileByDifyDocumentId(@Param("difyDocumentId") String difyDocumentId);
|
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>
|
</foreach>
|
||||||
</insert>
|
</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>
|
</mapper>
|
||||||
|
|||||||
@@ -179,33 +179,6 @@
|
|||||||
placeholder="请输入分段内容"
|
placeholder="请输入分段内容"
|
||||||
/>
|
/>
|
||||||
</el-form-item>
|
</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>
|
</el-form>
|
||||||
<template #footer>
|
<template #footer>
|
||||||
<el-button @click="showAddSegmentDialog = false">取消</el-button>
|
<el-button @click="showAddSegmentDialog = false">取消</el-button>
|
||||||
@@ -455,8 +428,7 @@ async function handleCreateSegment() {
|
|||||||
props.datasetId,
|
props.datasetId,
|
||||||
props.documentId,
|
props.documentId,
|
||||||
[{
|
[{
|
||||||
content,
|
content
|
||||||
keywords: newSegmentForm.value.keywords.length > 0 ? newSegmentForm.value.keywords : undefined
|
|
||||||
}]
|
}]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -137,7 +137,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</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">
|
<el-table-column prop="createTime" label="上传时间" width="180">
|
||||||
<template #default="{ row }">
|
<template #default="{ row }">
|
||||||
{{ formatDate(row.createTime) }}
|
{{ formatDate(row.createTime) }}
|
||||||
|
|||||||
Reference in New Issue
Block a user