|
@@ -43,6 +43,8 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.StopWatch;
|
|
|
|
|
|
import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
+import java.nio.file.Paths;
|
|
|
import java.util.*;
|
|
|
import java.util.regex.Matcher;
|
|
|
import java.util.regex.Pattern;
|
|
@@ -135,41 +137,63 @@ public class EmailParseService {
|
|
|
List<EmailZipFileDTO> resultList = ListUtil.list(false);
|
|
|
Integer emailType = emailContentInfoDTO.getEmailType();
|
|
|
String filepath = emailContentInfoDTO.getFilePath();
|
|
|
- if (ExcelUtil.isZip(filepath)) {
|
|
|
- String destPath = filepath.replaceAll(".zip", "").replaceAll(".ZIP", "");
|
|
|
- log.info("压缩包地址:{},解压后文件地址:{}", filepath, destPath);
|
|
|
- List<String> dirs = ExcelUtil.extractCompressedFiles(filepath, destPath);
|
|
|
- for (String dir : dirs) {
|
|
|
- File file = new File(dir);
|
|
|
- if (file.isDirectory() && file.list() != null) {
|
|
|
- for (String subDir : Objects.requireNonNull(file.list())) {
|
|
|
- resultList.add(new EmailZipFileDTO(subDir, emailType));
|
|
|
- }
|
|
|
- } else {
|
|
|
- resultList.add(new EmailZipFileDTO(dir, emailType));
|
|
|
- }
|
|
|
+
|
|
|
+ try {
|
|
|
+ if (ExcelUtil.isZip(filepath)) {
|
|
|
+ handleCompressedFiles(filepath, ".zip", emailType, resultList);
|
|
|
+ } else if (ExcelUtil.isRAR(filepath)) {
|
|
|
+ handleCompressedFiles(filepath, ".rar", emailType, resultList);
|
|
|
}
|
|
|
- } else if (ExcelUtil.isRAR(filepath)) {
|
|
|
- String destPath = filepath.replaceAll(".rar", "").replaceAll(".RAR", "");
|
|
|
- File destFile = new File(destPath);
|
|
|
- if (!destFile.exists()) {
|
|
|
- destFile.mkdirs();
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error("解压文件时发生异常: {}", e.getMessage(), e);
|
|
|
+ }
|
|
|
+
|
|
|
+ return resultList;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void handleCompressedFiles(String filepath, String extension, Integer emailType, List<EmailZipFileDTO> resultList) throws IOException {
|
|
|
+ String destPath = getDestinationPath(filepath, extension);
|
|
|
+ log.info("压缩包地址:{}, 解压后文件地址:{}", filepath, destPath);
|
|
|
+
|
|
|
+ File destFile = new File(destPath);
|
|
|
+ if (!destFile.exists()) {
|
|
|
+ if (!destFile.mkdirs()) {
|
|
|
+ throw new IOException("无法创建目标目录: " + destPath);
|
|
|
}
|
|
|
- List<String> rarDirs = ExcelUtil.extractRar(filepath, destPath);
|
|
|
- for (String rarDir : rarDirs) {
|
|
|
- File file = new File(rarDir);
|
|
|
- if (file.isDirectory() && file.list() != null) {
|
|
|
- for (String subRarDir : Objects.requireNonNull(file.list())) {
|
|
|
- resultList.add(new EmailZipFileDTO(subRarDir, emailType));
|
|
|
+ }
|
|
|
+
|
|
|
+ List<String> extractedDirs;
|
|
|
+ if (ExcelUtil.isZip(filepath)) {
|
|
|
+ extractedDirs = ExcelUtil.extractCompressedFiles(filepath, destPath);
|
|
|
+ } else if (ExcelUtil.isRAR(filepath)) {
|
|
|
+ extractedDirs = ExcelUtil.extractRar(filepath, destPath);
|
|
|
+ } else {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ for (String dir : extractedDirs) {
|
|
|
+ File file = new File(dir);
|
|
|
+ if (file.isDirectory()) {
|
|
|
+ String[] subDirs = file.list();
|
|
|
+ if (subDirs != null) {
|
|
|
+ for (String subDir : subDirs) {
|
|
|
+ resultList.add(new EmailZipFileDTO(subDir, emailType));
|
|
|
}
|
|
|
} else {
|
|
|
- resultList.add(new EmailZipFileDTO(rarDir, emailType));
|
|
|
+ log.warn("目录 {} 下无文件", dir);
|
|
|
}
|
|
|
+ } else {
|
|
|
+ resultList.add(new EmailZipFileDTO(dir, emailType));
|
|
|
}
|
|
|
}
|
|
|
- return resultList;
|
|
|
}
|
|
|
|
|
|
+ private String getDestinationPath(String filepath, String extension) {
|
|
|
+ String fileName = Paths.get(filepath).getFileName().toString();
|
|
|
+ String baseName = fileName.substring(0, fileName.length() - extension.length());
|
|
|
+ return Paths.get(filepath).getParent().resolve(baseName).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
public void saveRelatedTable(String emailKey, String emailAddress,
|
|
|
Map<EmailContentInfoDTO, List<EmailZipFileDTO>> emailZipFileMap) {
|
|
|
// python 报告解析接口结果
|
|
@@ -233,7 +257,7 @@ public class EmailParseService {
|
|
|
result.setMsg(ReportParseStatus.NOT_A_REPORT.getMsg());
|
|
|
return result;
|
|
|
}
|
|
|
- Pattern pattern = Pattern.compile("S(?:[A-Z]{0}[0-9]{5}|[A-Z][0-9]{4}|[A-Z]{2}[0-9]{3}|[A-Z]{3}[0-9]{2})");
|
|
|
+ Pattern pattern = Pattern.compile("[A-Z0-9]{6}");
|
|
|
Matcher matcher = pattern.matcher(fileName);
|
|
|
String registerNumber = null;
|
|
|
if (matcher.find()) {
|
|
@@ -351,6 +375,10 @@ public class EmailParseService {
|
|
|
emailParseInfoDO.setEmailType(emailContentInfoDTO.getEmailType());
|
|
|
emailParseInfoDO.setParseStatus(EmailParseStatusConst.SUCCESS);
|
|
|
emailParseInfoDO.setIsvalid(1);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
emailParseInfoDO.setCreatorId(0);
|
|
|
emailParseInfoDO.setCreateTime(new Date());
|
|
|
emailParseInfoDO.setUpdaterId(0);
|
|
@@ -366,6 +394,7 @@ public class EmailParseService {
|
|
|
// String report = emailTypeRuleDO != null && StrUtil.isNotBlank(emailTypeRuleDO.getReport()) ? emailTypeRuleDO.getReport() : emailRuleConfig.getReport();
|
|
|
// emailTypeMap.put(EmailTypeConst.VALUATION_EMAIL_TYPE, Arrays.stream(valuation.split(",")).toList());
|
|
|
// emailTypeMap.put(EmailTypeConst.NAV_EMAIL_TYPE, Arrays.stream(nav.split(",")).toList());
|
|
|
+ emailTypeMap.put(EmailTypeConst.REPORT_EMAIL_TYPE, ListUtil.toList("月报", "周报", "月度报告"));
|
|
|
emailTypeMap.put(EmailTypeConst.REPORT_LETTER_EMAIL_TYPE, ListUtil.toList("确认单", "确认函", "确认"));
|
|
|
return emailTypeMap;
|
|
|
}
|