ソースを参照

fix:修复分卷压缩包解压失败问题

wangzaijun 2 ヶ月 前
コミット
b0984b744d

+ 57 - 0
mo-daq/logs/error.log

@@ -0,0 +1,57 @@
+2025-02-28 11:30:44.261 [main] - [] ERROR com.smppw.modaq.domain.service.EmailParseService:135  - 压缩包解压失败:org.apache.commons.compress.archivers.zip.UnsupportedZipFeatureException: Unsupported feature splitting used in archive.
+	at org.apache.commons.compress.archivers.zip.ZipArchiveInputStream.readFirstLocalFileHeader(ZipArchiveInputStream.java:1052)
+	at org.apache.commons.compress.archivers.zip.ZipArchiveInputStream.getNextZipEntry(ZipArchiveInputStream.java:662)
+	at org.apache.commons.compress.archivers.zip.ZipArchiveInputStream.getNextEntry(ZipArchiveInputStream.java:632)
+	at org.apache.commons.compress.archivers.zip.ZipArchiveInputStream.getNextEntry(ZipArchiveInputStream.java:74)
+	at com.smppw.modaq.infrastructure.util.ExcelUtil.extractCompressedFiles(ExcelUtil.java:52)
+	at com.smppw.modaq.domain.service.EmailParseService.handleCompressedFiles(EmailParseService.java:180)
+	at com.smppw.modaq.domain.service.EmailParseService.parseZipEmail(EmailParseService.java:159)
+	at com.smppw.modaq.domain.service.EmailParseService.parseEmail(EmailParseService.java:132)
+	at com.smppw.modaq.MoDaqApplicationTests.reportTest(MoDaqApplicationTests.java:41)
+	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
+	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
+	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
+	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
+	at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:767)
+	at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
+	at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)
+	at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:156)
+	at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:147)
+	at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:86)
+	at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(InterceptingExecutableInvoker.java:103)
+	at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.lambda$invoke$0(InterceptingExecutableInvoker.java:93)
+	at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
+	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)
+	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)
+	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)
+	at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:92)
+	at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(Interce
+2025-02-28 11:59:10.901 [main] - [] ERROR com.smppw.modaq.domain.service.EmailParseService:135  - 压缩包解压失败:java.nio.file.FileAlreadyExistsException: \home\wwwroot\mo_report_file\wangzaijun@simuwang.com\20250228\2025022811134020250227_份额及交易确认函_深圳福汇资本管理有限公司_深圳市前海排排网基金销售有限责任公司_TA确认数据\基金分红确认函_GB233C_20250227_莫志刚_202502270107876969.pdf
+	at java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:87)
+	at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
+	at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:108)
+	at java.base/sun.nio.fs.WindowsFileSystemProvider.newByteChannel(WindowsFileSystemProvider.java:236)
+	at java.base/java.nio.file.spi.FileSystemProvider.newOutputStream(FileSystemProvider.java:484)
+	at java.base/java.nio.file.Files.newOutputStream(Files.java:228)
+	at java.base/java.nio.file.Files.copy(Files.java:3160)
+	at com.smppw.modaq.infrastructure.util.ExcelUtil.extractSplitZip(ExcelUtil.java:137)
+	at com.smppw.modaq.infrastructure.util.ExcelUtil.extractCompressedFiles(ExcelUtil.java:84)
+	at com.smppw.modaq.domain.service.EmailParseService.handleCompressedFiles(EmailParseService.java:180)
+	at com.smppw.modaq.domain.service.EmailParseService.parseZipEmail(EmailParseService.java:159)
+	at com.smppw.modaq.domain.service.EmailParseService.parseEmail(EmailParseService.java:132)
+	at com.smppw.modaq.MoDaqApplicationTests.reportTest(MoDaqApplicationTests.java:41)
+	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
+	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
+	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
+	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
+	at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:767)
+	at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
+	at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)
+	at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:156)
+	at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:147)
+	at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:86)
+	at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(InterceptingExecutableInvoker.java:103)
+	at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.lambda$invoke$0(InterceptingExecutableInvoker.java:93)
+	at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
+	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)
+	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.

ファイルの差分が大きいため隠しています
+ 104 - 0
mo-daq/logs/info.log


+ 3 - 0
mo-daq/logs/warn.log

@@ -0,0 +1,3 @@
+2025-02-28 11:24:24.714 [HikariCP-daq housekeeper] - [] WARN  com.zaxxer.hikari.pool.HikariPool:797  - HikariCP-daq - Thread starvation or clock leap detected (housekeeper delta=2m4s973ms252µs900ns).
+2025-02-28 11:30:44.254 [HikariCP-daq housekeeper] - [] WARN  com.zaxxer.hikari.pool.HikariPool:797  - HikariCP-daq - Thread starvation or clock leap detected (housekeeper delta=6m19s540ms3µs800ns).
+2025-02-28 12:13:21.760 [HikariCP-daq housekeeper] - [] WARN  com.zaxxer.hikari.pool.HikariPool:797  - HikariCP-daq - Thread starvation or clock leap detected (housekeeper delta=4m14s130ms409µs500ns).

+ 43 - 0
mo-daq/src/main/java/com/smppw/modaq/infrastructure/util/ExcelUtil.java

@@ -1,6 +1,7 @@
 package com.smppw.modaq.infrastructure.util;
 
 import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.collection.ListUtil;
 import cn.hutool.core.io.FileUtil;
 import cn.hutool.core.util.StrUtil;
 import com.github.junrar.Archive;
@@ -9,10 +10,16 @@ import org.apache.commons.compress.archivers.ArchiveEntry;
 import org.apache.commons.compress.archivers.ArchiveException;
 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 java.io.*;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.util.ArrayList;
+import java.util.Enumeration;
 import java.util.List;
 
 public class ExcelUtil {
@@ -70,6 +77,14 @@ public class ExcelUtil {
                     }
                 }
             }
+        } catch (Exception e) {
+            if (e.getMessage() != null
+                    && (e.getMessage().contains("split")
+                    || e.getMessage().contains("volume"))) {
+                filePathList.addAll(extractSplitZip(zipFilePath, destFilePath));
+            } else {
+                throw e;
+            }
         }
 
         return filePathList;
@@ -108,4 +123,32 @@ public class ExcelUtil {
         }
         return fileList;
     }
+
+    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)) {
+            Enumeration<ZipArchiveEntry> entries = zipFile.getEntries();
+            while (entries.hasMoreElements()) {
+                ZipArchiveEntry entry = entries.nextElement();
+                // 解压到目标目录
+                try (InputStream is = zipFile.getInputStream(entry)) {
+                    Path path = Paths.get(destFilePath, entry.getName());
+                    FileUtil.del(path);
+                    Files.copy(is, path);
+                    resultList.add(path.toAbsolutePath().toString());
+                }
+            }
+        }
+        return resultList;
+    }
+
+    public static void main(String[] args) throws IOException, ArchiveException {
+        String zipFilePath = "1.zip";
+        String destFilePath = "xx";
+        List<String> fileList = extractCompressedFiles(zipFilePath, destFilePath);
+        for (String s : fileList) {
+            System.out.println(s);
+        }
+    }
 }

+ 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-27 09:18:00", DateConst.YYYY_MM_DD_HH_MM_SS);
-        Date endDate = DateUtil.parse("2025-02-27 09:58:00", DateConst.YYYY_MM_DD_HH_MM_SS);
+        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);
         try {
             emailParseService.parseEmail(emailInfoDTO, startDate, endDate);
         } catch (Exception e) {