|
@@ -281,9 +281,12 @@ public class EmailParseService {
|
|
|
String filepath,
|
|
|
Integer emailType,
|
|
|
List<EmailZipFileDTO> resultList) throws IOException {
|
|
|
- String parent = FileUtil.getParent(filepath, 2);
|
|
|
- String destPath = parent + File.separator + "archive" + File.separator + FileUtil.mainName(filepath);
|
|
|
- File destFile = new File(destPath);
|
|
|
+ if (!ArchiveUtil.isArchive(filepath)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String output = filepath.replaceAll("original", "archive");
|
|
|
+ String destPath = FileUtil.getParent(output, 1) + File.separator + FileUtil.mainName(output);
|
|
|
+ File destFile = FileUtil.file(destPath);
|
|
|
if (!destFile.exists()) {
|
|
|
if (!destFile.mkdirs()) {
|
|
|
throw new IOException("无法创建目标目录: " + destPath);
|
|
@@ -435,11 +438,10 @@ public class EmailParseService {
|
|
|
/**
|
|
|
* 邮件信息前置处理,在解析操作执行之前的过滤逻辑和校验逻辑。返回所有附件大小汇总
|
|
|
*
|
|
|
- * @param emailInfo 邮件信息(包含所有解压后的文件)
|
|
|
+ * @param emailTitle 邮件信息(包含所有解压后的文件)
|
|
|
+ * @param dtos 邮件信息(包含所有解压后的文件)
|
|
|
*/
|
|
|
- private void checkEmailFileInfo(EmailInfoDTO emailInfo) {
|
|
|
- String emailTitle = emailInfo.getEmailTitle();
|
|
|
- List<EmailZipFileDTO> dtos = emailInfo.getEmailFileList();
|
|
|
+ private void checkEmailFileInfo(String emailTitle, List<EmailZipFileDTO> dtos) {
|
|
|
// 如果压缩包里面既有pdf又有其他格式的文件,说明其他格式的文件是不需要解析的
|
|
|
List<String> exts = dtos.stream().map(EmailZipFileDTO::getExtName).distinct().toList();
|
|
|
if (exts.contains(Constants.FILE_PDF) && exts.size() > 1) {
|
|
@@ -506,18 +508,17 @@ public class EmailParseService {
|
|
|
private void parseResults(EmailInfoDTO emailInfo,
|
|
|
List<ParseResult<ReportData>> resultList) {
|
|
|
String emailTitle = emailInfo.getEmailTitle();
|
|
|
- String senderEmail = emailInfo.getSenderEmail();
|
|
|
- List<EmailZipFileDTO> dtos = emailInfo.getEmailFileList();
|
|
|
+ List<EmailZipFileDTO> dtos = ListUtil.toList(emailInfo.getEmailFileList());
|
|
|
if (CollUtil.isEmpty(dtos)) {
|
|
|
return;
|
|
|
}
|
|
|
// 附件文件检查
|
|
|
- this.checkEmailFileInfo(emailInfo);
|
|
|
+ this.checkEmailFileInfo(emailTitle, dtos);
|
|
|
// 解析邮件报告
|
|
|
for (EmailZipFileDTO zipFile : dtos) {
|
|
|
// EmailFileInfoDO emailFile = this.saveEmailFileInfo(emailId, zipFile.getFilename(), zipFile.getFilepath());
|
|
|
// 解析并保存报告
|
|
|
- ParseResult<ReportData> parseResult = this.parseReportAndHandleResult(emailTitle, senderEmail, zipFile);
|
|
|
+ ParseResult<ReportData> parseResult = this.parseReportAndHandleResult(emailTitle, emailInfo.getSenderEmail(), zipFile);
|
|
|
if (!Objects.equals(1, parseResult.getStatus())) {
|
|
|
log.error(parseResult.getMsg());
|
|
|
}
|
|
@@ -649,17 +650,19 @@ public class EmailParseService {
|
|
|
result = new ParseResult<>(ReportParseStatus.PARSE_FAIL, null, e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
- if (reportData != null && reportData.getBaseInfo() != null) {
|
|
|
+ // 当reportData==null时重新构建一个reportData对象
|
|
|
+ reportData = this.buildNvlReportData(fileId, reportType, reportData, fileName);
|
|
|
+ if (reportData.getBaseInfo() != null) {
|
|
|
// 设置月报类型
|
|
|
reportData.getBaseInfo().setMonthlyType(monthlyType.getType());
|
|
|
// 当报告日期还是空时设置为今天的前一天
|
|
|
if (reportData.getBaseInfo().getReportDate() == null) {
|
|
|
- Date date = DateUtil.offsetDay(new Date(), -1);
|
|
|
- reportData.getBaseInfo().setReportDate(date);
|
|
|
+ reportData.getBaseInfo().setReportDate(DateUtil.offsetDay(new Date(), -1));
|
|
|
}
|
|
|
}
|
|
|
// ocr信息提取(印章、联系人、基金名称和产品代码)
|
|
|
reportData = this.ocrReportData(fileId, reportType, reportData, fileName, senderEmail, images);
|
|
|
+ result.setData(reportData);
|
|
|
if (log.isInfoEnabled()) {
|
|
|
log.info("报告{} 解析耗时{}ms,结果是:{}", fileName, (System.currentTimeMillis() - start), reportData);
|
|
|
}
|
|
@@ -736,13 +739,11 @@ public class EmailParseService {
|
|
|
if (CollUtil.isEmpty(images)) {
|
|
|
return reportData;
|
|
|
}
|
|
|
- if (log.isInfoEnabled()) {
|
|
|
- log.info("报告{} 用ocr补充解析结果。补充前的结果是:{}", fileName, reportData);
|
|
|
- }
|
|
|
- // 当reportData==null时重新构建一个reportData对象
|
|
|
- reportData = this.buildNvlReportData(fileId, reportType, reportData, fileName);
|
|
|
// 报告才识别尾页的印章和联系人,确认单不识别尾页
|
|
|
if (ReportType.LETTER != reportType) {
|
|
|
+ if (log.isInfoEnabled()) {
|
|
|
+ log.info("报告{} 用ocr补充解析结果。补充前的结果是:{}", fileName, reportData);
|
|
|
+ }
|
|
|
OCRParseData parseRes = null;
|
|
|
try {
|
|
|
// 首页和尾页相等时只读首页
|
|
@@ -784,48 +785,54 @@ public class EmailParseService {
|
|
|
reportData.getFundInfo().setCompanyName(parseRes.getCompanyName());
|
|
|
}
|
|
|
}
|
|
|
- } else {
|
|
|
- // 确认单AI解析失败时重新用OCR识别
|
|
|
- LetterReportData letterReportData = (LetterReportData) reportData;
|
|
|
- if (letterReportData.wasFailed()) {
|
|
|
- OCRLetterParseData parseRes = null;
|
|
|
- try {
|
|
|
- parseRes = new OCRReportParser().parseLetterData(fileName, this.ocrParserUrl, images.get(0));
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("报告{} OCR提取确认单关键信息出错:{}", fileName, e.getMessage());
|
|
|
- }
|
|
|
- if (parseRes == null) {
|
|
|
- return reportData;
|
|
|
- }
|
|
|
- if (letterReportData.getFundInfo() != null) {
|
|
|
- letterReportData.getFundInfo().setFundName(parseRes.getFundName());
|
|
|
- letterReportData.getFundInfo().setFundCode(parseRes.getFundCode());
|
|
|
- }
|
|
|
- // 投资者信息
|
|
|
- if (letterReportData.getInvestorInfo() == null) {
|
|
|
- letterReportData.setInvestorInfo(new ReportInvestorInfoDTO(fileId));
|
|
|
- }
|
|
|
- letterReportData.getInvestorInfo().setInvestorName(parseRes.getInvestorName());
|
|
|
- letterReportData.getInvestorInfo().setCertificateNumber(parseRes.getCertificateNumber());
|
|
|
- letterReportData.getInvestorInfo().setTradingAccount(parseRes.getTradingAccount());
|
|
|
- letterReportData.getInvestorInfo().setFundAccount(parseRes.getFundAccount());
|
|
|
- letterReportData.getInvestorInfo().setCertificateType(parseRes.getCertificateType());
|
|
|
- // 交易流水
|
|
|
- if (letterReportData.getFundTransaction() == null) {
|
|
|
- letterReportData.setFundTransaction(new ReportFundTransactionDTO(fileId));
|
|
|
- }
|
|
|
- letterReportData.getFundTransaction().setTransactionType(parseRes.getTransactionType());
|
|
|
- letterReportData.getFundTransaction().setApplyDate(parseRes.getApplyDate());
|
|
|
- letterReportData.getFundTransaction().setApplyShare(parseRes.getApplyShare());
|
|
|
- letterReportData.getFundTransaction().setApplyAmount(parseRes.getApplyAmount());
|
|
|
- letterReportData.getFundTransaction().setHoldingDate(parseRes.getHoldingDate());
|
|
|
- letterReportData.getFundTransaction().setAmount(parseRes.getAmount());
|
|
|
- letterReportData.getFundTransaction().setShare(parseRes.getShare());
|
|
|
- letterReportData.getFundTransaction().setNav(parseRes.getNav());
|
|
|
- }
|
|
|
- return letterReportData;
|
|
|
+ reportData.setAiParse(true);
|
|
|
+ return reportData;
|
|
|
}
|
|
|
- return reportData;
|
|
|
+ // 确认单AI解析失败时重新用OCR识别
|
|
|
+ if (!reportData.wasFailed()) {
|
|
|
+ return reportData;
|
|
|
+ }
|
|
|
+ if (log.isInfoEnabled()) {
|
|
|
+ log.info("确认单报告{} 用ocr补充解析结果。补充前的结果是:{}", fileName, reportData);
|
|
|
+ }
|
|
|
+ LetterReportData letterReportData = (LetterReportData) reportData;
|
|
|
+ OCRLetterParseData parseRes = null;
|
|
|
+ try {
|
|
|
+ parseRes = new OCRReportParser().parseLetterData(fileName, this.ocrParserUrl, images.get(0));
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("确认单报告{} OCR提取确认单关键信息出错:{}", fileName, e.getMessage());
|
|
|
+ }
|
|
|
+ if (parseRes == null) {
|
|
|
+ return reportData;
|
|
|
+ }
|
|
|
+ if (letterReportData.getFundInfo() != null) {
|
|
|
+ letterReportData.getFundInfo().setFundName(parseRes.getFundName());
|
|
|
+ letterReportData.getFundInfo().setFundCode(parseRes.getFundCode());
|
|
|
+ }
|
|
|
+ // 投资者信息
|
|
|
+ if (letterReportData.getInvestorInfo() == null) {
|
|
|
+ letterReportData.setInvestorInfo(new ReportInvestorInfoDTO(fileId));
|
|
|
+ }
|
|
|
+ letterReportData.getInvestorInfo().setInvestorName(parseRes.getInvestorName());
|
|
|
+ letterReportData.getInvestorInfo().setCertificateNumber(parseRes.getCertificateNumber());
|
|
|
+ letterReportData.getInvestorInfo().setTradingAccount(parseRes.getTradingAccount());
|
|
|
+ letterReportData.getInvestorInfo().setFundAccount(parseRes.getFundAccount());
|
|
|
+ letterReportData.getInvestorInfo().setCertificateType(parseRes.getCertificateType());
|
|
|
+ // 交易流水
|
|
|
+ if (letterReportData.getTransaction() == null) {
|
|
|
+ letterReportData.setTransaction(new ReportFundTransactionDTO(fileId));
|
|
|
+ }
|
|
|
+ letterReportData.getTransaction().setTransactionType(parseRes.getTransactionType());
|
|
|
+ letterReportData.getTransaction().setApplyDate(parseRes.getApplyDate());
|
|
|
+ letterReportData.getTransaction().setApplyShare(parseRes.getApplyShare());
|
|
|
+ letterReportData.getTransaction().setApplyAmount(parseRes.getApplyAmount());
|
|
|
+ letterReportData.getTransaction().setHoldingDate(parseRes.getHoldingDate());
|
|
|
+ letterReportData.getTransaction().setAmount(parseRes.getAmount());
|
|
|
+ letterReportData.getTransaction().setShare(parseRes.getShare());
|
|
|
+ letterReportData.getTransaction().setNav(parseRes.getNav());
|
|
|
+
|
|
|
+ letterReportData.setAiParse(true);
|
|
|
+ return letterReportData;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -863,7 +870,6 @@ public class EmailParseService {
|
|
|
} else if (ReportType.LETTER == reportType) {
|
|
|
reportData = new LetterReportData(baseInfo, fundInfo);
|
|
|
}
|
|
|
- reportData.setAiParse(true);
|
|
|
return reportData;
|
|
|
}
|
|
|
|