|
@@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.collection.ListUtil;
|
|
import cn.hutool.core.collection.ListUtil;
|
|
import cn.hutool.core.date.DateUtil;
|
|
import cn.hutool.core.date.DateUtil;
|
|
import cn.hutool.core.exceptions.ExceptionUtil;
|
|
import cn.hutool.core.exceptions.ExceptionUtil;
|
|
|
|
+import cn.hutool.core.io.FileUtil;
|
|
import cn.hutool.core.map.MapUtil;
|
|
import cn.hutool.core.map.MapUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import com.smppw.modaq.application.components.ReportParseUtils;
|
|
import com.smppw.modaq.application.components.ReportParseUtils;
|
|
@@ -31,7 +32,7 @@ import com.smppw.modaq.domain.entity.EmailParseInfoDO;
|
|
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.infrastructure.util.ExcelUtil;
|
|
import com.smppw.modaq.infrastructure.util.ExcelUtil;
|
|
-import com.smppw.modaq.infrastructure.util.FileUtil;
|
|
|
|
|
|
+import com.smppw.modaq.infrastructure.util.PdfUtil;
|
|
import jakarta.mail.*;
|
|
import jakarta.mail.*;
|
|
import jakarta.mail.internet.MimeUtility;
|
|
import jakarta.mail.internet.MimeUtility;
|
|
import jakarta.mail.search.ComparisonTerm;
|
|
import jakarta.mail.search.ComparisonTerm;
|
|
@@ -46,6 +47,8 @@ import org.springframework.util.StopWatch;
|
|
|
|
|
|
import java.io.File;
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
|
+import java.io.InputStream;
|
|
|
|
+import java.nio.file.Files;
|
|
import java.nio.file.Path;
|
|
import java.nio.file.Path;
|
|
import java.nio.file.Paths;
|
|
import java.nio.file.Paths;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
@@ -116,7 +119,7 @@ public class EmailParseService {
|
|
}
|
|
}
|
|
Map<String, List<EmailContentInfoDTO>> emailContentMap;
|
|
Map<String, List<EmailContentInfoDTO>> emailContentMap;
|
|
try {
|
|
try {
|
|
- emailContentMap = realEmail(mailboxInfoDTO, startDate, endDate, folderNames);
|
|
|
|
|
|
+ emailContentMap = this.realEmail(mailboxInfoDTO, startDate, endDate, folderNames);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
log.error("采集邮件失败 -> 邮箱配置信息:{},堆栈信息:{}", mailboxInfoDTO, ExceptionUtil.stacktraceToString(e));
|
|
log.error("采集邮件失败 -> 邮箱配置信息:{},堆栈信息:{}", mailboxInfoDTO, ExceptionUtil.stacktraceToString(e));
|
|
return;
|
|
return;
|
|
@@ -216,13 +219,16 @@ public class EmailParseService {
|
|
emailContentInfoDTO.setEmailType(emailType);
|
|
emailContentInfoDTO.setEmailType(emailType);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if (log.isInfoEnabled()) {
|
|
|
|
+ log.info("当前邮件{} 所有解压缩文件解压完成:{}", emailTitle, resultList);
|
|
|
|
+ }
|
|
|
|
+
|
|
return resultList;
|
|
return resultList;
|
|
}
|
|
}
|
|
|
|
|
|
private void handleCompressedFiles(String emailTitle, String filepath, String extension,
|
|
private void handleCompressedFiles(String emailTitle, String filepath, String extension,
|
|
Integer emailType, List<EmailZipFileDTO> resultList) throws Exception {
|
|
Integer emailType, List<EmailZipFileDTO> resultList) throws Exception {
|
|
String destPath = getDestinationPath(filepath, extension);
|
|
String destPath = getDestinationPath(filepath, extension);
|
|
- log.info("压缩包地址:{}, 解压后文件地址:{}", filepath, destPath);
|
|
|
|
|
|
|
|
File destFile = new File(destPath);
|
|
File destFile = new File(destPath);
|
|
if (!destFile.exists()) {
|
|
if (!destFile.exists()) {
|
|
@@ -403,6 +409,17 @@ public class EmailParseService {
|
|
}
|
|
}
|
|
Integer fileId = emailFileInfo.getId();
|
|
Integer fileId = emailFileInfo.getId();
|
|
String aiFileId = emailFileInfo.getAiFileId();
|
|
String aiFileId = emailFileInfo.getAiFileId();
|
|
|
|
+
|
|
|
|
+ // 首页和尾页转为png图片,首页用来识别基金名称和基金代码、尾页用来识别印章和联系人
|
|
|
|
+ List<String> images = null;
|
|
|
|
+ try {
|
|
|
|
+ String parent = FileUtil.getParent(filepath, 1);
|
|
|
|
+ String output = parent + File.separator + "image";
|
|
|
|
+ images = PdfUtil.convertFirstAndLastPagesToPng(filepath, FileUtil.file(output), 300);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.warn("报告[{}] 生成图片失败:{}", fileName, ExceptionUtil.stacktraceToString(e));
|
|
|
|
+ }
|
|
|
|
+
|
|
// 不支持解析的格式文件
|
|
// 不支持解析的格式文件
|
|
boolean notSupportFile = false;
|
|
boolean notSupportFile = false;
|
|
// 解析报告
|
|
// 解析报告
|
|
@@ -619,9 +636,8 @@ public class EmailParseService {
|
|
String uuidKey = UUID.randomUUID().toString().replaceAll("-", "");
|
|
String uuidKey = UUID.randomUUID().toString().replaceAll("-", "");
|
|
Integer emailType;
|
|
Integer emailType;
|
|
String senderEmail;
|
|
String senderEmail;
|
|
- String emailTitle = null;
|
|
|
|
|
|
+ String emailTitle = message.getSubject();
|
|
try {
|
|
try {
|
|
- emailTitle = message.getSubject();
|
|
|
|
Date emailDate = message.getSentDate();
|
|
Date emailDate = message.getSentDate();
|
|
String emailDateStr = DateUtil.format(emailDate, DateConst.YYYY_MM_DD_HH_MM_SS);
|
|
String emailDateStr = DateUtil.format(emailDate, DateConst.YYYY_MM_DD_HH_MM_SS);
|
|
if (log.isInfoEnabled()) {
|
|
if (log.isInfoEnabled()) {
|
|
@@ -661,7 +677,7 @@ public class EmailParseService {
|
|
});
|
|
});
|
|
emailMessageMap.put(uuidKey, emailContentInfoDTOList);
|
|
emailMessageMap.put(uuidKey, emailContentInfoDTOList);
|
|
}
|
|
}
|
|
- if (log.isInfoEnabled() && emailTitle != null) {
|
|
|
|
|
|
+ if (log.isInfoEnabled()) {
|
|
log.info("{} 邮件{} 下载完成,总计耗时{} ms,文件内容如下\n {}", folderName,
|
|
log.info("{} 邮件{} 下载完成,总计耗时{} ms,文件内容如下\n {}", folderName,
|
|
emailTitle, System.currentTimeMillis() - start, emailContentInfoDTOList);
|
|
emailTitle, System.currentTimeMillis() - start, emailContentInfoDTOList);
|
|
}
|
|
}
|
|
@@ -699,8 +715,7 @@ public class EmailParseService {
|
|
String emailDate = DateUtil.format(sendDate, DateConst.YYYYMMDDHHMMSS24);
|
|
String emailDate = DateUtil.format(sendDate, DateConst.YYYYMMDDHHMMSS24);
|
|
String emailDateStr = DateUtil.format(sendDate, DateConst.YYYYMMDD);
|
|
String emailDateStr = DateUtil.format(sendDate, DateConst.YYYYMMDD);
|
|
String filePath = path + File.separator + account + File.separator + emailDateStr + File.separator;
|
|
String filePath = path + File.separator + account + File.separator + emailDateStr + File.separator;
|
|
- String realPath = filePath + emailDate + fileName;
|
|
|
|
- File saveFile = cn.hutool.core.io.FileUtil.file(realPath);
|
|
|
|
|
|
+ File saveFile = FileUtil.file(filePath + emailDate + fileName);
|
|
if (!saveFile.exists()) {
|
|
if (!saveFile.exists()) {
|
|
if (!saveFile.getParentFile().exists()) {
|
|
if (!saveFile.getParentFile().exists()) {
|
|
boolean mkdirs = saveFile.getParentFile().mkdirs();
|
|
boolean mkdirs = saveFile.getParentFile().mkdirs();
|
|
@@ -708,10 +723,14 @@ public class EmailParseService {
|
|
log.warn("file path mkdir failed.");
|
|
log.warn("file path mkdir failed.");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- FileUtil.saveFile(saveFile, part);
|
|
|
|
|
|
+ try (InputStream is = part.getInputStream()) {
|
|
|
|
+ Files.copy(is, saveFile.toPath());
|
|
|
|
+ }
|
|
} else {
|
|
} else {
|
|
- cn.hutool.core.io.FileUtil.del(saveFile);
|
|
|
|
- FileUtil.saveFile(saveFile, part);
|
|
|
|
|
|
+ FileUtil.del(saveFile);
|
|
|
|
+ try (InputStream is = part.getInputStream()) {
|
|
|
|
+ Files.copy(is, saveFile.toPath());
|
|
|
|
+ }
|
|
}
|
|
}
|
|
EmailContentInfoDTO emailContentInfoDTO = new EmailContentInfoDTO();
|
|
EmailContentInfoDTO emailContentInfoDTO = new EmailContentInfoDTO();
|
|
emailContentInfoDTO.setFileName(fileName);
|
|
emailContentInfoDTO.setFileName(fileName);
|
|
@@ -763,17 +782,6 @@ public class EmailParseService {
|
|
if (matcher.find()) {
|
|
if (matcher.find()) {
|
|
return matcher.group(1);
|
|
return matcher.group(1);
|
|
}
|
|
}
|
|
-// //说明匹配不到,直接获取sender
|
|
|
|
-// Address sender = message.getSender();
|
|
|
|
-// if (sender == null) {
|
|
|
|
-// return address;
|
|
|
|
-// }
|
|
|
|
-// String senderEmail = sender.toString();
|
|
|
|
-// log.info("senderEmail:" + senderEmail + "====================");
|
|
|
|
-// if (senderEmail.contains("<") && senderEmail.contains(">") && senderEmail.indexOf("<") < senderEmail.indexOf(">")) {
|
|
|
|
-// senderEmail = senderEmail.substring(senderEmail.indexOf("<") + 1, senderEmail.length() - 1);
|
|
|
|
-// }
|
|
|
|
-// return senderEmail;
|
|
|
|
} catch (MessagingException e) {
|
|
} catch (MessagingException e) {
|
|
log.error(e.getMessage(), e);
|
|
log.error(e.getMessage(), e);
|
|
}
|
|
}
|