|
@@ -8,6 +8,8 @@ import cn.hutool.core.io.FileUtil;
|
|
import cn.hutool.core.map.MapUtil;
|
|
import cn.hutool.core.map.MapUtil;
|
|
import cn.hutool.core.util.IdUtil;
|
|
import cn.hutool.core.util.IdUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.smppw.modaq.application.components.OCRReportParser;
|
|
import com.smppw.modaq.application.components.OCRReportParser;
|
|
import com.smppw.modaq.application.components.ReportParseUtils;
|
|
import com.smppw.modaq.application.components.ReportParseUtils;
|
|
import com.smppw.modaq.application.components.report.parser.ReportParser;
|
|
import com.smppw.modaq.application.components.report.parser.ReportParser;
|
|
@@ -31,8 +33,10 @@ 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.ocr.OCRParseData;
|
|
import com.smppw.modaq.domain.entity.EmailFileInfoDO;
|
|
import com.smppw.modaq.domain.entity.EmailFileInfoDO;
|
|
import com.smppw.modaq.domain.entity.EmailParseInfoDO;
|
|
import com.smppw.modaq.domain.entity.EmailParseInfoDO;
|
|
|
|
+import com.smppw.modaq.domain.entity.TgEmailConfigDO;
|
|
import com.smppw.modaq.domain.mapper.EmailFileInfoMapper;
|
|
import com.smppw.modaq.domain.mapper.EmailFileInfoMapper;
|
|
import com.smppw.modaq.domain.mapper.EmailParseInfoMapper;
|
|
import com.smppw.modaq.domain.mapper.EmailParseInfoMapper;
|
|
|
|
+import com.smppw.modaq.domain.mapper.TgEmailConfigMapper;
|
|
import com.smppw.modaq.infrastructure.util.ArchiveUtil;
|
|
import com.smppw.modaq.infrastructure.util.ArchiveUtil;
|
|
import com.smppw.modaq.infrastructure.util.ConvertUtil;
|
|
import com.smppw.modaq.infrastructure.util.ConvertUtil;
|
|
import com.smppw.modaq.infrastructure.util.PdfUtil;
|
|
import com.smppw.modaq.infrastructure.util.PdfUtil;
|
|
@@ -84,6 +88,9 @@ public class EmailParseService {
|
|
// 按需添加其他类型...
|
|
// 按需添加其他类型...
|
|
);
|
|
);
|
|
|
|
|
|
|
|
+ private static final List<String> TG_EMAIL_LIST = ListUtil.list(false);
|
|
|
|
+
|
|
|
|
+ private final TgEmailConfigMapper tgEmailConfigMapper;
|
|
private final EmailParseInfoMapper emailParseInfoMapper;
|
|
private final EmailParseInfoMapper emailParseInfoMapper;
|
|
private final EmailFileInfoMapper emailFileInfoMapper;
|
|
private final EmailFileInfoMapper emailFileInfoMapper;
|
|
/* 报告解析和入库的方法 */
|
|
/* 报告解析和入库的方法 */
|
|
@@ -100,14 +107,25 @@ public class EmailParseService {
|
|
@Value("${email.read-write-seen:true}")
|
|
@Value("${email.read-write-seen:true}")
|
|
private boolean readWriteSeen;
|
|
private boolean readWriteSeen;
|
|
|
|
|
|
- public EmailParseService(EmailParseInfoMapper emailParseInfoMapper,
|
|
|
|
|
|
+ public EmailParseService(TgEmailConfigMapper tgEmailConfigMapper,
|
|
|
|
+ EmailParseInfoMapper emailParseInfoMapper,
|
|
EmailFileInfoMapper emailFileInfoMapper,
|
|
EmailFileInfoMapper emailFileInfoMapper,
|
|
ReportParserFactory reportParserFactory,
|
|
ReportParserFactory reportParserFactory,
|
|
ReportWriterFactory reportWriterFactory) {
|
|
ReportWriterFactory reportWriterFactory) {
|
|
|
|
+ this.tgEmailConfigMapper = tgEmailConfigMapper;
|
|
this.emailParseInfoMapper = emailParseInfoMapper;
|
|
this.emailParseInfoMapper = emailParseInfoMapper;
|
|
this.emailFileInfoMapper = emailFileInfoMapper;
|
|
this.emailFileInfoMapper = emailFileInfoMapper;
|
|
this.reportParserFactory = reportParserFactory;
|
|
this.reportParserFactory = reportParserFactory;
|
|
this.reportWriterFactory = reportWriterFactory;
|
|
this.reportWriterFactory = reportWriterFactory;
|
|
|
|
+ this.init();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void init() {
|
|
|
|
+ LambdaQueryWrapper<TgEmailConfigDO> wrapper = Wrappers.lambdaQuery(TgEmailConfigDO.class);
|
|
|
|
+ List<TgEmailConfigDO> dataList = this.tgEmailConfigMapper.selectList(wrapper);
|
|
|
|
+ for (TgEmailConfigDO temp : dataList) {
|
|
|
|
+ TG_EMAIL_LIST.add(temp.getEmail());
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -120,7 +138,8 @@ public class EmailParseService {
|
|
*/
|
|
*/
|
|
public void parseEmail(MailboxInfoDTO mailboxInfoDTO,
|
|
public void parseEmail(MailboxInfoDTO mailboxInfoDTO,
|
|
Date startDate, Date endDate,
|
|
Date startDate, Date endDate,
|
|
- List<String> folderNames, List<Integer> emailTypes) {
|
|
|
|
|
|
+ List<String> folderNames,
|
|
|
|
+ List<Integer> emailTypes) {
|
|
if (CollUtil.isEmpty(emailTypes)) {
|
|
if (CollUtil.isEmpty(emailTypes)) {
|
|
emailTypes = ListUtil.of(EmailTypeConst.REPORT_LETTER_EMAIL_TYPE);
|
|
emailTypes = ListUtil.of(EmailTypeConst.REPORT_LETTER_EMAIL_TYPE);
|
|
}
|
|
}
|
|
@@ -148,44 +167,70 @@ public class EmailParseService {
|
|
}
|
|
}
|
|
EmailContentInfoDTO dto = emailContentInfoDTOList.get(0);
|
|
EmailContentInfoDTO dto = emailContentInfoDTOList.get(0);
|
|
String emailTitle = dto.getEmailTitle();
|
|
String emailTitle = dto.getEmailTitle();
|
|
- log.info("开始解析邮件数据 -> 邮件主题:{},邮件日期:{}", emailTitle, dto.getEmailDate());
|
|
|
|
|
|
+ if (log.isInfoEnabled()) {
|
|
|
|
+ log.info("开始解析邮件数据 -> 邮件主题:{},邮件日期:{}", emailTitle, dto.getEmailDate());
|
|
|
|
+ }
|
|
|
|
+ Long totalSize = emailContentInfoDTOList.stream().map(EmailContentInfoDTO::getFileSize).reduce(0L, Long::sum);
|
|
|
|
+ String errMsg = null;
|
|
|
|
+ int status = 1;
|
|
List<EmailZipFileDTO> emailFileList = ListUtil.list(false);
|
|
List<EmailZipFileDTO> emailFileList = ListUtil.list(false);
|
|
EmailInfoDTO emailInfo = new EmailInfoDTO(dto, emailFileList);
|
|
EmailInfoDTO emailInfo = new EmailInfoDTO(dto, emailFileList);
|
|
- for (EmailContentInfoDTO emailDto : emailContentInfoDTOList) {
|
|
|
|
- // 正文不用解压附件
|
|
|
|
- if (emailDto.getFileName() != null && emailDto.getFileName().endsWith(Constants.FILE_HTML)) {
|
|
|
|
- continue;
|
|
|
|
|
|
+ if (dto.getEmailContent() != null && dto.getEmailContent().contains("超大附件列表")) {
|
|
|
|
+ status = 0;
|
|
|
|
+ errMsg = "邮件中存在超大附件,需要手动处理该邮件";
|
|
|
|
+ } else {
|
|
|
|
+ for (EmailContentInfoDTO emailDto : emailContentInfoDTOList) {
|
|
|
|
+ // 正文不用解压附件
|
|
|
|
+ if (emailDto.getFileName() != null && emailDto.getFileName().endsWith(Constants.FILE_HTML)) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ try {
|
|
|
|
+ emailFileList.addAll(this.parseZipEmail(emailDto));
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ log.error("邮件{} 压缩包解压失败:{}", emailTitle, ExceptionUtil.stacktraceToString(e));
|
|
|
|
+ status = 0;
|
|
|
|
+ errMsg = "压缩包解压失败";
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.error("邮件{} 堆栈信息:{}", emailTitle, ExceptionUtil.stacktraceToString(e));
|
|
|
|
+ status = 0;
|
|
|
|
+ errMsg = "内部错误";
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- try {
|
|
|
|
- emailFileList.addAll(this.parseZipEmail(emailDto));
|
|
|
|
- } catch (IOException e) {
|
|
|
|
- log.error("压缩包解压失败:{}", ExceptionUtil.stacktraceToString(e));
|
|
|
|
- EmailParseInfoDO fail = buildEmailParseInfo(mailboxInfoDTO.getAccount(),
|
|
|
|
- dto.getEmailType(), emailInfo, emailDto.getFileSize());
|
|
|
|
- fail.setFailReason("压缩包解压失败");
|
|
|
|
- fail.setParseStatus(EmailParseStatusConst.FAIL);
|
|
|
|
- fail.setEmailKey(emailEntry.getKey());
|
|
|
|
- this.emailParseInfoMapper.insert(fail);
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- log.error("堆栈信息:{}", ExceptionUtil.stacktraceToString(e));
|
|
|
|
|
|
+ // 重新判断类型
|
|
|
|
+ this.recheckEmailType(emailTitle, emailFileList);
|
|
|
|
+ Iterator<EmailZipFileDTO> entryIterator = emailFileList.iterator();
|
|
|
|
+ while (entryIterator.hasNext()) {
|
|
|
|
+ EmailZipFileDTO entry = entryIterator.next();
|
|
|
|
+ if (!emailTypes.contains(entry.getEmailType())) {
|
|
|
|
+ log.warn("当前邮件{} 中的报告{} 的类型{} 不在支持的任务类型{} 中,不用执行解析逻辑。",
|
|
|
|
+ entry.getEmailTitle(), entry.getFilename(), entry.getEmailType(), emailTypes);
|
|
|
|
+ entryIterator.remove();
|
|
|
|
+ }
|
|
|
|
+ ReportParserFileType fileType = ReportParserFileType.getBySuffix(entry.getExtName());
|
|
|
|
+ if (fileType == null) {
|
|
|
|
+ log.warn("当前邮件{} 中的文件{} 是不支持的文件格式{} 中,不用执行解析逻辑。",
|
|
|
|
+ entry.getEmailTitle(), entry.getFilepath(), entry.getExtName());
|
|
|
|
+ entryIterator.remove();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- // 重新判断类型
|
|
|
|
- this.recheckEmailType(emailTitle, emailFileList);
|
|
|
|
- Iterator<EmailZipFileDTO> entryIterator = emailFileList.iterator();
|
|
|
|
- while (entryIterator.hasNext()) {
|
|
|
|
- EmailZipFileDTO entry = entryIterator.next();
|
|
|
|
- if (!emailTypes.contains(entry.getEmailType())) {
|
|
|
|
- log.warn("当前邮件{} 文件{} 的类型{} 不在支持的任务类型{} 中,不用执行解析逻辑。",
|
|
|
|
- entry.getEmailTitle(), entry.getFilepath(), entry.getEmailType(), emailTypes);
|
|
|
|
- entryIterator.remove();
|
|
|
|
- }
|
|
|
|
|
|
+ // 保存邮件信息
|
|
|
|
+ EmailParseInfoDO emailDo = this.buildEmailParseInfo(mailboxInfoDTO.getAccount(), emailInfo, totalSize);
|
|
|
|
+ emailDo.setEmailKey(emailEntry.getKey());
|
|
|
|
+ emailDo.setParseStatus(status);
|
|
|
|
+ emailDo.setFailReason(errMsg);
|
|
|
|
+ Integer emailId = this.saveEmailParseInfo(emailDo);
|
|
|
|
+ // 保存附件(解压后的)
|
|
|
|
+ for (EmailZipFileDTO zipFile : emailFileList) {
|
|
|
|
+ EmailFileInfoDO emailFile = this.saveEmailFileInfo(emailId, zipFile.getFilename(), zipFile.getFilepath());
|
|
|
|
+ zipFile.setFileId(emailFile.getId());
|
|
|
|
+ }
|
|
|
|
+ if (CollUtil.isNotEmpty(emailFileList)) {
|
|
|
|
+ // 保存相关信息 -> 邮件信息表,邮件文件表,邮件净值表,邮件规模表,基金净值表
|
|
|
|
+ this.saveRelatedTable(emailId, emailInfo);
|
|
|
|
+ log.info("结束邮件解析 -> 邮箱信息:{},开始时间:{},结束时间:{}", emailEntry.getValue(),
|
|
|
|
+ DateUtil.format(startDate, DateConst.YYYY_MM_DD_HH_MM_SS), DateUtil.format(endDate, DateConst.YYYY_MM_DD_HH_MM_SS));
|
|
}
|
|
}
|
|
-
|
|
|
|
- // 保存相关信息 -> 邮件信息表,邮件文件表,邮件净值表,邮件规模表,基金净值表
|
|
|
|
- saveRelatedTable(emailEntry.getKey(), mailboxInfoDTO.getAccount(), emailInfo);
|
|
|
|
- log.info("结束邮件解析 -> 邮箱信息:{},开始时间:{},结束时间:{}", emailEntry.getValue(),
|
|
|
|
- DateUtil.format(startDate, DateConst.YYYY_MM_DD_HH_MM_SS), DateUtil.format(endDate, DateConst.YYYY_MM_DD_HH_MM_SS));
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -278,33 +323,20 @@ public class EmailParseService {
|
|
/**
|
|
/**
|
|
* 邮件附件解析并保存结果数据
|
|
* 邮件附件解析并保存结果数据
|
|
*
|
|
*
|
|
- * @param emailKey 没封邮件的uuid
|
|
|
|
- * @param emailAddress 发送人地址
|
|
|
|
- * @param emailInfo 邮件信息
|
|
|
|
|
|
+ * @param emailId 邮件数据ID
|
|
|
|
+ * @param emailInfo 邮件信息
|
|
*/
|
|
*/
|
|
- public void saveRelatedTable(String emailKey, String emailAddress, EmailInfoDTO emailInfo) {
|
|
|
|
- // 附件文件检查
|
|
|
|
- Long totalSize = this.checkEmailFileInfo(emailInfo);
|
|
|
|
- if (totalSize == null) {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
|
|
+ public void saveRelatedTable(Integer emailId, EmailInfoDTO emailInfo) {
|
|
// 解析并保存数据
|
|
// 解析并保存数据
|
|
List<ParseResult<ReportData>> dataList = ListUtil.list(true);
|
|
List<ParseResult<ReportData>> dataList = ListUtil.list(true);
|
|
- Integer emailId = this.parseResults(null, emailKey, emailAddress, totalSize, emailInfo, dataList);
|
|
|
|
|
|
+ this.parseResults(emailInfo, dataList);
|
|
|
|
|
|
String failReason = null;
|
|
String failReason = null;
|
|
int emailParseStatus = EmailParseStatusConst.SUCCESS;
|
|
int emailParseStatus = EmailParseStatusConst.SUCCESS;
|
|
// 报告邮件有一条失败就表示整个邮件解析失败
|
|
// 报告邮件有一条失败就表示整个邮件解析失败
|
|
if (CollUtil.isNotEmpty(dataList)) {
|
|
if (CollUtil.isNotEmpty(dataList)) {
|
|
- // ai解析结果
|
|
|
|
- List<ReportData> aiParaseList = dataList.stream().map(ParseResult::getData)
|
|
|
|
- .filter(Objects::nonNull).filter(e -> Objects.equals(true, e.getAiParse())).toList();
|
|
|
|
- if (CollUtil.isNotEmpty(aiParaseList)) {
|
|
|
|
- for (ReportData data : aiParaseList) {
|
|
|
|
- this.emailFileInfoMapper.updateAiParseByFileId(data.getBaseInfo().getFileId(),
|
|
|
|
- data.getAiParse(), data.getAiFileId());
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ List<EmailFileInfoDO> entityList = this.buildEmailFileInfo(dataList);
|
|
|
|
+ this.emailFileInfoMapper.batchUpdateByFileId(entityList);
|
|
long failNum = dataList.stream().filter(e -> !Objects.equals(EmailParseStatusConst.SUCCESS, e.getStatus())).count();
|
|
long failNum = dataList.stream().filter(e -> !Objects.equals(EmailParseStatusConst.SUCCESS, e.getStatus())).count();
|
|
if (failNum > 0) {
|
|
if (failNum > 0) {
|
|
emailParseStatus = EmailParseStatusConst.FAIL;
|
|
emailParseStatus = EmailParseStatusConst.FAIL;
|
|
@@ -314,6 +346,20 @@ public class EmailParseService {
|
|
this.emailParseInfoMapper.updateParseStatus(emailId, emailParseStatus, failReason);
|
|
this.emailParseInfoMapper.updateParseStatus(emailId, emailParseStatus, failReason);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private List<EmailFileInfoDO> buildEmailFileInfo(List<ParseResult<ReportData>> dataList) {
|
|
|
|
+ List<EmailFileInfoDO> entityList = ListUtil.list(false);
|
|
|
|
+ for (ParseResult<ReportData> result : dataList) {
|
|
|
|
+ EmailFileInfoDO entity = new EmailFileInfoDO();
|
|
|
|
+ entity.setId(result.getData().getBaseInfo().getFileId());
|
|
|
|
+ entity.setParseStatus(result.getStatus());
|
|
|
|
+ entity.setFailReason(result.getMsg());
|
|
|
|
+ entity.setAiParse(result.getData().getAiParse());
|
|
|
|
+ entity.setAiFileId(result.getData().getAiFileId());
|
|
|
|
+ entityList.add(entity);
|
|
|
|
+ }
|
|
|
|
+ return entityList;
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 上传文件解析并返回解析状态
|
|
* 上传文件解析并返回解析状态
|
|
*
|
|
*
|
|
@@ -343,12 +389,19 @@ public class EmailParseService {
|
|
// 重新判断类型
|
|
// 重新判断类型
|
|
this.recheckEmailType(emailTitle, dtos);
|
|
this.recheckEmailType(emailTitle, dtos);
|
|
EmailInfoDTO emailInfo = new EmailInfoDTO(emailTitle, dtos);
|
|
EmailInfoDTO emailInfo = new EmailInfoDTO(emailTitle, dtos);
|
|
- // 附件文件检查
|
|
|
|
- Long totalSize = this.checkEmailFileInfo(emailInfo);
|
|
|
|
- if (totalSize == null) {
|
|
|
|
- return null;
|
|
|
|
|
|
+// // 附件文件检查
|
|
|
|
+// Long totalSize = this.checkEmailFileInfo(emailInfo);
|
|
|
|
+// if (totalSize == null) {
|
|
|
|
+// return null;
|
|
|
|
+// }
|
|
|
|
+ Long totalSize = dtos.stream().map(EmailZipFileDTO::getFileSize).reduce(0L, Long::sum);
|
|
|
|
+ EmailParseInfoDO emailDo = this.buildEmailParseInfo("upload", emailInfo, totalSize);
|
|
|
|
+ Integer emailId = this.saveEmailParseInfo(emailDo);
|
|
|
|
+ for (EmailZipFileDTO zipFile : dtos) {
|
|
|
|
+ EmailFileInfoDO emailFile = this.saveEmailFileInfo(emailId, zipFile.getFilename(), zipFile.getFilepath());
|
|
|
|
+ zipFile.setFileId(emailFile.getId());
|
|
}
|
|
}
|
|
- this.parseResults(-1, null, null, totalSize, emailInfo, dataList);
|
|
|
|
|
|
+ this.parseResults(emailInfo, dataList);
|
|
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();
|
|
@@ -382,9 +435,8 @@ public class EmailParseService {
|
|
* 邮件信息前置处理,在解析操作执行之前的过滤逻辑和校验逻辑。返回所有附件大小汇总
|
|
* 邮件信息前置处理,在解析操作执行之前的过滤逻辑和校验逻辑。返回所有附件大小汇总
|
|
*
|
|
*
|
|
* @param emailInfo 邮件信息(包含所有解压后的文件)
|
|
* @param emailInfo 邮件信息(包含所有解压后的文件)
|
|
- * @return 所有附件大小汇总,为null说明没有文件需要上传
|
|
|
|
*/
|
|
*/
|
|
- private Long checkEmailFileInfo(EmailInfoDTO emailInfo) {
|
|
|
|
|
|
+ private void checkEmailFileInfo(EmailInfoDTO emailInfo) {
|
|
String emailTitle = emailInfo.getEmailTitle();
|
|
String emailTitle = emailInfo.getEmailTitle();
|
|
List<EmailZipFileDTO> dtos = emailInfo.getEmailFileList();
|
|
List<EmailZipFileDTO> dtos = emailInfo.getEmailFileList();
|
|
// 如果压缩包里面既有pdf又有其他格式的文件,说明其他格式的文件是不需要解析的
|
|
// 如果压缩包里面既有pdf又有其他格式的文件,说明其他格式的文件是不需要解析的
|
|
@@ -437,45 +489,34 @@ public class EmailParseService {
|
|
}
|
|
}
|
|
if (CollUtil.isEmpty(dtos)) {
|
|
if (CollUtil.isEmpty(dtos)) {
|
|
log.info("邮件{} 所有文件都已经解析成功过,不能重复解析了", emailTitle);
|
|
log.info("邮件{} 所有文件都已经解析成功过,不能重复解析了", emailTitle);
|
|
- return null;
|
|
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
if (log.isInfoEnabled()) {
|
|
if (log.isInfoEnabled()) {
|
|
log.info("邮件{} 还有报告待解析:\n{}", emailTitle, dtos);
|
|
log.info("邮件{} 还有报告待解析:\n{}", emailTitle, dtos);
|
|
}
|
|
}
|
|
- return totalSize;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* 邮件信息保存+附件解析
|
|
* 邮件信息保存+附件解析
|
|
*
|
|
*
|
|
- * @param emailId 邮件ID,上传解析时一定是-1
|
|
|
|
- * @param emailKey 邮件uuid(邮箱下载解析时)
|
|
|
|
- * @param emailAddress 接收人地址(邮箱下载解析时)
|
|
|
|
- * @param totalSize 所有附件大小汇总
|
|
|
|
- * @param emailInfo 邮件信息,包含附件
|
|
|
|
- * @param resultList 解析结果
|
|
|
|
- * @return 邮件数据ID
|
|
|
|
|
|
+ * @param emailInfo 邮件信息,包含附件
|
|
|
|
+ * @param resultList 解析结果
|
|
*/
|
|
*/
|
|
- private Integer parseResults(Integer emailId,
|
|
|
|
- String emailKey,
|
|
|
|
- String emailAddress,
|
|
|
|
- long totalSize,
|
|
|
|
- EmailInfoDTO emailInfo,
|
|
|
|
- List<ParseResult<ReportData>> resultList) {
|
|
|
|
|
|
+ private void parseResults(EmailInfoDTO emailInfo,
|
|
|
|
+ List<ParseResult<ReportData>> resultList) {
|
|
String emailTitle = emailInfo.getEmailTitle();
|
|
String emailTitle = emailInfo.getEmailTitle();
|
|
|
|
+ String senderEmail = emailInfo.getSenderEmail();
|
|
List<EmailZipFileDTO> dtos = emailInfo.getEmailFileList();
|
|
List<EmailZipFileDTO> dtos = emailInfo.getEmailFileList();
|
|
- if (emailId == null) {
|
|
|
|
- // 保存邮件信息
|
|
|
|
- Integer emailType = dtos.get(0).getEmailType();
|
|
|
|
- EmailParseInfoDO emailParseInfoDO = this.buildEmailParseInfo(emailAddress, emailType, emailInfo, totalSize);
|
|
|
|
- emailParseInfoDO.setEmailKey(emailKey);
|
|
|
|
- emailId = this.saveEmailParseInfo(emailParseInfoDO);
|
|
|
|
|
|
+ if (CollUtil.isEmpty(dtos)) {
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
|
|
+ // 附件文件检查
|
|
|
|
+ this.checkEmailFileInfo(emailInfo);
|
|
// 解析邮件报告
|
|
// 解析邮件报告
|
|
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.getId(), zipFile);
|
|
|
|
|
|
+ ParseResult<ReportData> parseResult = this.parseReportAndHandleResult(emailTitle, senderEmail, zipFile);
|
|
if (!Objects.equals(1, parseResult.getStatus())) {
|
|
if (!Objects.equals(1, parseResult.getStatus())) {
|
|
log.error(parseResult.getMsg());
|
|
log.error(parseResult.getMsg());
|
|
}
|
|
}
|
|
@@ -485,20 +526,19 @@ public class EmailParseService {
|
|
parseResult.getData().setReportPath(zipFile.getFilepath());
|
|
parseResult.getData().setReportPath(zipFile.getFilepath());
|
|
resultList.add(parseResult);
|
|
resultList.add(parseResult);
|
|
}
|
|
}
|
|
- return emailId;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* 解析报告并保存解析结果
|
|
* 解析报告并保存解析结果
|
|
*
|
|
*
|
|
* @param emailTitle 邮件主题
|
|
* @param emailTitle 邮件主题
|
|
- * @param fileId 当前文件数据库ID
|
|
|
|
* @param zipFile 当前报告的路径信息
|
|
* @param zipFile 当前报告的路径信息
|
|
* @return /
|
|
* @return /
|
|
*/
|
|
*/
|
|
private ParseResult<ReportData> parseReportAndHandleResult(String emailTitle,
|
|
private ParseResult<ReportData> parseReportAndHandleResult(String emailTitle,
|
|
- Integer fileId,
|
|
|
|
|
|
+ String senderEmail,
|
|
EmailZipFileDTO zipFile) {
|
|
EmailZipFileDTO zipFile) {
|
|
|
|
+ Integer fileId = zipFile.getFileId();
|
|
Integer emailType = zipFile.getEmailType();
|
|
Integer emailType = zipFile.getEmailType();
|
|
String fileName = zipFile.getFilename();
|
|
String fileName = zipFile.getFilename();
|
|
String filepath = zipFile.getFilepath();
|
|
String filepath = zipFile.getFilepath();
|
|
@@ -618,7 +658,7 @@ public class EmailParseService {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// ocr信息提取(印章、联系人、基金名称和产品代码)
|
|
// ocr信息提取(印章、联系人、基金名称和产品代码)
|
|
- reportData = this.ocrReportData(fileId, reportType, reportData, fileName, images);
|
|
|
|
|
|
+ reportData = this.ocrReportData(fileId, reportType, reportData, fileName, senderEmail, images);
|
|
if (log.isInfoEnabled()) {
|
|
if (log.isInfoEnabled()) {
|
|
log.info("报告{} 解析耗时{}ms,结果是:{}", fileName, (System.currentTimeMillis() - start), reportData);
|
|
log.info("报告{} 解析耗时{}ms,结果是:{}", fileName, (System.currentTimeMillis() - start), reportData);
|
|
}
|
|
}
|
|
@@ -690,6 +730,7 @@ public class EmailParseService {
|
|
ReportType reportType,
|
|
ReportType reportType,
|
|
ReportData reportData,
|
|
ReportData reportData,
|
|
String fileName,
|
|
String fileName,
|
|
|
|
+ String senderEmail,
|
|
List<String> images) {
|
|
List<String> images) {
|
|
if (CollUtil.isEmpty(images)) {
|
|
if (CollUtil.isEmpty(images)) {
|
|
return reportData;
|
|
return reportData;
|
|
@@ -710,14 +751,16 @@ public class EmailParseService {
|
|
log.error("报告{} OCR识别印章和联系人出错:{}", fileName, e.getMessage());
|
|
log.error("报告{} OCR识别印章和联系人出错:{}", fileName, e.getMessage());
|
|
}
|
|
}
|
|
// ocr识别尾页是否包含印章和联系人信息
|
|
// ocr识别尾页是否包含印章和联系人信息
|
|
- if (parseRes != null) {
|
|
|
|
- if (reportData.getBaseInfo() != null) {
|
|
|
|
|
|
+ if (parseRes != null && reportData.getBaseInfo() != null) {
|
|
|
|
+ if (TG_EMAIL_LIST.contains(senderEmail)) {
|
|
|
|
+ reportData.getBaseInfo().setWithSeals(true);
|
|
|
|
+ } else {
|
|
reportData.getBaseInfo().setWithSeals(parseRes.getWithSeals());
|
|
reportData.getBaseInfo().setWithSeals(parseRes.getWithSeals());
|
|
- reportData.getBaseInfo().setWithContacts(parseRes.getWithContacts());
|
|
|
|
if (fileName.contains("用印") && !Objects.equals(true, reportData.getBaseInfo().getWithSeals())) {
|
|
if (fileName.contains("用印") && !Objects.equals(true, reportData.getBaseInfo().getWithSeals())) {
|
|
reportData.getBaseInfo().setWithSeals(true);
|
|
reportData.getBaseInfo().setWithSeals(true);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ reportData.getBaseInfo().setWithContacts(parseRes.getWithContacts());
|
|
}
|
|
}
|
|
// 首页和尾页不相等时解析首页的数据
|
|
// 首页和尾页不相等时解析首页的数据
|
|
if (images.size() != 1) {
|
|
if (images.size() != 1) {
|
|
@@ -853,10 +896,19 @@ public class EmailParseService {
|
|
EmailFileInfoDO emailFileInfoDO = buildEmailFileInfoDO(emailId, fileName, filePath);
|
|
EmailFileInfoDO emailFileInfoDO = buildEmailFileInfoDO(emailId, fileName, filePath);
|
|
emailFileInfoDO.setAiFileId(null);
|
|
emailFileInfoDO.setAiFileId(null);
|
|
if (emailFileInfoDO.getId() != null) {
|
|
if (emailFileInfoDO.getId() != null) {
|
|
- emailFileInfoMapper.updateTimeById(null, new Date());
|
|
|
|
|
|
+ this.emailFileInfoMapper.updateTimeById(emailFileInfoDO.getId(), new Date());
|
|
return emailFileInfoDO;
|
|
return emailFileInfoDO;
|
|
}
|
|
}
|
|
- emailFileInfoMapper.insert(emailFileInfoDO);
|
|
|
|
|
|
+
|
|
|
|
+ LambdaQueryWrapper<EmailFileInfoDO> wrapper = Wrappers.lambdaQuery(EmailFileInfoDO.class)
|
|
|
|
+ .eq(EmailFileInfoDO::getEmailId, emailId)
|
|
|
|
+ .eq(EmailFileInfoDO::getFileName, fileName)
|
|
|
|
+ .eq(EmailFileInfoDO::getFilePath, filePath);
|
|
|
|
+ List<EmailFileInfoDO> tempList = this.emailFileInfoMapper.selectList(wrapper);
|
|
|
|
+ if (CollUtil.isNotEmpty(tempList)) {
|
|
|
|
+ return tempList.get(0);
|
|
|
|
+ }
|
|
|
|
+ this.emailFileInfoMapper.insertById(emailFileInfoDO);
|
|
return emailFileInfoDO;
|
|
return emailFileInfoDO;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -880,15 +932,26 @@ public class EmailParseService {
|
|
}
|
|
}
|
|
// 重新邮件功能 -> 修改解析时间和更新时间
|
|
// 重新邮件功能 -> 修改解析时间和更新时间
|
|
if (emailParseInfoDO.getId() != null) {
|
|
if (emailParseInfoDO.getId() != null) {
|
|
- emailParseInfoMapper.updateParseTime(emailParseInfoDO.getId(), emailParseInfoDO.getParseDate());
|
|
|
|
|
|
+ this.emailParseInfoMapper.updateParseTime(emailParseInfoDO.getId(), emailParseInfoDO.getParseDate());
|
|
return emailParseInfoDO.getId();
|
|
return emailParseInfoDO.getId();
|
|
}
|
|
}
|
|
- emailParseInfoMapper.insert(emailParseInfoDO);
|
|
|
|
|
|
+
|
|
|
|
+ LambdaQueryWrapper<EmailParseInfoDO> wrapper = Wrappers.lambdaQuery(EmailParseInfoDO.class)
|
|
|
|
+ .eq(EmailParseInfoDO::getEmailTitle, emailParseInfoDO.getEmailTitle())
|
|
|
|
+ .eq(EmailParseInfoDO::getSenderEmail, emailParseInfoDO.getSenderEmail())
|
|
|
|
+ .eq(EmailParseInfoDO::getEmailDate, emailParseInfoDO.getEmailDate())
|
|
|
|
+ .eq(EmailParseInfoDO::getEmail, emailParseInfoDO.getEmail())
|
|
|
|
+ .orderByDesc(EmailParseInfoDO::getId);
|
|
|
|
+ List<EmailParseInfoDO> tempList = this.emailParseInfoMapper.selectList(wrapper);
|
|
|
|
+ if (CollUtil.isNotEmpty(tempList)) {
|
|
|
|
+ this.emailParseInfoMapper.update(emailParseInfoDO, wrapper);
|
|
|
|
+ return tempList.get(0).getId();
|
|
|
|
+ }
|
|
|
|
+ this.emailParseInfoMapper.insertAndId(emailParseInfoDO);
|
|
return emailParseInfoDO.getId();
|
|
return emailParseInfoDO.getId();
|
|
}
|
|
}
|
|
|
|
|
|
- private EmailParseInfoDO buildEmailParseInfo(String emailAddress, Integer emailType,
|
|
|
|
- EmailInfoDTO emailInfo, long totalSize) {
|
|
|
|
|
|
+ private EmailParseInfoDO buildEmailParseInfo(String emailAddress, EmailInfoDTO emailInfo, long totalSize) {
|
|
EmailParseInfoDO emailParseInfoDO = new EmailParseInfoDO();
|
|
EmailParseInfoDO emailParseInfoDO = new EmailParseInfoDO();
|
|
emailParseInfoDO.setId(null);
|
|
emailParseInfoDO.setId(null);
|
|
emailParseInfoDO.setSenderEmail(emailInfo.getSenderEmail());
|
|
emailParseInfoDO.setSenderEmail(emailInfo.getSenderEmail());
|
|
@@ -896,7 +959,6 @@ public class EmailParseService {
|
|
emailParseInfoDO.setEmailDate(DateUtil.parse(emailInfo.getEmailDate(), DateConst.YYYY_MM_DD_HH_MM_SS));
|
|
emailParseInfoDO.setEmailDate(DateUtil.parse(emailInfo.getEmailDate(), DateConst.YYYY_MM_DD_HH_MM_SS));
|
|
emailParseInfoDO.setParseDate(new Date());
|
|
emailParseInfoDO.setParseDate(new Date());
|
|
emailParseInfoDO.setEmailTitle(emailInfo.getEmailTitle());
|
|
emailParseInfoDO.setEmailTitle(emailInfo.getEmailTitle());
|
|
- emailParseInfoDO.setEmailType(emailType);
|
|
|
|
emailParseInfoDO.setParseStatus(EmailParseStatusConst.SUCCESS);
|
|
emailParseInfoDO.setParseStatus(EmailParseStatusConst.SUCCESS);
|
|
emailParseInfoDO.setAttrSize(totalSize);
|
|
emailParseInfoDO.setAttrSize(totalSize);
|
|
emailParseInfoDO.setIsvalid(1);
|
|
emailParseInfoDO.setIsvalid(1);
|