|
@@ -13,9 +13,12 @@ import com.simuwang.base.pojo.dos.EmailFileInfoDO;
|
|
import com.simuwang.base.pojo.dos.EmailParseInfoDO;
|
|
import com.simuwang.base.pojo.dos.EmailParseInfoDO;
|
|
import com.simuwang.base.pojo.dto.EmailContentInfoDTO;
|
|
import com.simuwang.base.pojo.dto.EmailContentInfoDTO;
|
|
import com.simuwang.base.pojo.dto.EmailFundNavDTO;
|
|
import com.simuwang.base.pojo.dto.EmailFundNavDTO;
|
|
|
|
+import com.simuwang.base.pojo.dto.EmailInfoDTO;
|
|
import com.simuwang.base.pojo.dto.MailboxInfoDTO;
|
|
import com.simuwang.base.pojo.dto.MailboxInfoDTO;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
+import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
|
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
import java.io.BufferedReader;
|
|
@@ -24,6 +27,7 @@ import java.io.IOException;
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
/**
|
|
* @author mozuwen
|
|
* @author mozuwen
|
|
@@ -38,12 +42,14 @@ public class EmailParseApiServiceImpl implements EmailParseApiService {
|
|
private final EmailParseService emailParseService;
|
|
private final EmailParseService emailParseService;
|
|
private final EmailParseInfoMapper emailParseInfoMapper;
|
|
private final EmailParseInfoMapper emailParseInfoMapper;
|
|
private final EmailFileInfoMapper emailFileInfoMapper;
|
|
private final EmailFileInfoMapper emailFileInfoMapper;
|
|
|
|
+ private final ThreadPoolTaskExecutor asyncExecutor;
|
|
|
|
|
|
public EmailParseApiServiceImpl(EmailParseService emailParseService, EmailParseInfoMapper emailParseInfoMapper,
|
|
public EmailParseApiServiceImpl(EmailParseService emailParseService, EmailParseInfoMapper emailParseInfoMapper,
|
|
- EmailFileInfoMapper emailFileInfoMapper) {
|
|
|
|
|
|
+ EmailFileInfoMapper emailFileInfoMapper, @Qualifier("asyncExecutor") ThreadPoolTaskExecutor asyncExecutor) {
|
|
this.emailParseService = emailParseService;
|
|
this.emailParseService = emailParseService;
|
|
this.emailParseInfoMapper = emailParseInfoMapper;
|
|
this.emailParseInfoMapper = emailParseInfoMapper;
|
|
this.emailFileInfoMapper = emailFileInfoMapper;
|
|
this.emailFileInfoMapper = emailFileInfoMapper;
|
|
|
|
+ this.asyncExecutor = asyncExecutor;
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -74,24 +80,78 @@ public class EmailParseApiServiceImpl implements EmailParseApiService {
|
|
|
|
|
|
List<EmailFundNavDTO> emailFundNavDTOList = CollUtil.newArrayList();
|
|
List<EmailFundNavDTO> emailFundNavDTOList = CollUtil.newArrayList();
|
|
Map<EmailContentInfoDTO, List<EmailFundNavDTO>> fileNameNavMap = MapUtil.newHashMap();
|
|
Map<EmailContentInfoDTO, List<EmailFundNavDTO>> fileNameNavMap = MapUtil.newHashMap();
|
|
- for (EmailContentInfoDTO emailContentInfoDTO : emailContentInfoDTOList) {
|
|
|
|
- try {
|
|
|
|
- List<EmailFundNavDTO> fundNavDTOList = emailParseService.parseEmail(emailContentInfoDTO, emailFieldMap);
|
|
|
|
- fileNameNavMap.put(emailContentInfoDTO, fundNavDTOList);
|
|
|
|
- emailFundNavDTOList.addAll(fundNavDTOList);
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- log.error("重新解析邮件失败,邮件id:{},堆栈信息:{}", emailId, ExceptionUtil.stacktraceToString(e));
|
|
|
|
|
|
+ asyncExecutor.execute(() -> {
|
|
|
|
+ for (EmailContentInfoDTO emailContentInfoDTO : emailContentInfoDTOList) {
|
|
|
|
+ try {
|
|
|
|
+ List<EmailFundNavDTO> fundNavDTOList = emailParseService.parseEmail(emailContentInfoDTO, emailFieldMap);
|
|
|
|
+ fileNameNavMap.put(emailContentInfoDTO, fundNavDTOList);
|
|
|
|
+ emailFundNavDTOList.addAll(fundNavDTOList);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.error("重新解析邮件失败,邮件id:{},堆栈信息:{}", emailId, ExceptionUtil.stacktraceToString(e));
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
+ // 保存相关信息 -> 邮件信息表,邮件文件表,邮件净值表,邮件规模表,基金净值表
|
|
|
|
+ emailParseService.saveRelatedTable(emailParseInfoDO.getEmail(), emailContentInfoDTOList, fileNameNavMap);
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void reparseFile(List<Integer> fileIdList) {
|
|
|
|
+ if (CollUtil.isEmpty(fileIdList)) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ List<EmailInfoDTO> emailParseInfoDOList = emailParseInfoMapper.queryValuationEmailByFileId(fileIdList);
|
|
|
|
+ if (CollUtil.isEmpty(emailParseInfoDOList)) {
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
- // 保存相关信息 -> 邮件信息表,邮件文件表,邮件净值表,邮件规模表,基金净值表
|
|
|
|
- emailParseService.saveRelatedTable(emailParseInfoDO.getEmail(), emailContentInfoDTOList, fileNameNavMap);
|
|
|
|
|
|
+ asyncExecutor.execute(() -> {
|
|
|
|
+ Map<Integer, List<EmailInfoDTO>> emailIdFileMap = emailParseInfoDOList.stream().collect(Collectors.groupingBy(EmailInfoDTO::getId));
|
|
|
|
+ for (Map.Entry<Integer, List<EmailInfoDTO>> entry : emailIdFileMap.entrySet()) {
|
|
|
|
+ Integer emailId = entry.getKey();
|
|
|
|
+ List<EmailInfoDTO> emailInfoDTOList = entry.getValue();
|
|
|
|
+ String emailAddress = emailInfoDTOList.get(0).getEmail();
|
|
|
|
+ List<EmailContentInfoDTO> emailContentInfoDTOList = emailInfoDTOList.stream().map(this::buildEmailContentInfoDTO).collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
+ List<EmailFundNavDTO> emailFundNavDTOList = CollUtil.newArrayList();
|
|
|
|
+ Map<EmailContentInfoDTO, List<EmailFundNavDTO>> fileNameNavMap = MapUtil.newHashMap();
|
|
|
|
+ for (EmailContentInfoDTO emailContentInfoDTO : emailContentInfoDTOList) {
|
|
|
|
+ try {
|
|
|
|
+ log.info("开始重新解析文件 -> 文件id:{}", emailContentInfoDTO.getFielId());
|
|
|
|
+ List<EmailFundNavDTO> fundNavDTOList = emailParseService.parseEmail(emailContentInfoDTO, MapUtil.newHashMap());
|
|
|
|
+ fileNameNavMap.put(emailContentInfoDTO, fundNavDTOList);
|
|
|
|
+ emailFundNavDTOList.addAll(fundNavDTOList);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.error("重新解析文件失败,邮件id:{},文件id:{},堆栈信息:{}", emailId, emailContentInfoDTO.getFielId(), ExceptionUtil.stacktraceToString(e));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // 保存相关信息 -> 邮件信息表,邮件文件表,邮件净值表,邮件规模表,基金净值表
|
|
|
|
+ emailParseService.saveRelatedTable(emailAddress, emailContentInfoDTOList, fileNameNavMap);
|
|
|
|
+ }
|
|
|
|
+ log.info("重新解析文件结束... -> 文件id:{}", fileIdList);
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private EmailContentInfoDTO buildEmailContentInfoDTO(EmailInfoDTO emailInfoDTO) {
|
|
|
|
+ String emailDate = DateUtil.format(emailInfoDTO.getEmailDate(), DateConst.YYYY_MM_DD_HH_MM_SS);
|
|
|
|
+ String parseDate = DateUtil.format(new Date(), DateConst.YYYY_MM_DD_HH_MM_SS);
|
|
|
|
+ EmailContentInfoDTO contentInfoDTO = new EmailContentInfoDTO();
|
|
|
|
+ contentInfoDTO.setEmailId(emailInfoDTO.getId());
|
|
|
|
+ contentInfoDTO.setFielId(emailInfoDTO.getFileId());
|
|
|
|
+ contentInfoDTO.setEmailAddress(emailInfoDTO.getEmail());
|
|
|
|
+ contentInfoDTO.setEmailDate(emailDate);
|
|
|
|
+ contentInfoDTO.setEmailTitle(emailInfoDTO.getEmailTitle());
|
|
|
|
+ contentInfoDTO.setParseDate(parseDate);
|
|
|
|
+ contentInfoDTO.setFileName(emailInfoDTO.getFileName());
|
|
|
|
+ contentInfoDTO.setFilePath(emailInfoDTO.getFilePath());
|
|
|
|
+ contentInfoDTO.setEmailType(emailInfoDTO.getEmailType());
|
|
|
|
+ return contentInfoDTO;
|
|
}
|
|
}
|
|
|
|
|
|
- private List<EmailContentInfoDTO> buildEmailContentInfoDTO(Integer emailId, EmailParseInfoDO emailParseInfoDO, List<EmailFileInfoDO> emailParseInfoDOList, Map<Integer, List<String>> emailTypeMap) {
|
|
|
|
|
|
+ private List<EmailContentInfoDTO> buildEmailContentInfoDTO(Integer emailId, EmailParseInfoDO emailParseInfoDO, List<EmailFileInfoDO> emailFileInfoDOList, Map<Integer, List<String>> emailTypeMap) {
|
|
List<EmailContentInfoDTO> emailContentInfoDTOList = CollUtil.newArrayList();
|
|
List<EmailContentInfoDTO> emailContentInfoDTOList = CollUtil.newArrayList();
|
|
String emailDate = DateUtil.format(emailParseInfoDO.getEmailDate(), DateConst.YYYY_MM_DD_HH_MM_SS);
|
|
String emailDate = DateUtil.format(emailParseInfoDO.getEmailDate(), DateConst.YYYY_MM_DD_HH_MM_SS);
|
|
String parseDate = DateUtil.format(new Date(), DateConst.YYYY_MM_DD_HH_MM_SS);
|
|
String parseDate = DateUtil.format(new Date(), DateConst.YYYY_MM_DD_HH_MM_SS);
|
|
- for (EmailFileInfoDO fileInfoDO : emailParseInfoDOList) {
|
|
|
|
|
|
+ for (EmailFileInfoDO fileInfoDO : emailFileInfoDOList) {
|
|
EmailContentInfoDTO contentInfoDTO = new EmailContentInfoDTO();
|
|
EmailContentInfoDTO contentInfoDTO = new EmailContentInfoDTO();
|
|
contentInfoDTO.setEmailId(emailId);
|
|
contentInfoDTO.setEmailId(emailId);
|
|
contentInfoDTO.setFielId(fileInfoDO.getId());
|
|
contentInfoDTO.setFielId(fileInfoDO.getId());
|
|
@@ -103,14 +163,14 @@ public class EmailParseApiServiceImpl implements EmailParseApiService {
|
|
contentInfoDTO.setFilePath(fileInfoDO.getFilePath());
|
|
contentInfoDTO.setFilePath(fileInfoDO.getFilePath());
|
|
Integer emailType = EmailUtil.getEmailTypeBySubject(emailParseInfoDO.getEmailTitle(), emailTypeMap);
|
|
Integer emailType = EmailUtil.getEmailTypeBySubject(emailParseInfoDO.getEmailTitle(), emailTypeMap);
|
|
contentInfoDTO.setEmailType(emailType);
|
|
contentInfoDTO.setEmailType(emailType);
|
|
- String emailContent = getEmailContent(fileInfoDO.getFilePath());
|
|
|
|
|
|
+ String emailContent = readHtmlFileContent(fileInfoDO.getFilePath());
|
|
contentInfoDTO.setEmailContent(emailContent);
|
|
contentInfoDTO.setEmailContent(emailContent);
|
|
emailContentInfoDTOList.add(contentInfoDTO);
|
|
emailContentInfoDTOList.add(contentInfoDTO);
|
|
}
|
|
}
|
|
return emailContentInfoDTOList;
|
|
return emailContentInfoDTOList;
|
|
}
|
|
}
|
|
|
|
|
|
- public static String getEmailContent(String filePath) {
|
|
|
|
|
|
+ public static String readHtmlFileContent(String filePath) {
|
|
if (StrUtil.isNotBlank(filePath) && filePath.endsWith("html")) {
|
|
if (StrUtil.isNotBlank(filePath) && filePath.endsWith("html")) {
|
|
StringBuilder content = new StringBuilder();
|
|
StringBuilder content = new StringBuilder();
|
|
try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) {
|
|
try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) {
|