fix: 修复xls预览内容为空问题,修复批量创建索引无效问题
This commit is contained in:
parent
c0a3c956aa
commit
d9ae2a07c1
|
|
@ -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, // 预览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;
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
|
|
|||
Loading…
Reference in New Issue