|
@@ -333,12 +333,9 @@ public class EmailParseService {
|
|
this.handleCompressedFiles(params.getTitle(), reportPath, e.getReportType(), dtos);
|
|
this.handleCompressedFiles(params.getTitle(), reportPath, e.getReportType(), dtos);
|
|
} catch (Exception ex) {
|
|
} catch (Exception ex) {
|
|
log.warn("报告{} 压缩包解压失败:{}", reportPath, ExceptionUtil.stacktraceToString(ex));
|
|
log.warn("报告{} 压缩包解压失败:{}", reportPath, ExceptionUtil.stacktraceToString(ex));
|
|
- ParseResult<ReportData> result = new ParseResult<>();
|
|
|
|
- result.setStatus(ReportParseStatus.ARCHIVE_FAIL.getCode());
|
|
|
|
- result.setMsg(ReportParseStatus.ARCHIVE_FAIL.getMsg());
|
|
|
|
ReportData reportData = new ReportData.DefaultReportData();
|
|
ReportData reportData = new ReportData.DefaultReportData();
|
|
reportData.setReportPath(reportPath);
|
|
reportData.setReportPath(reportPath);
|
|
- dataList.add(result);
|
|
|
|
|
|
+ dataList.add(new ParseResult<>(ReportParseStatus.ARCHIVE_FAIL, reportData));
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
dtos.add(new EmailZipFileDTO(params.getTitle(), reportPath, e.getReportType()));
|
|
dtos.add(new EmailZipFileDTO(params.getTitle(), reportPath, e.getReportType()));
|
|
@@ -354,11 +351,7 @@ public class EmailParseService {
|
|
List<UploadReportResult> resultList = ListUtil.list(false);
|
|
List<UploadReportResult> resultList = ListUtil.list(false);
|
|
for (ParseResult<ReportData> result : dataList) {
|
|
for (ParseResult<ReportData> result : dataList) {
|
|
ReportData data = result.getData();
|
|
ReportData data = result.getData();
|
|
- UploadReportResult temp = new UploadReportResult();
|
|
|
|
- temp.setReportPath(data.getReportPath());
|
|
|
|
- temp.setMsg(result.getMsg());
|
|
|
|
- temp.setStatus(result.getStatus());
|
|
|
|
- resultList.add(temp);
|
|
|
|
|
|
+ resultList.add(new UploadReportResult(data.getReportPath(), result.getStatus(), result.getMsg()));
|
|
}
|
|
}
|
|
return resultList;
|
|
return resultList;
|
|
}
|
|
}
|
|
@@ -460,7 +453,10 @@ public class EmailParseService {
|
|
for (EmailZipFileDTO zipFile : dtos) {
|
|
for (EmailZipFileDTO zipFile : dtos) {
|
|
EmailFileInfoDO emailFile = this.saveEmailFileInfo(emailId, zipFile.getFilename(), zipFile.getFilepath());
|
|
EmailFileInfoDO emailFile = this.saveEmailFileInfo(emailId, zipFile.getFilename(), zipFile.getFilepath());
|
|
// 解析并保存报告
|
|
// 解析并保存报告
|
|
- ParseResult<ReportData> parseResult = this.parseReportAndHandleResult(emailTitle, emailFile, zipFile);
|
|
|
|
|
|
+ ParseResult<ReportData> parseResult = this.parseReportAndHandleResult(emailTitle, emailFile.getId(), zipFile);
|
|
|
|
+ if (!Objects.equals(1, parseResult.getStatus())) {
|
|
|
|
+ log.error(parseResult.getMsg());
|
|
|
|
+ }
|
|
if (parseResult.getData() == null) {
|
|
if (parseResult.getData() == null) {
|
|
parseResult.setData(new ReportData.DefaultReportData());
|
|
parseResult.setData(new ReportData.DefaultReportData());
|
|
}
|
|
}
|
|
@@ -473,13 +469,13 @@ public class EmailParseService {
|
|
/**
|
|
/**
|
|
* 解析报告并保存解析结果
|
|
* 解析报告并保存解析结果
|
|
*
|
|
*
|
|
- * @param emailTitle 邮件主题
|
|
|
|
- * @param emailFileInfo 当前报告信息
|
|
|
|
- * @param zipFile 当前报告的路径信息
|
|
|
|
|
|
+ * @param emailTitle 邮件主题
|
|
|
|
+ * @param fileId 当前文件数据库ID
|
|
|
|
+ * @param zipFile 当前报告的路径信息
|
|
* @return /
|
|
* @return /
|
|
*/
|
|
*/
|
|
private ParseResult<ReportData> parseReportAndHandleResult(String emailTitle,
|
|
private ParseResult<ReportData> parseReportAndHandleResult(String emailTitle,
|
|
- EmailFileInfoDO emailFileInfo,
|
|
|
|
|
|
+ Integer fileId,
|
|
EmailZipFileDTO zipFile) {
|
|
EmailZipFileDTO zipFile) {
|
|
Integer emailType = zipFile.getEmailType();
|
|
Integer emailType = zipFile.getEmailType();
|
|
String fileName = zipFile.getFilename();
|
|
String fileName = zipFile.getFilename();
|
|
@@ -487,10 +483,7 @@ public class EmailParseService {
|
|
ParseResult<ReportData> result = new ParseResult<>();
|
|
ParseResult<ReportData> result = new ParseResult<>();
|
|
boolean reportFlag = emailType == null || !EmailTypeConst.SUPPORT_EMAIL_TYPES.contains(emailType);
|
|
boolean reportFlag = emailType == null || !EmailTypeConst.SUPPORT_EMAIL_TYPES.contains(emailType);
|
|
if (reportFlag || StrUtil.isBlank(fileName) || fileName.endsWith(Constants.FILE_HTML)) {
|
|
if (reportFlag || StrUtil.isBlank(fileName) || fileName.endsWith(Constants.FILE_HTML)) {
|
|
- result.setStatus(ReportParseStatus.NOT_A_REPORT.getCode());
|
|
|
|
- result.setMsg(StrUtil.format(ReportParseStatus.NOT_A_REPORT.getMsg(), fileName));
|
|
|
|
- log.error(result.getMsg());
|
|
|
|
- return result;
|
|
|
|
|
|
+ return new ParseResult<>(ReportParseStatus.NOT_A_REPORT, null, fileName);
|
|
}
|
|
}
|
|
// 类型识别---先识别季度报告,没有季度再识别年度报告,最后识别月报
|
|
// 类型识别---先识别季度报告,没有季度再识别年度报告,最后识别月报
|
|
ReportType reportType = ReportParseUtils.matchReportType(emailType, fileName);
|
|
ReportType reportType = ReportParseUtils.matchReportType(emailType, fileName);
|
|
@@ -504,19 +497,12 @@ public class EmailParseService {
|
|
ReportParserFileType fileType = ReportParserFileType.getBySuffix(zipFile.getExtName());
|
|
ReportParserFileType fileType = ReportParserFileType.getBySuffix(zipFile.getExtName());
|
|
// 不支持的格式
|
|
// 不支持的格式
|
|
if (fileType == null) {
|
|
if (fileType == null) {
|
|
- result.setStatus(ReportParseStatus.NO_SUPPORT_TEMPLATE.getCode());
|
|
|
|
- result.setMsg(StrUtil.format(ReportParseStatus.NO_SUPPORT_TEMPLATE.getMsg(), fileName));
|
|
|
|
- log.error(result.getMsg());
|
|
|
|
- return result;
|
|
|
|
|
|
+ return new ParseResult<>(ReportParseStatus.NO_SUPPORT_TEMPLATE, null, fileName);
|
|
}
|
|
}
|
|
// 不是定期报告的判断逻辑放在不支持的格式下面
|
|
// 不是定期报告的判断逻辑放在不支持的格式下面
|
|
if (reportType == null) {
|
|
if (reportType == null) {
|
|
- result.setStatus(ReportParseStatus.NOT_A_REPORT.getCode());
|
|
|
|
- result.setMsg(StrUtil.format(ReportParseStatus.NOT_A_REPORT.getMsg(), fileName));
|
|
|
|
- log.error(result.getMsg());
|
|
|
|
- return result;
|
|
|
|
|
|
+ return new ParseResult<>(ReportParseStatus.NOT_A_REPORT, null, fileName);
|
|
}
|
|
}
|
|
- Integer fileId = emailFileInfo.getId();
|
|
|
|
|
|
|
|
// 首页和尾页转为png图片,首页用来识别基金名称和基金代码、尾页用来识别印章和联系人
|
|
// 首页和尾页转为png图片,首页用来识别基金名称和基金代码、尾页用来识别印章和联系人
|
|
List<String> images = ListUtil.list(true);
|
|
List<String> images = ListUtil.list(true);
|
|
@@ -551,25 +537,21 @@ public class EmailParseService {
|
|
if (reportType != ReportType.OTHER && reportType != ReportType.WEEKLY) {
|
|
if (reportType != ReportType.OTHER && reportType != ReportType.WEEKLY) {
|
|
ReportParser<ReportData> instance = this.reportParserFactory.getInstance(reportType, fileType);
|
|
ReportParser<ReportData> instance = this.reportParserFactory.getInstance(reportType, fileType);
|
|
reportData = instance.parse(params);
|
|
reportData = instance.parse(params);
|
|
- result.setStatus(1);
|
|
|
|
- result.setMsg("报告解析成功");
|
|
|
|
- result.setData(reportData);
|
|
|
|
|
|
+ result = new ParseResult<>(1, "报告解析成功", reportData);
|
|
} else {
|
|
} else {
|
|
if (log.isInfoEnabled()) {
|
|
if (log.isInfoEnabled()) {
|
|
log.info("报告{} 是周报或其他类型,直接用AI解析器解析", fileName);
|
|
log.info("报告{} 是周报或其他类型,直接用AI解析器解析", fileName);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} catch (ReportParseException e) {
|
|
} catch (ReportParseException e) {
|
|
- log.error("解析失败:{}", StrUtil.format(e.getMsg(), fileName));
|
|
|
|
- result.setStatus(e.getCode());
|
|
|
|
- result.setMsg(StrUtil.format(e.getMsg(), fileName));
|
|
|
|
|
|
+ log.warn("解析失败:{}", StrUtil.format(e.getMsg(), fileName));
|
|
|
|
+ result = new ParseResult<>(e.getCode(), StrUtil.format(e.getMsg(), fileName), null);
|
|
if (e instanceof NotSupportReportException) {
|
|
if (e instanceof NotSupportReportException) {
|
|
notSupportFile = true;
|
|
notSupportFile = true;
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
- log.error("解析错误:{}", ExceptionUtil.stacktraceToString(e));
|
|
|
|
- result.setStatus(ReportParseStatus.PARSE_FAIL.getCode());
|
|
|
|
- result.setMsg(StrUtil.format(ReportParseStatus.PARSE_FAIL.getMsg(), e.getMessage()));
|
|
|
|
|
|
+ log.warn("解析错误:{}", ExceptionUtil.stacktraceToString(e));
|
|
|
|
+ result = new ParseResult<>(ReportParseStatus.PARSE_FAIL, null, e.getMessage());
|
|
} finally {
|
|
} finally {
|
|
// 如果解析结果是空的就用AI工具解析一次
|
|
// 如果解析结果是空的就用AI工具解析一次
|
|
if (reportData == null && !notSupportFile) {
|
|
if (reportData == null && !notSupportFile) {
|
|
@@ -587,17 +569,13 @@ public class EmailParseService {
|
|
params = new ReportParserParams(fileId, fileName, filepath, reportType);
|
|
params = new ReportParserParams(fileId, fileName, filepath, reportType);
|
|
ReportParser<ReportData> instance = this.reportParserFactory.getInstance(reportType, ReportParserFileType.AI);
|
|
ReportParser<ReportData> instance = this.reportParserFactory.getInstance(reportType, ReportParserFileType.AI);
|
|
reportData = instance.parse(params);
|
|
reportData = instance.parse(params);
|
|
- result.setStatus(1);
|
|
|
|
- result.setMsg("报告解析成功--AI");
|
|
|
|
- result.setData(reportData);
|
|
|
|
|
|
+ result = new ParseResult<>(1, "报告解析成功--AI", reportData);
|
|
} catch (ReportParseException e) {
|
|
} catch (ReportParseException e) {
|
|
- log.error("AI解析失败:{}", StrUtil.format(e.getMsg(), fileName));
|
|
|
|
- result.setStatus(e.getCode());
|
|
|
|
- result.setMsg(StrUtil.format(e.getMsg(), fileName));
|
|
|
|
|
|
+ log.warn("AI解析失败:{}", StrUtil.format(e.getMsg(), fileName));
|
|
|
|
+ result = new ParseResult<>(e.getCode(), StrUtil.format(e.getMsg(), fileName), null);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
- log.error("AI解析错误:{}", ExceptionUtil.stacktraceToString(e));
|
|
|
|
- result.setStatus(ReportParseStatus.PARSE_FAIL.getCode());
|
|
|
|
- result.setMsg(StrUtil.format(ReportParseStatus.PARSE_FAIL.getMsg(), e.getMessage()));
|
|
|
|
|
|
+ log.warn("AI解析错误:{}", ExceptionUtil.stacktraceToString(e));
|
|
|
|
+ result = new ParseResult<>(ReportParseStatus.PARSE_FAIL, null, e.getMessage());
|
|
}
|
|
}
|
|
if (log.isInfoEnabled()) {
|
|
if (log.isInfoEnabled()) {
|
|
log.info("报告{} AI解析结束!结果是:{}", fileName, reportData);
|
|
log.info("报告{} AI解析结束!结果是:{}", fileName, reportData);
|
|
@@ -979,12 +957,7 @@ public class EmailParseService {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
- String emailDateStr = DateUtil.format(sendDate, DateConst.YYYYMMDD);
|
|
|
|
- String filePath = path + File.separator + account + File.separator + emailDateStr + File.separator + "original" + File.separator;
|
|
|
|
- // 压缩包重名时的后面的压缩包会覆盖前面压缩包的问题(不考虑普通文件)
|
|
|
|
- String emailDate = DateUtil.format(sendDate, DateConst.YYYYMMDDHHMMSS24);
|
|
|
|
- String realName = ArchiveUtil.isArchive(fileName) ? emailDate + fileName : fileName;
|
|
|
|
- File saveFile = FileUtil.file(filePath + realName);
|
|
|
|
|
|
+ File saveFile = this.generateSavePath(account, sendDate, fileName);
|
|
if (!saveFile.exists()) {
|
|
if (!saveFile.exists()) {
|
|
if (!saveFile.getParentFile().exists()) {
|
|
if (!saveFile.getParentFile().exists()) {
|
|
boolean mkdirs = saveFile.getParentFile().mkdirs();
|
|
boolean mkdirs = saveFile.getParentFile().mkdirs();
|
|
@@ -1011,6 +984,16 @@ public class EmailParseService {
|
|
emailContentInfoDTOList.add(emailContentInfoDTO);
|
|
emailContentInfoDTOList.add(emailContentInfoDTO);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public File generateSavePath(String account, Date sendDate, String fileName) {
|
|
|
|
+ String emailDateStr = DateUtil.format(sendDate, DateConst.YYYYMMDD);
|
|
|
|
+ String filePath = this.path + File.separator + account + File.separator +
|
|
|
|
+ emailDateStr + File.separator + "original" + File.separator;
|
|
|
|
+ // 压缩包重名时的后面的压缩包会覆盖前面压缩包的问题(不考虑普通文件)
|
|
|
|
+ String emailDate = DateUtil.format(sendDate, DateConst.YYYYMMDDHHMMSS24);
|
|
|
|
+ String realName = ArchiveUtil.isArchive(fileName) ? emailDate + fileName : fileName;
|
|
|
|
+ return FileUtil.file(filePath + realName);
|
|
|
|
+ }
|
|
|
|
+
|
|
private void reMultipart(String account, String subject, Date emailDate, Multipart multipart,
|
|
private void reMultipart(String account, String subject, Date emailDate, Multipart multipart,
|
|
List<EmailContentInfoDTO> emailContentInfoDTOList) throws Exception {
|
|
List<EmailContentInfoDTO> emailContentInfoDTOList) throws Exception {
|
|
for (int i = 0; i < multipart.getCount(); i++) {
|
|
for (int i = 0; i < multipart.getCount(); i++) {
|