修复 文件导出
This commit is contained in:
parent
01ab7a07f7
commit
70e2e167a7
|
|
@ -1251,6 +1251,7 @@ public class SaleOrderServiceImpl implements SaleOrderService {
|
|||
log.info("稿件导出 请求wkapp接口返回结果:" + result);
|
||||
//WKHtmlToPdfUtil.convert(templatePath, pdfPath);
|
||||
File file = FileUtil.file(ouput);
|
||||
System.out.println("ouput:"+ouput);
|
||||
files.add(file);
|
||||
delFiles.add(ouput);
|
||||
}
|
||||
|
|
@ -1258,36 +1259,33 @@ public class SaleOrderServiceImpl implements SaleOrderService {
|
|||
if(FuncUtil.isEmpty(files)){
|
||||
throw exception(ErrorCodeConstants.SALE_ORDER_NOT_FILE_EXPORT);
|
||||
}
|
||||
System.out.println("files:"+files);
|
||||
|
||||
String zipFileName = StrUtil.format(targetPath + "/订单稿件_{}.zip", new Date().getTime());
|
||||
|
||||
// 压缩到的位置
|
||||
File zipFile = new File(zipFileName);
|
||||
if(zipFile.exists()){
|
||||
System.out.println("文件:"+zipFileName);
|
||||
ZipUtil.zip(zipFile, false, files.toArray(new File[files.size()]));
|
||||
System.out.println("文件:"+zipFileName);
|
||||
ZipUtil.zip(zipFile, false, files.toArray(new File[files.size()]));
|
||||
|
||||
// 设置响应类型
|
||||
//response.setContentType("application/pdf");
|
||||
response.setContentType("application/octet-stream");
|
||||
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(zipFile.getName(), "UTF-8"));
|
||||
// 设置响应类型
|
||||
//response.setContentType("application/pdf");
|
||||
response.setContentType("application/octet-stream");
|
||||
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(zipFile.getName(), "UTF-8"));
|
||||
|
||||
// 输出PDF到响应输出流
|
||||
// 将文件内容写入响应流
|
||||
try (InputStream inputStream = new FileInputStream(zipFile)) {
|
||||
IoUtil.copy(inputStream, response.getOutputStream());
|
||||
} catch (IOException e) {
|
||||
// 异常处理
|
||||
log.info("写入流失败,{}", e.getMessage());
|
||||
}
|
||||
// 导出完删除
|
||||
delFiles.add(zipFileName);
|
||||
for (String delFile : delFiles) {
|
||||
FileUtil.del(delFile);
|
||||
}
|
||||
}else {
|
||||
System.out.println("文件不存在");
|
||||
// 输出PDF到响应输出流
|
||||
// 将文件内容写入响应流
|
||||
try (InputStream inputStream = new FileInputStream(zipFile)) {
|
||||
IoUtil.copy(inputStream, response.getOutputStream());
|
||||
} catch (IOException e) {
|
||||
// 异常处理
|
||||
log.info("写入流失败,{}", e.getMessage());
|
||||
}
|
||||
// 导出完删除
|
||||
// delFiles.add(zipFileName);
|
||||
// for (String delFile : delFiles) {
|
||||
// FileUtil.del(delFile);
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue