提交 ad9ea009 作者: chenshiqiang

add response header

上级 95fa6172
...@@ -33,6 +33,7 @@ import javax.servlet.http.HttpServletResponse; ...@@ -33,6 +33,7 @@ import javax.servlet.http.HttpServletResponse;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.net.URLEncoder;
import java.util.*; import java.util.*;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
...@@ -230,8 +231,14 @@ public class KnowledgeController { ...@@ -230,8 +231,14 @@ public class KnowledgeController {
@PostMapping(value = "/export") @PostMapping(value = "/export")
public Result<?> exportCollectionXls(HttpServletRequest request, public Result<?> exportCollectionXls(HttpServletRequest request,
String newsIds, String fileIds) { String newsIds, String fileIds) {
knowledgeService.exportExcel(newsIds); log.info("newsIds:{},fileIds:{}",newsIds,fileIds);
knowledgeService.exportPackage(fileIds); if(!newsIds.isEmpty()){
knowledgeService.exportExcel(newsIds);
}
if(!fileIds.isEmpty()){
knowledgeService.exportPackage(fileIds);
}
return Result.OK(true); return Result.OK(true);
} }
...@@ -244,9 +251,11 @@ public class KnowledgeController { ...@@ -244,9 +251,11 @@ public class KnowledgeController {
@RequestMapping(value = "/downloadFile") @RequestMapping(value = "/downloadFile")
public void downloadXls(HttpServletResponse response, String newsIds, String fileIds) { public void downloadXls(HttpServletResponse response, String newsIds, String fileIds) {
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
//获取下载路径 //获取下载路径
Object newsObject = redisUtil.get(newsIds); Object newsObject = redisUtil.get(newsIds);
Object fileObject = redisUtil.get(fileIds); Object fileObject = redisUtil.get(fileIds);
String fileName = UUID.randomUUID().toString().replace("-", "");
String newsFilePath = null; String newsFilePath = null;
String fileFilePath = null; String fileFilePath = null;
if (newsObject != null) { if (newsObject != null) {
...@@ -261,20 +270,30 @@ public class KnowledgeController { ...@@ -261,20 +270,30 @@ public class KnowledgeController {
List<String> list=new ArrayList<>(); List<String> list=new ArrayList<>();
list.add(newsFilePath); list.add(newsFilePath);
list.add(fileFilePath); list.add(fileFilePath);
String filePath = knowledgeService.comprocessByName(list, UUID.randomUUID().toString().replace("-", "")); log.info("newsFilePath:{},fileFilePath:{}",newsFilePath,fileFilePath);
String filePath = knowledgeService.comprocessByName(list,fileName );
log.info("filePath:{}",filePath);
response.setHeader("content-Disposition", "attachment;filename=" + URLEncoder.encode(filePath, "UTF-8"));
ExcelExportUtil.download(response, filePath, true); ExcelExportUtil.download(response, filePath, true);
return; return;
} }
if (fileIds.isEmpty()) {//news if (fileIds.isEmpty()) {//news
log.info("only news downloading"); log.info("only news downloading");
redisUtil.del(newsIds); redisUtil.del(newsIds);
if(newsFilePath==null){
log.error("nothing");
return;
}
log.info("newsFilePath:{}",newsFilePath);
response.setHeader("content-Disposition", "attachment;filename=" + URLEncoder.encode(newsFilePath, "UTF-8"));
ExcelExportUtil.download(response, newsFilePath, true); ExcelExportUtil.download(response, newsFilePath, true);
return; return;
} }
log.info("only files downloading"); log.info("only files downloading");
String s = knowledgeService.exportPackage(fileIds); String s = knowledgeService.exportPackage(fileIds);
log.info("packageFile:{}",s);
response.setHeader("content-Disposition", "attachment;filename=" + URLEncoder.encode(s, "UTF-8"));
ExcelExportUtil.download(response, s, true); ExcelExportUtil.download(response, s, true);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
log.error(e.getMessage()); log.error(e.getMessage());
......
...@@ -721,6 +721,7 @@ class KnowledgeServiceImpl implements IKnowledgeService { ...@@ -721,6 +721,7 @@ class KnowledgeServiceImpl implements IKnowledgeService {
for (KnowledgeVO knowledgeVO : knowledgeVOS) { for (KnowledgeVO knowledgeVO : knowledgeVOS) {
pathList.add(filesStorage + knowledgeVO.getFiles().get(0).getFilePath()); pathList.add(filesStorage + knowledgeVO.getFiles().get(0).getFilePath());
} }
log.info("pathList:{}",pathList);
String filePackage = comprocessByName(pathList, UUID.randomUUID().toString().replace("-","")); String filePackage = comprocessByName(pathList, UUID.randomUUID().toString().replace("-",""));
redisUtil.set(ids, filePackage, 3600 * 24); redisUtil.set(ids, filePackage, 3600 * 24);
return filePackage; return filePackage;
...@@ -742,7 +743,7 @@ class KnowledgeServiceImpl implements IKnowledgeService { ...@@ -742,7 +743,7 @@ class KnowledgeServiceImpl implements IKnowledgeService {
* 将所有的文件都压缩到一个文件中去 * 将所有的文件都压缩到一个文件中去
*/ */
public String comprocessByFile(List<File> fileNamemList, String key) { public String comprocessByFile(List<File> fileNamemList, String key) {
String tmpFile = Constants.USER_HOME + Constants.FSP + "brap" + Constants.FSP + "download" String tmpFile = "/storage" + Constants.FSP + "brap" + Constants.FSP + "download"
+ Constants.FSP; + Constants.FSP;
byte[] buffer = new byte[4096]; byte[] buffer = new byte[4096];
FileInputStream fis = null; FileInputStream fis = null;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论