Browse Source

Merge branch 'dev' into pre-production

newStockUp
pref_mail@163.com 1 year ago
parent
commit
338e0aa83f
  1. 84
      blade-biz-common/src/main/java/org/springblade/common/utils/FileUtil.java
  2. 25
      blade-service/logpm-distribution/src/main/java/com/logpm/distribution/service/impl/DistributionSignforServiceImpl.java

84
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<String> LocalTempFiles;
//loadhost
// private static String savePath = "D:/"+"reservationZip/";
private static String zipPavePath = CommonConstant.SYSTEMFILEPATH+"reservationZip/";
public FileUtil(List<String> 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<String> 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() + "/";

25
blade-service/logpm-distribution/src/main/java/com/logpm/distribution/service/impl/DistributionSignforServiceImpl.java

@ -971,10 +971,8 @@ public class DistributionSignforServiceImpl extends BaseServiceImpl<Distribution
List<DistributionParcelListEntity> 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<Distribution
}
List<File> fileList = new ArrayList<>();
List<Long> signIds = Func.toLongList(",", ids);
List<String> reservationCodes= new ArrayList<>();
List<DistributionSignforEntity> distributionSignforEntities = this.listByIds(signIds);
if (Func.isNotEmpty(distributionSignforEntities)) {
for (DistributionSignforEntity distributionSignforEntity : distributionSignforEntities) {
@ -3050,26 +3049,28 @@ public class DistributionSignforServiceImpl extends BaseServiceImpl<Distribution
FileUtil.handleSignPictureZip(urls, k, distributionReservationEntity.getReservationCode(), distributionReservationEntity.getConsignee());
});
File file = FileUtil.checkZipFile(distributionReservationEntity.getReservationCode());
if (Func.isNotEmpty(file)){
fileList.add(file);
}
//拼接ReservationCode
reservationCodes.add(distributionReservationEntity.getReservationCode());
}
}
}
//获取Zip文件
//将指定的文件进行压缩
String fileName = FileUtil.reservationPictureFileToZip(String.join(",",reservationCodes));
//获得压缩后的文件进行前端下载数据推送
File file = FileUtil.getZipFile(fileName);
if (Func.isNotEmpty(file)){
fileList.add(file);
}
if (Func.isNotEmpty(fileList)){
byte[] buffer = new byte[1024 * 1024 * 1024];
FileInputStream fis = null;
BufferedInputStream bis = null;
try {
for (File file : fileList) {
for (File f : fileList) {
ServletOutputStream os = res.getOutputStream();
fis = new FileInputStream(file);
fis = new FileInputStream(f);
bis = new BufferedInputStream(fis);
// res.setHeader("Content-Length", ""+file.listFiles().length);
// res.setContentType("application/zip;charset=UTF-8");

Loading…
Cancel
Save