From d37bf55e27b7edb61037bccde6cabeda1ddec6b7 Mon Sep 17 00:00:00 2001 From: k94314517 <8417338+k94314517@user.noreply.gitee.com> Date: 星期二, 30 七月 2024 15:54:22 +0800 Subject: [PATCH] git ch --- server/service/src/main/java/com/doumee/core/utils/Constants.java | 51 +++++++++++++++++++++++++++++++++++++++------------ 1 files changed, 39 insertions(+), 12 deletions(-) diff --git a/server/service/src/main/java/com/doumee/core/utils/Constants.java b/server/service/src/main/java/com/doumee/core/utils/Constants.java index 838ddac..3f7b900 100644 --- a/server/service/src/main/java/com/doumee/core/utils/Constants.java +++ b/server/service/src/main/java/com/doumee/core/utils/Constants.java @@ -1,5 +1,6 @@ package com.doumee.core.utils; +import cn.hutool.core.io.IoUtil; import cn.hutool.core.util.IdcardUtil; import com.doumee.core.constants.ResponseStatus; import com.doumee.core.exception.BusinessException; @@ -9,6 +10,7 @@ import com.doumee.dao.business.vo.CountCyclePriceVO; import io.swagger.models.auth.In; import org.apache.commons.collections4.CollectionUtils; +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; @@ -724,7 +726,7 @@ // 鏅�氭柟娉� public static String getName(int index) { - for (ProjectRecord c : ProjectRecord.values()) { + for (MultiFile c : MultiFile.values()) { if (c.getKey() == index) { return c.name; } @@ -734,7 +736,7 @@ // 鏅�氭柟娉� public static String getInfo(int index) { - for (ProjectRecord c : ProjectRecord.values()) { + for (MultiFile c : MultiFile.values()) { if (c.getKey() == index) { return c.noteinfo; } @@ -2202,7 +2204,13 @@ InputStream inStream = null; OutputStream os = null; try { - String tempDir = System.getProperty("java.io.tmpdir")+fileName; + String tempDir = "C:\\hj\\jars\\temp\\"; + File f = new File(tempDir); + if(!f.exists() ){ + f.mkdirs(); + } + tempDir += fileName; + System.out.println(url+"================="+tempDir); file = new File(tempDir); //涓嬭浇 urlfile = new URL(url); @@ -2228,26 +2236,45 @@ } } }catch (Exception e){ - + e.printStackTrace(); } return file; } - public static void packFilesToZip(List<File> files, ServletOutputStream os) throws IOException { - try (ZipArchiveOutputStream zipOutputStream = new ZipArchiveOutputStream(os)) { + 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); - try (FileInputStream fileInputStream = new FileInputStream(file)) { - byte[] buffer = new byte[1024]; - int length; - while ((length = fileInputStream.read(buffer)) > 0) { - zipOutputStream.write(buffer, 0, length); - } + 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