From 1ad2f74f3c8c6872d57c285809d2384bd3946aa3 Mon Sep 17 00:00:00 2001
From: renkang <8417338+k94314517@user.noreply.gitee.com>
Date: 星期一, 13 一月 2025 09:16:35 +0800
Subject: [PATCH] 客户资料 巡检任务业务

---
 server/system_service/src/main/java/com/doumee/core/utils/Constants.java |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 46 insertions(+), 0 deletions(-)

diff --git a/server/system_service/src/main/java/com/doumee/core/utils/Constants.java b/server/system_service/src/main/java/com/doumee/core/utils/Constants.java
index 29e590d..820bb4d 100644
--- a/server/system_service/src/main/java/com/doumee/core/utils/Constants.java
+++ b/server/system_service/src/main/java/com/doumee/core/utils/Constants.java
@@ -1,7 +1,10 @@
 package com.doumee.core.utils;
 
 
+import cn.hutool.core.io.IoUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.doumee.core.constants.ResponseStatus;
+import com.doumee.core.exception.BusinessException;
 import com.doumee.core.model.LoginUserInfo;
 import com.fasterxml.jackson.annotation.JsonInclude;
 import com.fasterxml.jackson.core.JsonProcessingException;
@@ -9,10 +12,16 @@
 import com.fasterxml.jackson.databind.PropertyNamingStrategy;
 import io.swagger.models.auth.In;
 import org.apache.batik.util.Platform;
+import org.apache.commons.compress.archivers.zip.Zip64Mode;
+import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
+import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.util.CollectionUtils;
 
+import java.io.File;
+import java.io.FileInputStream;
 import java.io.IOException;
+import java.io.OutputStream;
 import java.math.BigDecimal;
 import java.net.URLDecoder;
 import java.text.SimpleDateFormat;
@@ -1528,4 +1537,41 @@
         }
     }
 
+    public static void packFilesToZip(List<File> files, OutputStream os) throws IOException {
+        try {
+            ZipArchiveOutputStream zipOutputStream = new ZipArchiveOutputStream(os);
+            zipOutputStream.setUseZip64(Zip64Mode.AsNeeded);
+            for (File file : files) {
+                if(!file.exists()){
+                    System.out.println("===鏂囦欢涓嶅瓨鍦�======="+file.getPath());
+                    continue;
+                }else{
+                    System.out.println("===鏂囦欢瀛樺湪======="+file.getPath());
+                }
+                ZipArchiveEntry entry = new ZipArchiveEntry(file.getName());
+                zipOutputStream.putArchiveEntry(entry);
+                FileInputStream fileInputStream = new FileInputStream(file);
+                byte[] buffer = new byte[1024];
+                int length;
+                while ((length = fileInputStream.read(buffer)) > 0) {
+                    zipOutputStream.write(buffer, 0, length);
+                }
+                zipOutputStream.closeArchiveEntry();
+                zipOutputStream.flush();
+                IoUtil.close(fileInputStream);
+                file.delete();
+            }
+        }catch (Exception e){
+            throw new BusinessException(ResponseStatus.EXPORT_EXCEL_ERROR.getCode(),"瀵逛笉璧凤紝涓嬭浇鍘嬬缉鏂囦欢澶辫触");
+        }finally {
+            if (os != null) {
+                try {
+                    os.close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+    }
+
 }

--
Gitblit v1.9.3