|
@@ -25,6 +25,7 @@ import com.simuwang.base.pojo.dto.report.ReportParserParams;
|
|
|
import com.simuwang.base.pojo.valuation.CmValuationTableAttribute;
|
|
|
import com.simuwang.daq.components.report.parser.ReportParser;
|
|
|
import com.simuwang.daq.components.report.parser.ReportParserFactory;
|
|
|
+import com.simuwang.daq.components.report.writer.ReportWriter;
|
|
|
import com.simuwang.daq.components.report.writer.ReportWriterFactory;
|
|
|
import jakarta.mail.*;
|
|
|
import jakarta.mail.internet.MimeMultipart;
|
|
@@ -36,6 +37,7 @@ import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.StopWatch;
|
|
|
|
|
|
import java.io.File;
|
|
|
import java.math.BigDecimal;
|
|
@@ -87,7 +89,7 @@ public class EmailParseService {
|
|
|
EmailParseInfoMapper emailParseInfoMapper, EmailFileInfoMapper emailFileInfoMapper,
|
|
|
EmailFundNavMapper emailFundNavMapper, EmailFundAssetMapper emailFundAssetMapper,
|
|
|
AssetMapper assetMapper, NavMapper navMapper, FundService fundService,
|
|
|
- FundAliasMapper fundAliasMapper, DaqProperties properties,
|
|
|
+ FundAliasMapper fundAliasMapper,
|
|
|
ValuationTableMapper valuationTableMapper, ValuationTableAttributeMapper valuationTableAttributeMapper,
|
|
|
FundPositionDetailMapper fundPositionDetailMapper) {
|
|
|
this.emailTypeRuleMapper = emailTypeRuleMapper;
|
|
@@ -103,7 +105,6 @@ public class EmailParseService {
|
|
|
this.fundService = fundService;
|
|
|
this.fundAliasMapper = fundAliasMapper;
|
|
|
|
|
|
- this.properties = properties;
|
|
|
this.valuationTableMapper = valuationTableMapper;
|
|
|
this.valuationTableAttributeMapper = valuationTableAttributeMapper;
|
|
|
this.fundPositionDetailMapper = fundPositionDetailMapper;
|
|
@@ -185,12 +186,12 @@ public class EmailParseService {
|
|
|
if (CollUtil.isEmpty(fundNavDTOList) && !Objects.equals(EmailTypeConst.REPORT_EMAIL_TYPE, emailType)) {
|
|
|
continue;
|
|
|
}
|
|
|
- // 解析结果(可以从python获取或者自行解析)
|
|
|
- ReportData data = this.parseReportAndHandleResult(fileId, emailContentInfoDTO);
|
|
|
- if (data != null) {
|
|
|
- // 保存报告解析数据
|
|
|
- this.reportWriterFactory.getInstance(data.getReportType()).write(data);
|
|
|
- dataList.add(data);
|
|
|
+ if (Objects.equals(EmailTypeConst.REPORT_EMAIL_TYPE, emailType)) {
|
|
|
+ // 解析结果(可以从python获取或者自行解析)并保存报告
|
|
|
+ ReportData data = this.parseReportAndHandleResult(fileId, emailContentInfoDTO);
|
|
|
+ if (data != null) {
|
|
|
+ dataList.add(data);
|
|
|
+ }
|
|
|
}
|
|
|
for (EmailFundNavDTO fundNavDTO : fundNavDTOList) {
|
|
|
// 设置净值数据的解析状态
|
|
@@ -354,11 +355,11 @@ public class EmailParseService {
|
|
|
if (matcher.find()) {
|
|
|
registerNumber = matcher.group();
|
|
|
}
|
|
|
- ReportType type = ReportType.MONTHLY;
|
|
|
+ ReportType reportType = ReportType.MONTHLY;
|
|
|
if (fileName.contains(ReportType.QUARTERLY.getLabel())) {
|
|
|
- type = ReportType.QUARTERLY;
|
|
|
+ reportType = ReportType.QUARTERLY;
|
|
|
} else if (fileName.contains(ReportType.ANNUALLY.getLabel())) {
|
|
|
- type = ReportType.ANNUALLY;
|
|
|
+ reportType = ReportType.ANNUALLY;
|
|
|
}
|
|
|
ReportParserFileType fileType;
|
|
|
if (Objects.equals(Boolean.TRUE, this.properties.getEnablePyParser())) {
|
|
@@ -367,10 +368,45 @@ public class EmailParseService {
|
|
|
String fileSuffix = StrUtil.subAfter(fileName, ".", true);
|
|
|
fileType = ReportParserFileType.getBySuffix(fileSuffix);
|
|
|
}
|
|
|
- ReportParser<ReportData> instance = this.reportParserFactory.getInstance(type, fileType);
|
|
|
- ReportParserParams params = ReportParserParams.builder().fileId(fileId).filename(fileName)
|
|
|
- .filepath(emailContentInfoDTO.getFilePath()).registerNumber(registerNumber).build();
|
|
|
- return instance.parse(params);
|
|
|
+ // 解析报告
|
|
|
+ ReportParserParams params = null;
|
|
|
+ ReportData reportData = null;
|
|
|
+ StopWatch parserWatch = new StopWatch();
|
|
|
+ parserWatch.start();
|
|
|
+ try {
|
|
|
+ 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);
|
|
|
+ if (log.isInfoEnabled()) {
|
|
|
+ log.info("报告{}解析器{}的解析结果为:{}", params, instance.getParser(), reportData);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("报告{}解析失败\n{}", params, ExceptionUtil.stacktraceToString(e));
|
|
|
+ } finally {
|
|
|
+ parserWatch.stop();
|
|
|
+ if (log.isInfoEnabled()) {
|
|
|
+ log.info("报告{}解析完成,耗时{}ms", params, parserWatch.getTotalTimeMillis());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 保存报告解析结果
|
|
|
+ StopWatch writeWatch = new StopWatch();
|
|
|
+ writeWatch.start();
|
|
|
+ try {
|
|
|
+ ReportWriter<ReportData> instance = this.reportWriterFactory.getInstance(reportType);
|
|
|
+ instance.write(reportData);
|
|
|
+ if (log.isInfoEnabled()) {
|
|
|
+ log.info("报告{}结果保存成功", params);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("报告{}结果保存失败\n{}", params, ExceptionUtil.stacktraceToString(e));
|
|
|
+ } finally {
|
|
|
+ writeWatch.stop();
|
|
|
+ if (log.isInfoEnabled()) {
|
|
|
+ log.info("报告{}解析结果保存完成,耗时{}ms", params, writeWatch.getTotalTimeMillis());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return reportData;
|
|
|
}
|
|
|
|
|
|
private void saveNavAndAssetNet(Integer fileId, List<EmailFundNavDTO> fundNavDTOList, Date parseDate) {
|