|
@@ -6,6 +6,7 @@ import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.exceptions.ExceptionUtil;
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
import cn.hutool.core.map.MapUtil;
|
|
|
+import cn.hutool.core.util.IdUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.smppw.modaq.application.components.OCRReportParser;
|
|
|
import com.smppw.modaq.application.components.ReportParseUtils;
|
|
@@ -190,6 +191,13 @@ public class EmailParseService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 解压压缩包,如果不是压缩包需转换
|
|
|
+ *
|
|
|
+ * @param emailContentInfoDTO 邮件信息
|
|
|
+ * @return 解压后的文件列表
|
|
|
+ * @throws IOException /
|
|
|
+ */
|
|
|
public List<EmailZipFileDTO> parseZipEmail(EmailContentInfoDTO emailContentInfoDTO) throws IOException {
|
|
|
List<EmailZipFileDTO> resultList = ListUtil.list(false);
|
|
|
Integer emailType = emailContentInfoDTO.getEmailType();
|
|
@@ -209,16 +217,11 @@ public class EmailParseService {
|
|
|
emailType = EmailUtil.getEmailTypeBySubject(emailContentInfoDTO.getFileName());
|
|
|
emailContentInfoDTO.setEmailType(emailType);
|
|
|
}
|
|
|
-
|
|
|
if (CollUtil.isNotEmpty(resultList)) {
|
|
|
for (EmailZipFileDTO dto : resultList) {
|
|
|
dto.setEmailType(emailType);
|
|
|
}
|
|
|
- if (log.isInfoEnabled()) {
|
|
|
- log.info("当前邮件{} 所有解压缩文件解压完成:{}", emailTitle, resultList);
|
|
|
- }
|
|
|
}
|
|
|
-
|
|
|
return resultList;
|
|
|
}
|
|
|
|
|
@@ -333,7 +336,7 @@ public class EmailParseService {
|
|
|
ParseResult<ReportData> result = new ParseResult<>();
|
|
|
result.setStatus(ReportParseStatus.ARCHIVE_FAIL.getCode());
|
|
|
result.setMsg(ReportParseStatus.ARCHIVE_FAIL.getMsg());
|
|
|
- ReportData reportData = new ReportData.DefaultReportData(null, null);
|
|
|
+ ReportData reportData = new ReportData.DefaultReportData();
|
|
|
reportData.setReportPath(reportPath);
|
|
|
dataList.add(result);
|
|
|
}
|
|
@@ -459,7 +462,7 @@ public class EmailParseService {
|
|
|
// 解析并保存报告
|
|
|
ParseResult<ReportData> parseResult = this.parseReportAndHandleResult(emailTitle, emailFile, zipFile);
|
|
|
if (parseResult.getData() == null) {
|
|
|
- parseResult.setData(new ReportData.DefaultReportData(null, null));
|
|
|
+ parseResult.setData(new ReportData.DefaultReportData());
|
|
|
}
|
|
|
parseResult.getData().setReportPath(zipFile.getFilepath());
|
|
|
resultList.add(parseResult);
|
|
@@ -881,10 +884,7 @@ public class EmailParseService {
|
|
|
Map<String, List<EmailContentInfoDTO>> emailMessageMap = MapUtil.newHashMap();
|
|
|
for (Message message : messages) {
|
|
|
long start = System.currentTimeMillis();
|
|
|
- List<EmailContentInfoDTO> emailContentInfoDTOList = CollUtil.newArrayList();
|
|
|
- String uuidKey = UUID.randomUUID().toString().replaceAll("-", "");
|
|
|
- Integer emailType;
|
|
|
- String senderEmail;
|
|
|
+ List<EmailContentInfoDTO> dtos = CollUtil.newArrayList();
|
|
|
String emailTitle = message.getSubject();
|
|
|
if (this.readWriteSeen && isMessageRead(message)) {
|
|
|
log.warn("{} 邮件{} 已读,不用重新下载解析!", folderName, emailTitle);
|
|
@@ -906,8 +906,8 @@ public class EmailParseService {
|
|
|
log.warn("{} 邮件[{}]日期{}不在区间内【{} ~ {}】", folderName, emailTitle, emailDateStr, st, ed);
|
|
|
continue;
|
|
|
}
|
|
|
- senderEmail = getSenderEmail(message);
|
|
|
- emailType = EmailUtil.getEmailTypeBySubject(emailTitle);
|
|
|
+ String senderEmail = getSenderEmail(message);
|
|
|
+ Integer emailType = EmailUtil.getEmailTypeBySubject(emailTitle);
|
|
|
if (emailType == null) {
|
|
|
log.warn("{} 邮件不满足解析条件 -> 邮件主题:{},邮件日期:{}", folderName, emailTitle, emailDateStr);
|
|
|
continue;
|
|
@@ -918,27 +918,27 @@ public class EmailParseService {
|
|
|
Object content = message.getContent();
|
|
|
|
|
|
if (content instanceof Multipart multipart) {
|
|
|
- this.reMultipart(mailboxInfoDTO.getAccount(), emailTitle, emailDate, multipart, emailContentInfoDTOList);
|
|
|
+ this.reMultipart(mailboxInfoDTO.getAccount(), emailTitle, emailDate, multipart, dtos);
|
|
|
} else if (content instanceof Part part) {
|
|
|
- this.rePart(mailboxInfoDTO.getAccount(), emailTitle, emailDate, part, emailContentInfoDTOList);
|
|
|
+ this.rePart(mailboxInfoDTO.getAccount(), emailTitle, emailDate, part, dtos);
|
|
|
} else {
|
|
|
log.warn("{} 不支持的邮件数据 {}", folderName, emailTitle);
|
|
|
}
|
|
|
- if (CollUtil.isEmpty(emailContentInfoDTOList)) {
|
|
|
+ if (CollUtil.isEmpty(dtos)) {
|
|
|
log.warn("{} 邮件{} 没有获取到附件", folderName, emailTitle);
|
|
|
continue;
|
|
|
}
|
|
|
- emailContentInfoDTOList.forEach(e -> {
|
|
|
+ dtos.forEach(e -> {
|
|
|
e.setEmailType(emailType);
|
|
|
e.setSenderEmail(senderEmail);
|
|
|
});
|
|
|
- emailMessageMap.put(uuidKey, emailContentInfoDTOList);
|
|
|
+ emailMessageMap.put(IdUtil.simpleUUID(), dtos);
|
|
|
} catch (Exception e) {
|
|
|
log.error("{} 获取邮箱的邮件{} 报错,堆栈信息:{}", folderName, emailTitle, ExceptionUtil.stacktraceToString(e));
|
|
|
} finally {
|
|
|
if (log.isInfoEnabled()) {
|
|
|
log.info("{} 邮件{} 下载完成,总计耗时{} ms,文件内容如下\n {}", folderName,
|
|
|
- emailTitle, System.currentTimeMillis() - start, emailContentInfoDTOList);
|
|
|
+ emailTitle, System.currentTimeMillis() - start, dtos);
|
|
|
}
|
|
|
}
|
|
|
}
|