From d9ae2a07c1036a0767ba0ea581b7340b6086b59b Mon Sep 17 00:00:00 2001 From: wenjinbo <599483010@qq.com> Date: Tue, 23 Sep 2025 11:58:00 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Dxls=E9=A2=84=E8=A7=88?= =?UTF-8?q?=E5=86=85=E5=AE=B9=E4=B8=BA=E7=A9=BA=E9=97=AE=E9=A2=98=EF=BC=8C?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=89=B9=E9=87=8F=E5=88=9B=E5=BB=BA=E7=B4=A2?= =?UTF-8?q?=E5=BC=95=E6=97=A0=E6=95=88=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../datasets/components/DocumentList.vue | 51 +++++++++++++++++-- .../impl/EsTDatasetFilesServiceImpl.java | 14 ++--- .../brichat/util/EsTDatasetFilesImporter.java | 15 +++--- 3 files changed, 64 insertions(+), 16 deletions(-) diff --git a/chat-client/src/views/datasets/components/DocumentList.vue b/chat-client/src/views/datasets/components/DocumentList.vue index 6c2fce7..9cc7fdc 100644 --- a/chat-client/src/views/datasets/components/DocumentList.vue +++ b/chat-client/src/views/datasets/components/DocumentList.vue @@ -346,9 +346,11 @@ @error="errorHandler" /> + (null) + +// Excel 预览选项配置 +const excelPreviewOptions = ref({ + xls: false, // 预览xlsx文件设为false;预览xls文件设为true + minColLength: 0, // excel最少渲染多少列 + minRowLength: 0, // excel最少渲染多少行 + widthOffset: 10, // 列宽度偏移 + heightOffset: 10, // 行高度偏移 + beforeTransformData: (workbookData: any) => { return workbookData }, + transformData: (workbookData: any) => { return workbookData } +}) // 选择变化处理 const handleSelectionChange = (selection: FileItem[]) => { @@ -858,6 +873,9 @@ if (!newVal) { previewMarkdownContent.value = '' previewFileUrl.value = '' previewFileType.value = '' + currentPreviewFile.value = null + // 重置 Excel 预览选项 + excelPreviewOptions.value.xls = false } }) @@ -916,6 +934,13 @@ ElNotification({ }) } +// 从预览中下载文件 +const handleDownloadFromPreview = async () => { + if (currentPreviewFile.value) { + await handleDownload(currentPreviewFile.value) + } +} + //文件下载 const handleDownload = async (row: FileItem) => { try { @@ -980,7 +1005,9 @@ const handlePreview = async (row: FileItem) => { // 显示抽屉 previewDrawerVisible.value = true previewLoading.value = true - + + // 保存当前预览的文件信息 + currentPreviewFile.value = row previewFileType.value = row.fileType; try { @@ -999,7 +1026,6 @@ const handlePreview = async (row: FileItem) => { gfm: true }) - previewMarkdownContent.value = marked.parse(content) as string } } else { @@ -1012,6 +1038,13 @@ const handlePreview = async (row: FileItem) => { previewFileUrl.value = await fetchPreviewUrl(parseInt(row.id)) console.log("previewFileUrl (from API)", previewFileUrl.value) } + + // 针对 Excel 文件设置预览选项 + if (['xls', 'xlsx', 'csv'].includes(row.fileType.toLowerCase())) { + // 根据文件类型设置 xls 选项 + excelPreviewOptions.value.xls = (row.fileType.toLowerCase() === 'xls') + console.log(`Excel 预览模式: ${row.fileType.toUpperCase()}, XLS 模式: ${excelPreviewOptions.value.xls}`) + } } segmentdocId.value = row.difyDocId const resp = await getSegmentList({ @@ -2562,6 +2595,18 @@ transform: scale(0.9) translateY(-5px); +// Excel 文件预览样式优化 +.excel-preview-container { + height: 100%; + background: #fafbfc; + + .vue-office-excel { + border-radius: 8px; + overflow: hidden; + box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1); + } +} + // 文件替换信息样式 .replace-info { margin-bottom: 24px; diff --git a/chat-server/src/main/java/com/bjtds/brichat/service/impl/EsTDatasetFilesServiceImpl.java b/chat-server/src/main/java/com/bjtds/brichat/service/impl/EsTDatasetFilesServiceImpl.java index 3b5d6ad..b416e74 100644 --- a/chat-server/src/main/java/com/bjtds/brichat/service/impl/EsTDatasetFilesServiceImpl.java +++ b/chat-server/src/main/java/com/bjtds/brichat/service/impl/EsTDatasetFilesServiceImpl.java @@ -75,9 +75,11 @@ public class EsTDatasetFilesServiceImpl implements EsTDatasetFilesService { ) ); - System.out.println("索引创建成功: " + DatasetId); + log.info("索引创建成功: 知识库id{}", DatasetId); + //System.out.println("索引创建成功: " + DatasetId); } else { - System.out.println("索引已存在: " + DatasetId); + log.info("索引已存在: 知识库id{}", DatasetId); + //System.out.println("索引已存在: " + DatasetId); } } @@ -124,7 +126,6 @@ public class EsTDatasetFilesServiceImpl implements EsTDatasetFilesService { doc.getDifyStoragePath(), doc.getSourceUrl(), doc.getIsDeep(), - true ); @@ -133,6 +134,7 @@ public class EsTDatasetFilesServiceImpl implements EsTDatasetFilesService { .id(subDoc.getId().toString()) .document(subDoc) ); + log.info("异步添加文档分片到索引 fileId={} 索引构建成功 docName={}", subDoc.getId(), subDoc.getName()); } catch (IOException e) { throw new RuntimeException("分片索引失败", e); } @@ -174,7 +176,7 @@ public class EsTDatasetFilesServiceImpl implements EsTDatasetFilesService { .id(singleDoc.getId().toString()) .document(singleDoc) ); - + log.info("Single异步添加文档分片到索引 fileId={} 索引构建成功 docName={}", singleDoc.getId(), singleDoc.getName()); } for (Future f : futures) { @@ -185,8 +187,8 @@ public class EsTDatasetFilesServiceImpl implements EsTDatasetFilesService { } } - System.out.println("文档索引完成: " + doc.getName()); - + // System.out.println("文档索引完成: " + doc.getName()); + log.info("addDoc文档索引完成: 知识库id={} docName={}", doc.getDifyDatasetId(), doc.getName()); } finally { executor.shutdown(); } diff --git a/chat-server/src/main/java/com/bjtds/brichat/util/EsTDatasetFilesImporter.java b/chat-server/src/main/java/com/bjtds/brichat/util/EsTDatasetFilesImporter.java index 44fbb7b..07a841d 100644 --- a/chat-server/src/main/java/com/bjtds/brichat/util/EsTDatasetFilesImporter.java +++ b/chat-server/src/main/java/com/bjtds/brichat/util/EsTDatasetFilesImporter.java @@ -4,6 +4,7 @@ import com.bjtds.brichat.entity.dataset.TDatasetFiles; import com.bjtds.brichat.service.DatasetFilesService; import com.bjtds.brichat.service.EsTDatasetFilesService; import io.swagger.models.auth.In; +import lombok.extern.slf4j.Slf4j; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -16,7 +17,7 @@ import org.springframework.stereotype.Service; import java.io.File; import java.io.IOException; import java.util.List; - +@Slf4j @Service public class EsTDatasetFilesImporter { @Autowired @@ -24,7 +25,7 @@ public class EsTDatasetFilesImporter { @Autowired private DatasetFilesService datasetFilesService; - private static final Logger log = LoggerFactory.getLogger(EsTDatasetFilesImporter.class); + // private static final Logger log = LoggerFactory.getLogger(EsTDatasetFilesImporter.class); @Autowired private StringRedisTemplate redisTemplate; @@ -62,15 +63,15 @@ public class EsTDatasetFilesImporter { if (document == null) continue; String filePath = document.getDifyStoragePath(); if (filePath == null) { - log.debug("documentId=" + document.getId() + " 不存在difyStoragePath,跳过"); + log.info("documentId=" + document.getId() + " 不存在difyStoragePath,跳过"); continue; } File file = new File(filePath); if (!file.exists()) { - log.debug(file.getAbsolutePath() + " 不存在,跳过"); + log.info(file.getAbsolutePath() + " 不存在,跳过"); continue; } - if(document.getIsEs()){ + if(Boolean.TRUE.equals(document.getIsEs())){ log.info("documentId=" + document.getId() + " 是ES索引文件,跳过"); continue; } @@ -82,9 +83,9 @@ public class EsTDatasetFilesImporter { redisTemplate.opsForValue().set("import:task:" + taskId + ":finished", String.valueOf(finished)); document.setIsEs(true); datasetFilesService.updateFile(document); - log.debug("documentId=" + document.getId() + " 索引构建成功"); + log.info("documentId=" + document.getId() + " 索引构建成功"); } catch (Exception e) { - log.debug("documentId=" + document.getId() + " 索引构建失败: " + e.getMessage()); + log.info("documentId=" + document.getId() + " 索引构建失败: " + e.getMessage()); } } redisTemplate.opsForValue().set("import:task:" + taskId + ":status", "done");