|
@@ -28,9 +28,7 @@ import com.simuwang.base.pojo.dto.report.ReportData;
|
|
|
import com.simuwang.base.pojo.dto.report.ReportParseStatus;
|
|
|
import com.simuwang.base.pojo.dto.report.ReportParserParams;
|
|
|
import com.simuwang.base.pojo.valuation.CmValuationTableAttribute;
|
|
|
-import com.simuwang.base.pojo.vo.EmailParseDataViewVO;
|
|
|
-import com.simuwang.base.pojo.vo.EmailParseFailAnalysisVO;
|
|
|
-import com.simuwang.base.pojo.vo.NameValueVO;
|
|
|
+import com.simuwang.base.pojo.vo.*;
|
|
|
import com.simuwang.daq.components.report.parser.ReportParser;
|
|
|
import com.simuwang.daq.components.report.parser.ReportParserFactory;
|
|
|
import com.simuwang.daq.components.report.writer.ReportWriter;
|
|
@@ -396,13 +394,11 @@ public class EmailParseService {
|
|
|
registerNumber = matcher.group();
|
|
|
}
|
|
|
// 类型识别---先识别季度报告,没有季度再识别年度报告,最后识别月报
|
|
|
- ReportType reportType = null;
|
|
|
+ ReportType reportType = ReportType.MONTHLY;
|
|
|
if (StrUtil.containsAny(fileName, ReportType.QUARTERLY.getPatterns())) {
|
|
|
reportType = ReportType.QUARTERLY;
|
|
|
} else if (StrUtil.containsAny(fileName, ReportType.ANNUALLY.getPatterns())) {
|
|
|
reportType = ReportType.ANNUALLY;
|
|
|
- } else if (StrUtil.containsAny(fileName, ReportType.MONTHLY.getPatterns())) {
|
|
|
- reportType = ReportType.MONTHLY;
|
|
|
}
|
|
|
// 解析器--如果开启python解析则直接调用python接口,否则根据文件后缀获取对应解析器
|
|
|
ReportParserFileType fileType;
|
|
@@ -412,23 +408,13 @@ public class EmailParseService {
|
|
|
String fileSuffix = StrUtil.subAfter(fileName, ".", true);
|
|
|
fileType = ReportParserFileType.getBySuffix(fileSuffix);
|
|
|
}
|
|
|
- if (fileType == null) {
|
|
|
- result.setStatus(ReportParseStatus.NO_SUPPORT_TEMPLATE.getCode());
|
|
|
- result.setMsg(StrUtil.format(ReportParseStatus.NO_SUPPORT_TEMPLATE.getMsg(), fileName));
|
|
|
- return result;
|
|
|
- }
|
|
|
- // 不是定期报告的判断逻辑放在不支持的格式下面
|
|
|
- if (reportType == null) {
|
|
|
- result.setStatus(ReportParseStatus.NOT_A_REPORT.getCode());
|
|
|
- result.setMsg(StrUtil.format(ReportParseStatus.NOT_A_REPORT.getMsg(), fileName));
|
|
|
- return result;
|
|
|
- }
|
|
|
// 解析报告
|
|
|
+ ReportParserParams params = null;
|
|
|
ReportData reportData = null;
|
|
|
StopWatch parserWatch = new StopWatch();
|
|
|
parserWatch.start();
|
|
|
try {
|
|
|
- ReportParserParams params = ReportParserParams.builder().fileId(fileId).filename(fileName)
|
|
|
+ params = ReportParserParams.builder().fileId(fileId).filename(fileName)
|
|
|
.filepath(emailContentInfoDTO.getFilePath()).registerNumber(registerNumber).build();
|
|
|
ReportParser<ReportData> instance = this.reportParserFactory.getInstance(reportType, fileType);
|
|
|
reportData = instance.parse(params);
|
|
@@ -436,17 +422,17 @@ public class EmailParseService {
|
|
|
result.setMsg("报告解析成功");
|
|
|
result.setData(reportData);
|
|
|
} catch (ReportParseException e) {
|
|
|
- log.error("解析失败\n{}", e.getMsg());
|
|
|
+ log.error("报告{}解析失败\n{}", params, e.getMsg());
|
|
|
result.setStatus(e.getCode());
|
|
|
result.setMsg(e.getMsg());
|
|
|
} catch (Exception e) {
|
|
|
- log.error("解析失败\n{}", ExceptionUtil.stacktraceToString(e));
|
|
|
+ log.error("报告{}解析失败\n{}", params, ExceptionUtil.stacktraceToString(e));
|
|
|
result.setStatus(ReportParseStatus.PARSE_FAIL.getCode());
|
|
|
result.setMsg(StrUtil.format(ReportParseStatus.PARSE_FAIL.getMsg(), e.getMessage()));
|
|
|
} finally {
|
|
|
parserWatch.stop();
|
|
|
if (log.isInfoEnabled()) {
|
|
|
- log.info("报告{}解析结果为{},耗时{}ms", fileName, reportData, parserWatch.getTotalTimeMillis());
|
|
|
+ log.info("报告{}解析结果为{},耗时{}ms", params, reportData, parserWatch.getTotalTimeMillis());
|
|
|
}
|
|
|
}
|
|
|
// 保存报告解析结果
|
|
@@ -457,11 +443,11 @@ public class EmailParseService {
|
|
|
ReportWriter<ReportData> instance = this.reportWriterFactory.getInstance(reportType);
|
|
|
instance.write(reportData);
|
|
|
} catch (Exception e) {
|
|
|
- log.error("报告{}结果保存失败\n{}", fileName, ExceptionUtil.stacktraceToString(e));
|
|
|
+ log.error("报告{}结果保存失败\n{}", params, ExceptionUtil.stacktraceToString(e));
|
|
|
} finally {
|
|
|
writeWatch.stop();
|
|
|
if (log.isInfoEnabled()) {
|
|
|
- log.info("报告{}解析结果保存完成,耗时{}ms", fileName, writeWatch.getTotalTimeMillis());
|
|
|
+ log.info("报告{}解析结果保存完成,耗时{}ms", params, writeWatch.getTotalTimeMillis());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -860,14 +846,7 @@ public class EmailParseService {
|
|
|
// 2.邮件只有正文
|
|
|
if (content instanceof String) {
|
|
|
EmailContentInfoDTO emailContentInfoDTO = new EmailContentInfoDTO();
|
|
|
- try {
|
|
|
- //获取邮件编码
|
|
|
- String contentType = message.getContentType();
|
|
|
- contentType = contentType.substring(contentType.indexOf("charset=") + 8, contentType.length());
|
|
|
- emailContentInfoDTO.setEmailContent(new String(content.toString().getBytes(contentType), "UTF-8"));
|
|
|
- } catch (Exception e) {
|
|
|
- emailContentInfoDTO.setEmailContent(content.toString());
|
|
|
- }
|
|
|
+ emailContentInfoDTO.setEmailContent(content.toString());
|
|
|
emailContentInfoDTO.setEmailDate(emailDateStr);
|
|
|
emailContentInfoDTO.setEmailTitle(message.getSubject());
|
|
|
String fileName = message.getSubject() + DateUtil.format(emailDate, DateConst.YYYYMMDDHHMMSS24);
|