Merge remote-tracking branch 'origin/develop_master' into develop_master

This commit is contained in:
zj
2022-05-01 18:50:50 +08:00
9 changed files with 641 additions and 248 deletions
@@ -100,6 +100,7 @@ import org.apache.pdfbox.util.PDFTextStripper;
import org.apache.pdfbox.util.PDFTextStripperByArea;
import org.apache.poi.hwpf.extractor.WordExtractor;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.poifs.filesystem.FileMagic;
import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.json.JSONTokener;
@@ -112,6 +113,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.sql.Clob;
@@ -3007,15 +3009,26 @@ public class SarStandardsInfoServiceImpl extends ServiceImpl<SarStandardsInfoDao
// 判断文件是docx还是PDF
if (null != attFileEO.getFileSuffix() && (attFileEO.getFileSuffix().equals("docx") || attFileEO.getFileSuffix().equals("doc") || attFileEO.getFileSuffix().equals("DOC") || attFileEO.getFileSuffix().equals("DOCX") || attFileEO.getFileSuffix().equals("ppt") || attFileEO.getFileSuffix().equals("pptx"))) {
if (attFileEO.getFileSuffix().equals("doc") || attFileEO.getFileSuffix().equals("docx") || attFileEO.getFileSuffix().equals("DOC") || attFileEO.getFileSuffix().equals("DOCX")) {
FileInputStream fis = new FileInputStream(readFilePath);
WordExtractor wordExtractor = new WordExtractor(fis);
String txt = wordExtractor.getText();
content.append(txt);
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(new File(readFilePath)));
if (FileMagic.valueOf(bis) == FileMagic.OOXML) {
XWPFDocument doc = new XWPFDocument(bis);
XWPFWordExtractor extractor = new XWPFWordExtractor(doc);
String txt = extractor.getText();
content.append(txt);
extractor.close();
}else {
WordExtractor wordExtractor = new WordExtractor(bis);
String txt = wordExtractor.getText();
content.append(txt);
wordExtractor.close();
}
bis.close();
} else {
OPCPackage opcPackage = XWPFDocument.openPackage(readFilePath);
XWPFWordExtractor extractor = new XWPFWordExtractor(opcPackage);
String txt = extractor.getText();
content.append(txt);
opcPackage.close();
}
} else {
PDDocument document = PDDocument.load(new File(readFilePath));
@@ -3028,6 +3041,7 @@ public class SarStandardsInfoServiceImpl extends ServiceImpl<SarStandardsInfoDao
// String[] lines = pdfFileInText.split("\\r?\\n");
content.append(pdfFileInText);
}
document.close();
}
} catch (Exception e) {
logger.error("搜索中心新增数据读取文档内容时失败");