调整es中存放的文件路径,确保各端导入的路径是一样的
This commit is contained in:
parent
1c8b29e249
commit
fe74eb879d
72
src/main/java/com/doc/parser/domain/impl/ExcelImporter.java
Normal file
72
src/main/java/com/doc/parser/domain/impl/ExcelImporter.java
Normal file
@ -0,0 +1,72 @@
|
||||
package com.doc.parser.domain.impl;
|
||||
|
||||
/**
|
||||
* @author Luke.ye
|
||||
* @date 2025/5/25 14:54
|
||||
*/
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Iterator;
|
||||
|
||||
@Component
|
||||
public class ExcelImporter extends AbstractBaseFileImporter {
|
||||
|
||||
@Value("${excel.path}")
|
||||
private String excelPath;
|
||||
|
||||
@Override
|
||||
protected String getDirectoryPath() {
|
||||
return excelPath;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getFileSuffix() {
|
||||
return ".xlsx";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getDocTypeCode() {
|
||||
return "excel";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String extractContent(Path path) throws IOException {
|
||||
try (FileInputStream fis = new FileInputStream(path.toFile());
|
||||
Workbook workbook = new XSSFWorkbook(fis)) {
|
||||
|
||||
Sheet sheet = workbook.getSheetAt(0);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
Iterator<Row> rowIterator = sheet.iterator();
|
||||
|
||||
if (rowIterator.hasNext()) rowIterator.next(); // 跳过表头
|
||||
|
||||
while (rowIterator.hasNext()) {
|
||||
Row row = rowIterator.next();
|
||||
String title = getCellString(row.getCell(0));
|
||||
String content = getCellString(row.getCell(1));
|
||||
|
||||
if (!title.isBlank()) {
|
||||
sb.append("【标题】").append(title).append("\n");
|
||||
}
|
||||
if (!content.isBlank()) {
|
||||
sb.append(content).append("\n\n");
|
||||
}
|
||||
}
|
||||
|
||||
return sb.toString().trim();
|
||||
}
|
||||
}
|
||||
|
||||
private String getCellString(Cell cell) {
|
||||
if (cell == null) return "";
|
||||
cell.setCellType(CellType.STRING);
|
||||
return cell.getStringCellValue().trim();
|
||||
}
|
||||
}
|
||||
|
||||
@ -26,3 +26,4 @@ exclude.file.path.prefix=/Users/admin/Desktop/ahnx-share-src-public/public
|
||||
markdown.path=/Users/admin/Desktop/ahnx-share-src-public/public
|
||||
pdf.path=/Users/admin/Desktop/ahnx-share-src-public/public
|
||||
word.path=/Users/admin/Desktop/ahnx-share-src-public/public
|
||||
excel.path=/Users/admin/Desktop/ahnx-share-src-public/public
|
||||
|
||||
@ -25,4 +25,5 @@ arthas.tunnel-server=ws://101.132.255.39:7777/ws
|
||||
exclude.file.path.prefix=D:/02-documents/01-ahnx-share-src-public/public
|
||||
markdown.path=D:/02-documents/01-ahnx-share-src-public/public
|
||||
pdf.path=D:/02-documents/01-ahnx-share-src-public/public
|
||||
word.path=D:/02-documents/01-ahnx-share-src-public/public
|
||||
word.path=D:/02-documents/01-ahnx-share-src-public/public
|
||||
excel.path=D:/02-documents/01-ahnx-share-src-public/public
|
||||
@ -27,4 +27,4 @@ pdf.path=/app/import-data
|
||||
word.path=/app/import-data
|
||||
|
||||
# 相对路径裁剪
|
||||
exclude.file.path.prefix=/app/
|
||||
exclude.file.path.prefix=/app/import-data
|
||||
Loading…
x
Reference in New Issue
Block a user