fix: 修复xls预览内容为空问题,修复批量创建索引无效问题

This commit is contained in:
wenjinbo 2025-09-23 11:58:00 +08:00
parent c0a3c956aa
commit d9ae2a07c1
3 changed files with 64 additions and 16 deletions

View File

@ -346,9 +346,11 @@
@error="errorHandler"
/>
<!-- Excel 文件预览 (支持 .xls .xlsx) -->
<vue-office-excel
v-if="previewFileType == 'xlsx' || previewFileType == 'xls' || previewFileType == 'csv'"
v-if="['xls', 'xlsx', 'csv'].includes(previewFileType)"
:src="previewFileUrl"
:options="excelPreviewOptions"
style="height: 100vh;"
@rendered="renderedHandler"
@error="errorHandler"
@ -720,6 +722,19 @@ const previewFileUrl = ref('')
//
const previewTextContent = ref('')
const previewMarkdownContent = ref('')
//
const currentPreviewFile = ref<FileItem | null>(null)
// Excel
const excelPreviewOptions = ref({
xls: false, // xlsxfalsexlstrue
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;

View File

@ -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();
}

View File

@ -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");