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