From 3d44d557ad3741585cbd0561dda4c0a6a630e895 Mon Sep 17 00:00:00 2001 From: PigBaoBei <2739175034@qq.com> Date: Sat, 2 Dec 2023 11:28:54 +0800 Subject: [PATCH] =?UTF-8?q?PC=E5=9B=BE=E7=89=87=E6=89=93=E5=8C=85=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../springblade/common/utils/FileUtil.java | 84 +++++++++++-------- .../impl/DistributionSignforServiceImpl.java | 25 +++--- 2 files changed, 60 insertions(+), 49 deletions(-) diff --git a/blade-biz-common/src/main/java/org/springblade/common/utils/FileUtil.java b/blade-biz-common/src/main/java/org/springblade/common/utils/FileUtil.java index 59b2fc610..9060681eb 100644 --- a/blade-biz-common/src/main/java/org/springblade/common/utils/FileUtil.java +++ b/blade-biz-common/src/main/java/org/springblade/common/utils/FileUtil.java @@ -8,8 +8,7 @@ import java.lang.reflect.Type; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; -import java.util.List; -import java.util.TimerTask; +import java.util.*; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; @@ -25,13 +24,55 @@ public class FileUtil extends TimerTask { private List LocalTempFiles; + + //loadhost +// private static String savePath = "D:/"+"reservationZip/"; + + private static String zipPavePath = CommonConstant.SYSTEMFILEPATH+"reservationZip/"; + + + + + public FileUtil(List list) { this.LocalTempFiles = list; } public static File checkZipFile(String reservationCode) { - String savePath = CommonConstant.SYSTEMFILEPATH+"reservationZip/"+ reservationCode; - return new File(savePath+".zip"); + return new File(zipPavePath+".zip"); + } + + + /** + * 对指定的文件进行压缩,并返回文件名称 + * @param reservationCodes + * @return + */ + public static String reservationPictureFileToZip(String reservationCodes) { + String currentTimeMillis = System.currentTimeMillis()+".zip"; + try{ + //zip文件生成位置 + File zipFile = new File(zipPavePath+"/"+ currentTimeMillis); + FileOutputStream fos = new FileOutputStream(zipFile); + ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(fos)); + for (String s : reservationCodes.split(",")) { + File file = new File(zipPavePath+s); + if (!Objects.isNull(file)){ + fileToZip(zos, file, ""); + } + } + zos.close(); + fos.close(); + }catch (Exception e){ + throw new RuntimeException(e); + } + + return currentTimeMillis; + } + + public static File getZipFile(String fileName) { + + return new File(zipPavePath +fileName); } @@ -56,8 +97,7 @@ public class FileUtil extends TimerTask { */ public static void handleSignPictureZip(List urls, String type, String code, String consignee) { //将图片下载至本地中 - String savePath = CommonConstant.SYSTEMFILEPATH+"reservationZip/"; - String imgPath = savePath+code+"/"; + String imgPath = zipPavePath+code+"/"; // 打开连接 //设置请求超时为20s @@ -90,48 +130,18 @@ public class FileUtil extends TimerTask { //下载远程地址图片 download(imgUrl, imgPath, str); //将该客户的签收图片进行ZIP压缩 - - //读取该文件路径下的文件夹 - File file = new File(savePath); - fileToZip(file); } catch (Exception e) { throw new RuntimeException(e); } } - } - - /** - * sourceFile一定要是文件夹 - * 默认会在同目录下生成zip文件 - * - * @param sourceFile - * @throws Exception - */ - public static void fileToZip(File sourceFile) throws Exception { - - if (!sourceFile.exists()) { - throw new RuntimeException("不存在"); - } - if (!sourceFile.isDirectory()) { - throw new RuntimeException("不是文件夹"); - } - //zip文件生成位置 - File zipFile = new File(sourceFile.getAbsolutePath() + ".zip"); - FileOutputStream fos = new FileOutputStream(zipFile); - ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(fos)); - fileToZip(zos, sourceFile, ""); - zos.close(); - fos.close(); - } - private static void fileToZip(ZipOutputStream zos, File sourceFile, String path) throws Exception { - System.out.println(sourceFile.getAbsolutePath()); + private static void fileToZip(ZipOutputStream zos, File sourceFile, String path) throws Exception { //如果是文件夹只创建zip实体即可,如果是文件,创建zip实体后还要读取文件内容并写入 if (sourceFile.isDirectory()) { path = path + sourceFile.getName() + "/"; diff --git a/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/service/impl/DistributionSignforServiceImpl.java b/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/service/impl/DistributionSignforServiceImpl.java index a0aa1b1f2..50cdd5544 100644 --- a/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/service/impl/DistributionSignforServiceImpl.java +++ b/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/service/impl/DistributionSignforServiceImpl.java @@ -971,10 +971,8 @@ public class DistributionSignforServiceImpl extends BaseServiceImpl parcelListEntities = distributionReservationMapper.selectPackageListByReservationId(distrilbutionloadingscanDTO.getReservationId()); if (Func.isNotEmpty(parcelListEntities)){ boolean isHave = parcelListEntities.stream().map(DistributionParcelListEntity::getOrderPackageCode).anyMatch(c -> c.contains(distrilbutionloadingscanDTO.getBarcode())); - if (Func.isNotEmpty(isHave)){ + if (isHave){ return Resp.scanFail("请在订制品页面扫描此码", "请在订制品页面扫描此码"); - }else { - return Resp.scanFail("扫描错误", "未知二维码"); } } @@ -3035,6 +3033,7 @@ public class DistributionSignforServiceImpl extends BaseServiceImpl fileList = new ArrayList<>(); List signIds = Func.toLongList(",", ids); + List reservationCodes= new ArrayList<>(); List distributionSignforEntities = this.listByIds(signIds); if (Func.isNotEmpty(distributionSignforEntities)) { for (DistributionSignforEntity distributionSignforEntity : distributionSignforEntities) { @@ -3050,26 +3049,28 @@ public class DistributionSignforServiceImpl extends BaseServiceImpl