From 68555fdfb656b379952ecdbc1c9d66409251c83e Mon Sep 17 00:00:00 2001
From: moon <2623532423@qq.com>
Date: Mon, 22 Sep 2025 10:10:41 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=B4=A2=E5=BC=95=E6=9E=84?=
=?UTF-8?q?=E5=BB=BA=E5=8A=9F=E8=83=BD=EF=BC=8C=E4=BF=AE=E6=94=B9=E4=BA=9B?=
=?UTF-8?q?=E8=AE=B8bug?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
chat-client/src/api/dataset.ts | 19 ++++++-
.../views/permission/esindexManage/index.vue | 39 ++++++++++---
.../controller/KnowledgeBaseController.java | 30 ++++++++--
.../brichat/entity/dto/RetrievalDto.java | 1 +
.../brichat/entity/esmodel/IndexInfo.java | 1 +
.../mapper/opengauss/TDatasetFilesMapper.java | 5 ++
.../brichat/service/DatasetFilesService.java | 17 +++++-
.../service/EsTDatasetFilesService.java | 2 +
.../service/impl/DatasetFilesServiceImpl.java | 40 ++++++++++++-
.../impl/EsTDatasetFilesServiceImpl.java | 56 ++++++++++++++++++-
.../brichat/util/EsTDatasetFilesImporter.java | 12 ++--
.../mapper/opengauss/TDatasetFilesMapper.xml | 20 ++++++-
12 files changed, 218 insertions(+), 24 deletions(-)
diff --git a/chat-client/src/api/dataset.ts b/chat-client/src/api/dataset.ts
index 98657c6..1579c9e 100644
--- a/chat-client/src/api/dataset.ts
+++ b/chat-client/src/api/dataset.ts
@@ -253,4 +253,21 @@ export function createAllIndex() {
fileName
}
})
- }
\ No newline at end of file
+ }
+ export const deleteFileIndex = (documentId: string,datasetId: string) => {
+ return request({
+ url: "/brichat-service/knowledge-base/deleteFileIndex",
+ method: "delete",
+ params: {
+ documentId,
+ datasetId,
+ }
+ })
+ }
+
+ export const deleteAllIndex = () => {
+ return request({
+ url: "/brichat-service/knowledge-base/deleteAllIndex",
+ method: "delete",
+ })
+ }
diff --git a/chat-client/src/views/permission/esindexManage/index.vue b/chat-client/src/views/permission/esindexManage/index.vue
index 60c4d41..a8e5fc4 100644
--- a/chat-client/src/views/permission/esindexManage/index.vue
+++ b/chat-client/src/views/permission/esindexManage/index.vue
@@ -6,6 +6,9 @@
索引名: {{ selectedIndex?.indexName || '-' }}
-别名: {{ selectedIndex?.aliases?.join(', ') || '-' }}
+别名: {{ selectedIndex?.databaseName || '-' }}
文档数量: {{ selectedIndex?.docsCount || '-' }}
存储大小: {{ selectedIndex?.storeSize || '-' }}
健康状态:
@@ -112,7 +115,7 @@
import { ref, reactive, onMounted } from "vue"
import { ElMessage, ElMessageBox } from "element-plus"
import { Plus, Delete } from "@element-plus/icons-vue"
-import { getIndexInfo, createAllIndex ,deleteIndex,setIndextask,getIndexTask} from "@/api/dataset"
+import { getIndexInfo, createAllIndex ,deleteIndex,setIndextask,getIndexTask,deleteAllIndex} from "@/api/dataset"
const isFullscreen = ref(false) //是否全屏
const tableLoading = ref(false)
@@ -151,6 +154,7 @@ const loadIndexList = async () => {
try {
const res = await getIndexInfo(pagination.currentPage, pagination.pageSize, searchForm.indexName)
+ console.log(res.data)
indexList.value = res.data.content
pagination.total = res.data.total
@@ -162,8 +166,14 @@ const loadIndexList = async () => {
}
}
-const formatAliases = (row) =>
- row.aliases && row.aliases.length ? row.aliases.join(", ") : "-"
+const formatAliases = (row) => {
+ if (!row.databaseName) return "-";
+ if (Array.isArray(row.databaseName)) {
+ return row.databaseName.join(", ");
+ }
+ return row.databaseName; // 字符串直接返回
+};
+
const getStatusType = (health) => {
if (health === "green") return "success"
@@ -177,6 +187,19 @@ const handleSearch = () => {
loadIndexList()
}
+const handleDeleteAllIndex = async () => {
+ tableLoading.value = true
+ try {
+ await deleteAllIndex()
+ ElMessage.success("索引删除成功")
+ loadIndexList()
+ } catch (error) {
+ ElMessage.error(error.message)
+ } finally {
+ tableLoading.value = false
+ }
+}
+
const handleCurrentChange = (page) => {
pagination.currentPage = page
loadIndexList()
@@ -216,10 +239,10 @@ const pollTaskStatus = async (taskId) => {
if (total > 0) progress.value = Math.floor((finished / total) * 100)
if (status === "done") {
- ElMessage.success("索引构建完成")
+ ElMessage.success("索引构建完成"+`共构建${total}个文档,成功${finished}个`)
loadIndexList()
} else if (status === "failed") {
- ElMessage.error("索引构建失败")
+ ElMessage.error("索引构建失败"+`共构建${total}个文档,成功${finished}个`)
} else {
// 继续轮询
timer = setTimeout(() => pollTaskStatus(taskId), 200)
@@ -233,7 +256,7 @@ const handleCreateIndex = async () => {
try {
const res = await setIndextask()
const taskId = res.data
- ElMessage.success(`任务已提交,taskId=${ taskId}`)
+ ElMessage.success(`开始构建索引`)
progress.value = 0
taskStatus.value = "processing"
diff --git a/chat-server/src/main/java/com/bjtds/brichat/controller/KnowledgeBaseController.java b/chat-server/src/main/java/com/bjtds/brichat/controller/KnowledgeBaseController.java
index f421250..0e2d64b 100644
--- a/chat-server/src/main/java/com/bjtds/brichat/controller/KnowledgeBaseController.java
+++ b/chat-server/src/main/java/com/bjtds/brichat/controller/KnowledgeBaseController.java
@@ -40,16 +40,16 @@ public class KnowledgeBaseController {
@Autowired
private KnowledgeBaseService knowledgeBaseService;
- @Autowired
- private EsKnowledgeServiceImpl esKnowledgeService;
+// @Autowired
+// private EsKnowledgeServiceImpl esKnowledgeService;
@Autowired
private EsTDatasetFilesService esTDatasetFilesService;
- @Autowired
- private EsKnowledgeImporter esKnowledgeImporter;
+// @Autowired
+// private EsKnowledgeImporter esKnowledgeImporter;
@Autowired
private EsTDatasetFilesImporter esTDatasetFilesImporter;
@@ -99,7 +99,7 @@ public class KnowledgeBaseController {
public ResultUtils createIndex(@RequestParam("documentId") String documentId) throws Exception {
try{
- esKnowledgeImporter.importDocumentId(documentId);
+ esTDatasetFilesImporter.importDocumentId(documentId);
return ResultUtils.success("索引创建成功");
} catch (IOException e) {
return ResultUtils.error("索引创建失败: " + e.getMessage());
@@ -141,6 +141,26 @@ public class KnowledgeBaseController {
result.put("finished", finished);
return ResultUtils.success(result);
}
+ @ApiOperation("删除索引下的文件")
+ @DeleteMapping("/deleteFileIndex")
+ public ResultUtils deleteFileIndex(@RequestParam("documentId") String documentId,@RequestParam("datasetId")String datasetId) throws Exception {
+ try{
+ esTDatasetFilesService.deleteDocIndex(datasetId,documentId);
+ return ResultUtils.success("索引删除成功");
+ } catch (IOException e) {
+ return ResultUtils.error("索引删除失败: " + e.getMessage());
+ }
+ }
+ @ApiOperation("删除所有索引")
+ @DeleteMapping("/deleteAllIndex")
+ public ResultUtils deleteAllIndex() throws Exception {
+ try{
+ esTDatasetFilesService.deleteAllIndex();
+ return ResultUtils.success("索引删除成功");
+ } catch (IOException e) {
+ return ResultUtils.error("索引删除失败: " + e.getMessage());
+ }
+ }
@ApiOperation("返回关联表数据")
diff --git a/chat-server/src/main/java/com/bjtds/brichat/entity/dto/RetrievalDto.java b/chat-server/src/main/java/com/bjtds/brichat/entity/dto/RetrievalDto.java
index 7524caa..bb91868 100644
--- a/chat-server/src/main/java/com/bjtds/brichat/entity/dto/RetrievalDto.java
+++ b/chat-server/src/main/java/com/bjtds/brichat/entity/dto/RetrievalDto.java
@@ -17,4 +17,5 @@ public class RetrievalDto {
private String datasetId;
private String datasetName;
private String sourceUrl;
+ private String documentId;
}
diff --git a/chat-server/src/main/java/com/bjtds/brichat/entity/esmodel/IndexInfo.java b/chat-server/src/main/java/com/bjtds/brichat/entity/esmodel/IndexInfo.java
index aad3d68..d9a4cfe 100644
--- a/chat-server/src/main/java/com/bjtds/brichat/entity/esmodel/IndexInfo.java
+++ b/chat-server/src/main/java/com/bjtds/brichat/entity/esmodel/IndexInfo.java
@@ -10,6 +10,7 @@ import lombok.NoArgsConstructor;
@AllArgsConstructor
public class IndexInfo {
private String indexName;
+ private String databaseName;
private String health; // 健康状态
private String docsCount; // 文档数量
private String storeSize; //索引大小
diff --git a/chat-server/src/main/java/com/bjtds/brichat/mapper/opengauss/TDatasetFilesMapper.java b/chat-server/src/main/java/com/bjtds/brichat/mapper/opengauss/TDatasetFilesMapper.java
index dcfdaf3..794d8f6 100644
--- a/chat-server/src/main/java/com/bjtds/brichat/mapper/opengauss/TDatasetFilesMapper.java
+++ b/chat-server/src/main/java/com/bjtds/brichat/mapper/opengauss/TDatasetFilesMapper.java
@@ -182,5 +182,10 @@ public interface TDatasetFilesMapper {
List