فهرست منبع

Merge branch 'test' of http://112.74.196.215:3000/backend/mo-daq-all into release

wangzaijun 2 ماه پیش
والد
کامیت
df0bcd06bc

+ 15 - 10
mo-daq/src/main/java/com/smppw/modaq/domain/service/EmailParseService.java

@@ -46,6 +46,8 @@ import org.springframework.util.StopWatch;
 
 import java.io.File;
 import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.*;
 import java.util.regex.Matcher;
@@ -206,9 +208,10 @@ public class EmailParseService {
     }
 
     private String getDestinationPath(String filepath, String extension) {
-        String fileName = Paths.get(filepath).getFileName().toString();
+        Path path = Paths.get(filepath);
+        String fileName = path.getFileName().toString();
         String baseName = fileName.substring(0, fileName.length() - extension.length());
-        return Paths.get(filepath).getParent().resolve(baseName).toString();
+        return path.getParent().resolve(baseName).toString();
     }
 
     public void saveRelatedTable(String emailKey, String emailAddress,
@@ -217,6 +220,9 @@ public class EmailParseService {
         List<ParseResult<ReportData>> dataList = ListUtil.list(false);
         for (Map.Entry<EmailContentInfoDTO, List<EmailZipFileDTO>> entry : emailZipFileMap.entrySet()) {
             EmailContentInfoDTO emailContentInfoDTO = entry.getKey();
+            if (emailContentInfoDTO.getFileName() != null && emailContentInfoDTO.getFileName().endsWith(".html")) {
+                continue;
+            }
             Integer emailId = emailContentInfoDTO.getEmailId();
             EmailParseInfoDO emailParseInfoDO = buildEmailParseInfo(emailId, emailAddress, emailContentInfoDTO);
             emailParseInfoDO.setEmailKey(emailKey);
@@ -224,9 +230,6 @@ public class EmailParseService {
             if (emailId == null) {
                 continue;
             }
-            if (emailContentInfoDTO.getFileName() != null && emailContentInfoDTO.getFileName().endsWith(".html")) {
-                continue;
-            }
 
             List<EmailZipFileDTO> zipFiles = entry.getValue();
             if (CollUtil.isNotEmpty(zipFiles)) {
@@ -272,10 +275,9 @@ public class EmailParseService {
     private ParseResult<ReportData> parseReportAndHandleResult(int fileId, String fileName,
                                                                String filepath, Integer emailType, String aiFileId) {
         ParseResult<ReportData> result = new ParseResult<>();
-        if ((!Objects.equals(EmailTypeConst.REPORT_EMAIL_TYPE, emailType)
-                && !Objects.equals(EmailTypeConst.REPORT_LETTER_EMAIL_TYPE, emailType))
-                || StrUtil.isBlank(fileName)
-                || fileName.endsWith(".html")) {
+        boolean reportFlag = !Objects.equals(EmailTypeConst.REPORT_EMAIL_TYPE, emailType)
+                && !Objects.equals(EmailTypeConst.REPORT_LETTER_EMAIL_TYPE, emailType);
+        if (reportFlag || StrUtil.isBlank(fileName) || fileName.endsWith(".html")) {
             result.setStatus(ReportParseStatus.NOT_A_REPORT.getCode());
             result.setMsg(StrUtil.format(ReportParseStatus.NOT_A_REPORT.getMsg(), fileName));
             return result;
@@ -288,6 +290,9 @@ public class EmailParseService {
         }
         // 类型识别---先识别季度报告,没有季度再识别年度报告,最后识别月报
         ReportType reportType = ReportParseUtils.matchReportType(fileName);
+        if (Objects.equals(EmailTypeConst.REPORT_LETTER_EMAIL_TYPE, emailType)) {
+            reportType = ReportType.LETTER;
+        }
         // 解析器--如果开启python解析则直接调用python接口,否则根据文件后缀获取对应解析器
         ReportParserFileType fileType;
         String fileSuffix = StrUtil.subAfter(fileName, ".", true);
@@ -486,7 +491,7 @@ public class EmailParseService {
                     saveFile.setReadable(true);
                     if (!saveFile.exists()) {
                         if (!saveFile.getParentFile().exists()) {
-                            saveFile.getParentFile().mkdirs();
+                            Files.createDirectories(saveFile.getParentFile().toPath());
                             saveFile.getParentFile().setExecutable(true);
                         }
                     }

+ 11 - 10
mo-daq/src/main/java/com/smppw/modaq/infrastructure/util/ExcelUtil.java

@@ -5,6 +5,7 @@ import cn.hutool.core.collection.ListUtil;
 import cn.hutool.core.io.FileUtil;
 import cn.hutool.core.util.StrUtil;
 import com.github.junrar.Archive;
+import com.github.junrar.exception.RarException;
 import com.github.junrar.rarfile.FileHeader;
 import org.apache.commons.compress.archivers.ArchiveEntry;
 import org.apache.commons.compress.archivers.ArchiveException;
@@ -12,7 +13,7 @@ import org.apache.commons.compress.archivers.ArchiveInputStream;
 import org.apache.commons.compress.archivers.ArchiveStreamFactory;
 import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
 import org.apache.commons.compress.archivers.zip.ZipFile;
-import org.apache.commons.compress.utils.IOUtils;
+import org.apache.commons.io.IOUtils;
 
 import java.io.*;
 import java.nio.file.Files;
@@ -48,12 +49,11 @@ public class ExcelUtil {
 
         File destFile = FileUtil.file(destFilePath);
         if (!destFile.exists()) {
-            destFile.mkdirs();
+            Files.createDirectories(destFile.toPath());
         }
 
-
         try (BufferedInputStream fis = new BufferedInputStream(new FileInputStream(zipFilePath));
-             ArchiveInputStream ais = new ArchiveStreamFactory().createArchiveInputStream(fis)) {
+             ArchiveInputStream<? extends ArchiveEntry> ais = new ArchiveStreamFactory().createArchiveInputStream(fis)) {
             ArchiveEntry entry;
             int i = 1;
             while ((entry = ais.getNextEntry()) != null) {
@@ -69,7 +69,7 @@ public class ExcelUtil {
                     i++;
                 }
                 if (entry.isDirectory()) {
-                    entryFile.mkdirs();
+                    Files.createDirectories(entryFile.toPath());
                 } else {
                     try (FileOutputStream fos = new FileOutputStream(entryFile)) {
                         IOUtils.copy(ais, fos);
@@ -90,7 +90,7 @@ public class ExcelUtil {
         return filePathList;
     }
 
-    public static List<String> extractRar(String inputFilePath, String outputDirPath) {
+    public static List<String> extractRar(String inputFilePath, String outputDirPath) throws IOException {
         List<String> fileList = new ArrayList<>();
         // 创建Archive对象,用于读取rar压缩文件格式
         try {
@@ -108,10 +108,10 @@ public class ExcelUtil {
                 File f = FileUtil.file(outputDirPath + File.separator + fileName);
                 if (fd.isDirectory()) {
                     // 创建新子目录
-                    f.mkdirs();
+                    Files.createDirectories(f.toPath());
                 } else {
                     // 创建新子文件
-                    f.createNewFile();
+                    Files.createFile(f.toPath());
                     // 获取压缩包中的子文件输出流
                     InputStream in = archive.getInputStream(fd);
                     // 复制文件输入流至新子文件
@@ -119,7 +119,8 @@ public class ExcelUtil {
                     fileList.add(f.getAbsolutePath());
                 }
             }
-        } catch (Exception e) {
+        } catch (RarException e) {
+            throw new RuntimeException(e);
         }
         return fileList;
     }
@@ -127,7 +128,7 @@ public class ExcelUtil {
     public static List<String> extractSplitZip(String zipFilePath, String destFilePath) throws IOException {
         List<String> resultList = ListUtil.list(false);
         File file = new File(zipFilePath);
-        try (ZipFile zipFile = new ZipFile(file)) {
+        try (ZipFile zipFile = ZipFile.builder().setFile(file).get()) {
             Enumeration<ZipArchiveEntry> entries = zipFile.getEntries();
             while (entries.hasMoreElements()) {
                 ZipArchiveEntry entry = entries.nextElement();

+ 2 - 2
mo-daq/src/test/java/com/smppw/modaq/MoDaqApplicationTests.java

@@ -35,8 +35,8 @@ public class MoDaqApplicationTests {
     @Test
     public void reportTest() {
         MailboxInfoDTO emailInfoDTO = this.buildMailbox("xx@simuwang.com", "**");
-        Date startDate = DateUtil.parse("2025-02-28 11:13:00", DateConst.YYYY_MM_DD_HH_MM_SS);
-        Date endDate = DateUtil.parse("2025-02-28 11:58:00", DateConst.YYYY_MM_DD_HH_MM_SS);
+        Date startDate = DateUtil.parse("2025-03-05 10:40:00", DateConst.YYYY_MM_DD_HH_MM_SS);
+        Date endDate = DateUtil.parse("2025-03-05 11:42:05", DateConst.YYYY_MM_DD_HH_MM_SS);
         try {
             emailParseService.parseEmail(emailInfoDTO, startDate, endDate);
         } catch (Exception e) {