优化代码
This commit is contained in:
parent
a91397ebbf
commit
b2a63e4f18
|
|
@ -1,5 +1,6 @@
|
|||
package com.electromagnetic.industry.software.common.parse;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import com.electromagnetic.industry.software.common.util.OfficeFileUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
|
|
@ -10,11 +11,13 @@ public class PdfParse extends FileParse {
|
|||
@Override
|
||||
public String parseContent(InputStream stream, String fileType) {
|
||||
String res = "";
|
||||
try {
|
||||
String fileTmpPath = createFileTmpPath(fileType);
|
||||
try {
|
||||
res = OfficeFileUtil.parsePdf(fileTmpPath);
|
||||
} catch (Exception e) {
|
||||
log.error("解析pdf文件失败{}", e.getMessage(), e);
|
||||
} finally {
|
||||
FileUtil.del(fileTmpPath);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,12 +16,14 @@ public class WordParse extends FileParse {
|
|||
try {
|
||||
FileUtil.writeFromStream(stream, fileTmpPath);
|
||||
if (fileType.endsWith("docx")) {
|
||||
return OfficeFileUtil.parseDocx(fileTmpPath);
|
||||
res = OfficeFileUtil.parseDocx(fileTmpPath);
|
||||
} else {
|
||||
return OfficeFileUtil.parseDoc(fileTmpPath);
|
||||
res = OfficeFileUtil.parseDoc(fileTmpPath);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.info("解析{}失败,原因{}", fileType, e.getMessage(), e);
|
||||
} finally {
|
||||
FileUtil.del(fileTmpPath);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,8 +29,6 @@ public final class EleCommonUtil {
|
|||
PARSE_MAP.put("ppt", new PptParse());
|
||||
PARSE_MAP.put("pptx", new PptParse());
|
||||
PARSE_MAP.put("text", new TextParse());
|
||||
PARSE_MAP.put("txt", new TextParse());
|
||||
PARSE_MAP.put("py", new TextParse());
|
||||
}
|
||||
|
||||
// 正则表达式模式,匹配中文字符、下划线、连字符、加号、数字和英文字符
|
||||
|
|
|
|||
Loading…
Reference in New Issue