fix: 修复xls预览内容为空问题,修复批量创建索引无效问题
This commit is contained in:
parent
c0a3c956aa
commit
d9ae2a07c1
|
|
@ -346,9 +346,11 @@
|
||||||
@error="errorHandler"
|
@error="errorHandler"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<!-- Excel 文件预览 (支持 .xls 和 .xlsx) -->
|
||||||
<vue-office-excel
|
<vue-office-excel
|
||||||
v-if="previewFileType == 'xlsx' || previewFileType == 'xls' || previewFileType == 'csv'"
|
v-if="['xls', 'xlsx', 'csv'].includes(previewFileType)"
|
||||||
:src="previewFileUrl"
|
:src="previewFileUrl"
|
||||||
|
:options="excelPreviewOptions"
|
||||||
style="height: 100vh;"
|
style="height: 100vh;"
|
||||||
@rendered="renderedHandler"
|
@rendered="renderedHandler"
|
||||||
@error="errorHandler"
|
@error="errorHandler"
|
||||||
|
|
@ -720,6 +722,19 @@ const previewFileUrl = ref('')
|
||||||
// 添加文本内容预览状态
|
// 添加文本内容预览状态
|
||||||
const previewTextContent = ref('')
|
const previewTextContent = ref('')
|
||||||
const previewMarkdownContent = 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[]) => {
|
const handleSelectionChange = (selection: FileItem[]) => {
|
||||||
|
|
@ -858,6 +873,9 @@ if (!newVal) {
|
||||||
previewMarkdownContent.value = ''
|
previewMarkdownContent.value = ''
|
||||||
previewFileUrl.value = ''
|
previewFileUrl.value = ''
|
||||||
previewFileType.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) => {
|
const handleDownload = async (row: FileItem) => {
|
||||||
try {
|
try {
|
||||||
|
|
@ -981,6 +1006,8 @@ const handlePreview = async (row: FileItem) => {
|
||||||
previewDrawerVisible.value = true
|
previewDrawerVisible.value = true
|
||||||
previewLoading.value = true
|
previewLoading.value = true
|
||||||
|
|
||||||
|
// 保存当前预览的文件信息
|
||||||
|
currentPreviewFile.value = row
|
||||||
previewFileType.value = row.fileType;
|
previewFileType.value = row.fileType;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
@ -999,7 +1026,6 @@ const handlePreview = async (row: FileItem) => {
|
||||||
gfm: true
|
gfm: true
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
previewMarkdownContent.value = marked.parse(content) as string
|
previewMarkdownContent.value = marked.parse(content) as string
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -1012,6 +1038,13 @@ const handlePreview = async (row: FileItem) => {
|
||||||
previewFileUrl.value = await fetchPreviewUrl(parseInt(row.id))
|
previewFileUrl.value = await fetchPreviewUrl(parseInt(row.id))
|
||||||
console.log("previewFileUrl (from API)", previewFileUrl.value)
|
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
|
segmentdocId.value = row.difyDocId
|
||||||
const resp = await getSegmentList({
|
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 {
|
.replace-info {
|
||||||
margin-bottom: 24px;
|
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 {
|
} 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.getDifyStoragePath(),
|
||||||
doc.getSourceUrl(),
|
doc.getSourceUrl(),
|
||||||
doc.getIsDeep(),
|
doc.getIsDeep(),
|
||||||
|
|
||||||
true
|
true
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
@ -133,6 +134,7 @@ public class EsTDatasetFilesServiceImpl implements EsTDatasetFilesService {
|
||||||
.id(subDoc.getId().toString())
|
.id(subDoc.getId().toString())
|
||||||
.document(subDoc)
|
.document(subDoc)
|
||||||
);
|
);
|
||||||
|
log.info("异步添加文档分片到索引 fileId={} 索引构建成功 docName={}", subDoc.getId(), subDoc.getName());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException("分片索引失败", e);
|
throw new RuntimeException("分片索引失败", e);
|
||||||
}
|
}
|
||||||
|
|
@ -174,7 +176,7 @@ public class EsTDatasetFilesServiceImpl implements EsTDatasetFilesService {
|
||||||
.id(singleDoc.getId().toString())
|
.id(singleDoc.getId().toString())
|
||||||
.document(singleDoc)
|
.document(singleDoc)
|
||||||
);
|
);
|
||||||
|
log.info("Single异步添加文档分片到索引 fileId={} 索引构建成功 docName={}", singleDoc.getId(), singleDoc.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Future<?> f : futures) {
|
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 {
|
} finally {
|
||||||
executor.shutdown();
|
executor.shutdown();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import com.bjtds.brichat.entity.dataset.TDatasetFiles;
|
||||||
import com.bjtds.brichat.service.DatasetFilesService;
|
import com.bjtds.brichat.service.DatasetFilesService;
|
||||||
import com.bjtds.brichat.service.EsTDatasetFilesService;
|
import com.bjtds.brichat.service.EsTDatasetFilesService;
|
||||||
import io.swagger.models.auth.In;
|
import io.swagger.models.auth.In;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
@ -16,7 +17,7 @@ import org.springframework.stereotype.Service;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
public class EsTDatasetFilesImporter {
|
public class EsTDatasetFilesImporter {
|
||||||
@Autowired
|
@Autowired
|
||||||
|
|
@ -24,7 +25,7 @@ public class EsTDatasetFilesImporter {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private DatasetFilesService datasetFilesService;
|
private DatasetFilesService datasetFilesService;
|
||||||
private static final Logger log = LoggerFactory.getLogger(EsTDatasetFilesImporter.class);
|
// private static final Logger log = LoggerFactory.getLogger(EsTDatasetFilesImporter.class);
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private StringRedisTemplate redisTemplate;
|
private StringRedisTemplate redisTemplate;
|
||||||
|
|
@ -62,15 +63,15 @@ public class EsTDatasetFilesImporter {
|
||||||
if (document == null) continue;
|
if (document == null) continue;
|
||||||
String filePath = document.getDifyStoragePath();
|
String filePath = document.getDifyStoragePath();
|
||||||
if (filePath == null) {
|
if (filePath == null) {
|
||||||
log.debug("documentId=" + document.getId() + " 不存在difyStoragePath,跳过");
|
log.info("documentId=" + document.getId() + " 不存在difyStoragePath,跳过");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
File file = new File(filePath);
|
File file = new File(filePath);
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
log.debug(file.getAbsolutePath() + " 不存在,跳过");
|
log.info(file.getAbsolutePath() + " 不存在,跳过");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(document.getIsEs()){
|
if(Boolean.TRUE.equals(document.getIsEs())){
|
||||||
log.info("documentId=" + document.getId() + " 是ES索引文件,跳过");
|
log.info("documentId=" + document.getId() + " 是ES索引文件,跳过");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -82,9 +83,9 @@ public class EsTDatasetFilesImporter {
|
||||||
redisTemplate.opsForValue().set("import:task:" + taskId + ":finished", String.valueOf(finished));
|
redisTemplate.opsForValue().set("import:task:" + taskId + ":finished", String.valueOf(finished));
|
||||||
document.setIsEs(true);
|
document.setIsEs(true);
|
||||||
datasetFilesService.updateFile(document);
|
datasetFilesService.updateFile(document);
|
||||||
log.debug("documentId=" + document.getId() + " 索引构建成功");
|
log.info("documentId=" + document.getId() + " 索引构建成功");
|
||||||
} catch (Exception e) {
|
} 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");
|
redisTemplate.opsForValue().set("import:task:" + taskId + ":status", "done");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue