|
@@ -25,6 +25,9 @@ import com.smppw.modaq.common.enums.ReportType;
|
|
|
import com.smppw.modaq.common.exception.NotSupportReportException;
|
|
|
import com.smppw.modaq.common.exception.ReportParseException;
|
|
|
import com.smppw.modaq.domain.dto.*;
|
|
|
+import com.smppw.modaq.domain.dto.report.*;
|
|
|
+import com.smppw.modaq.domain.dto.report.ocr.OCRLetterParseData;
|
|
|
+import com.smppw.modaq.domain.dto.report.ocr.OCRParseData;
|
|
|
import com.smppw.modaq.domain.dto.report.ParseResult;
|
|
|
import com.smppw.modaq.domain.dto.report.ReportData;
|
|
|
import com.smppw.modaq.domain.dto.report.ReportParserParams;
|
|
@@ -669,63 +672,95 @@ public class EmailParseService {
|
|
|
// return ReportMonthlyType.FAILED;
|
|
|
// }
|
|
|
|
|
|
-// /**
|
|
|
-// * ocr 提取信息(包括首页的基金名称或报告日期,尾页的印章或联系人等信息)
|
|
|
-// *
|
|
|
-// * @param reportData 报告解析结果
|
|
|
-// * @param fileName 报告名称
|
|
|
-// * @param images 报告的收益和尾页png图片
|
|
|
-// */
|
|
|
-// private void ocrReportData(ReportType reportType,
|
|
|
-// ReportData reportData,
|
|
|
-// String fileName,
|
|
|
-// List<String> images) {
|
|
|
-// if (reportData == null || CollUtil.isEmpty(images)) {
|
|
|
-// return;
|
|
|
-// }
|
|
|
-// OCRParseData parseRes = null;
|
|
|
-// // 报告才识别尾页的印章和联系人,确认单不识别尾页
|
|
|
-// if (ReportType.LETTER != reportType) {
|
|
|
-// try {
|
|
|
-// // 首页和尾页相等时只读首页
|
|
|
-// String imageUrl = images.size() == 1 ? images.get(0) : images.get(1);
|
|
|
-// parseRes = new OCRReportParser().parse(fileName, this.ocrParserUrl, imageUrl);
|
|
|
-// } catch (Exception e) {
|
|
|
-// log.error("报告{} OCR识别印章和联系人出错:{}", fileName, e.getMessage());
|
|
|
-// }
|
|
|
-// // ocr识别尾页是否包含印章和联系人信息
|
|
|
-// if (parseRes != null) {
|
|
|
-// if (reportData.getBaseInfo() != null) {
|
|
|
-// reportData.getBaseInfo().setWithSeals(parseRes.getWithSeals());
|
|
|
-// reportData.getBaseInfo().setWithContacts(parseRes.getWithContacts());
|
|
|
-// if (fileName.contains("用印") && !Objects.equals(true, reportData.getBaseInfo().getWithSeals())) {
|
|
|
-// reportData.getBaseInfo().setWithSeals(true);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// // 首页和尾页不相等时解析首页的数据
|
|
|
-// if (images.size() != 1) {
|
|
|
-// try {
|
|
|
-// parseRes = new OCRReportParser().parse(fileName, this.ocrParserUrl, images.get(0));
|
|
|
-// } catch (Exception e) {
|
|
|
-// log.error("报告{} OCR识别首页基金名称和报告日期出错:{}", fileName, e.getMessage());
|
|
|
-// }
|
|
|
-// }
|
|
|
-// // 用首页识别基金名称、产品代码和基金管理人
|
|
|
-// if (reportData.getFundInfo() != null && parseRes != null) {
|
|
|
-// if (StrUtil.isBlank(reportData.getFundInfo().getFundName())) {
|
|
|
-// reportData.getFundInfo().setFundName(parseRes.getFundName());
|
|
|
-// }
|
|
|
-// if (StrUtil.isBlank(reportData.getFundInfo().getFundCode())) {
|
|
|
-// reportData.getFundInfo().setFundCode(parseRes.getFundCode());
|
|
|
-// }
|
|
|
-// if (StrUtil.isBlank(reportData.getFundInfo().getCompanyName())
|
|
|
-// || !reportData.getFundInfo().getCompanyName().contains("有限公司")) {
|
|
|
-// reportData.getFundInfo().setCompanyName(parseRes.getCompanyName());
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
+ /**
|
|
|
+ * ocr 提取信息(包括首页的基金名称或报告日期,尾页的印章或联系人等信息)
|
|
|
+ *
|
|
|
+ * @param reportData 报告解析结果
|
|
|
+ * @param fileName 报告名称
|
|
|
+ * @param images 报告的收益和尾页png图片
|
|
|
+ */
|
|
|
+ private void ocrReportData(ReportType reportType,
|
|
|
+ ReportData reportData,
|
|
|
+ String fileName,
|
|
|
+ List<String> images) {
|
|
|
+ if (reportData == null || CollUtil.isEmpty(images)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 报告才识别尾页的印章和联系人,确认单不识别尾页
|
|
|
+ if (ReportType.LETTER != reportType) {
|
|
|
+ OCRParseData parseRes = null;
|
|
|
+ try {
|
|
|
+ // 首页和尾页相等时只读首页
|
|
|
+ String imageUrl = images.size() == 1 ? images.get(0) : images.get(1);
|
|
|
+ parseRes = new OCRReportParser().parse(fileName, this.ocrParserUrl, imageUrl);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("报告{} OCR识别印章和联系人出错:{}", fileName, e.getMessage());
|
|
|
+ }
|
|
|
+ // ocr识别尾页是否包含印章和联系人信息
|
|
|
+ if (parseRes != null) {
|
|
|
+ if (reportData.getBaseInfo() != null) {
|
|
|
+ reportData.getBaseInfo().setWithSeals(parseRes.getWithSeals());
|
|
|
+ reportData.getBaseInfo().setWithContacts(parseRes.getWithContacts());
|
|
|
+ if (fileName.contains("用印") && !Objects.equals(true, reportData.getBaseInfo().getWithSeals())) {
|
|
|
+ reportData.getBaseInfo().setWithSeals(true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 首页和尾页不相等时解析首页的数据
|
|
|
+ if (images.size() != 1) {
|
|
|
+ try {
|
|
|
+ parseRes = new OCRReportParser().parse(fileName, this.ocrParserUrl, images.get(0));
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("报告{} OCR识别首页基金名称和报告日期出错:{}", fileName, e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 用首页识别基金名称、产品代码和基金管理人
|
|
|
+ if (reportData.getFundInfo() != null && parseRes != null) {
|
|
|
+ if (StrUtil.isBlank(reportData.getFundInfo().getFundName())) {
|
|
|
+ reportData.getFundInfo().setFundName(parseRes.getFundName());
|
|
|
+ }
|
|
|
+ if (StrUtil.isBlank(reportData.getFundInfo().getFundCode())) {
|
|
|
+ reportData.getFundInfo().setFundCode(parseRes.getFundCode());
|
|
|
+ }
|
|
|
+ if (StrUtil.isBlank(reportData.getFundInfo().getCompanyName())
|
|
|
+ || !reportData.getFundInfo().getCompanyName().contains("有限公司")) {
|
|
|
+ reportData.getFundInfo().setCompanyName(parseRes.getCompanyName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 确认单AI解析失败时重新用OCR识别
|
|
|
+ LetterReportData letterReportData = (LetterReportData) reportData;
|
|
|
+ if (letterReportData.wasFailed()) {
|
|
|
+ OCRLetterParseData parseRes = new OCRReportParser().parseLetterData(fileName, this.ocrParserUrl, images.get(0));
|
|
|
+ if (parseRes == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (letterReportData.getFundInfo() != null) {
|
|
|
+ letterReportData.getFundInfo().setFundName(parseRes.getFundName());
|
|
|
+ letterReportData.getFundInfo().setFundCode(parseRes.getFundCode());
|
|
|
+ }
|
|
|
+ if (letterReportData.getInvestorInfo() == null) {
|
|
|
+ letterReportData.setInvestorInfo(new ReportInvestorInfoDTO());
|
|
|
+ }
|
|
|
+ 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());
|
|
|
+ }
|
|
|
+ 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());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 保存报告解析结果
|