Commit e3d3d599 authored by wangqiang's avatar wangqiang

导出模板代码修改

parent f80188a7
...@@ -34,16 +34,21 @@ public class ExtFileTemplateManagerServiceImpl implements ExtFileTemplateManager ...@@ -34,16 +34,21 @@ public class ExtFileTemplateManagerServiceImpl implements ExtFileTemplateManager
InputStream inputStream = null; InputStream inputStream = null;
CustomMultipartFile multipartFile = null; CustomMultipartFile multipartFile = null;
Long fileId = null; Long fileId = null;
String fileName;
try { try {
if(fileType == 1){ //采购计划模板下载 if(fileType == 1){ //采购计划模板下载
fileId = systemFileFeignService.getSystemFileId(Constants.PURCHASE_PLAN_TEMP_FILE_CODE_NAME); fileId = systemFileFeignService.getSystemFileId(Constants.PURCHASE_PLAN_TEMP_FILE_CODE_NAME);
fileName = "采购计划模板(内部)..xlsx";
}else if(fileType == 2){ //IED计划模板下载 }else if(fileType == 2){ //IED计划模板下载
fileId = systemFileFeignService.getSystemFileId(Constants.IED_PLAN_TEMP_FILE_CODE_NAME); fileId = systemFileFeignService.getSystemFileId(Constants.IED_PLAN_TEMP_FILE_CODE_NAME);
fileName = "IED计划模板(内部)..xlsx";
}else if(fileType == 3){ //ICM计划模板下载 }else if(fileType == 3){ //ICM计划模板下载
fileId = systemFileFeignService.getSystemFileId(Constants.ICM_PLAN_TEMP_FILE_CODE_NAME); fileId = systemFileFeignService.getSystemFileId(Constants.ICM_PLAN_TEMP_FILE_CODE_NAME);
}else if (fileType == 4){ fileName = "ICM计划模板(内部)..xlsx";
}else if (fileType == 4){ //进度计划
fileId = systemFileFeignService.getSystemFileId(Constants.PROGRESS_TEMP_FILE_CODE_NAME); fileId = systemFileFeignService.getSystemFileId(Constants.PROGRESS_TEMP_FILE_CODE_NAME);
fileName = "进度计划模板(内部)..xlsx";
}else { }else {
log.info("未知文件类型:{}",fileType); log.info("未知文件类型:{}",fileType);
throw new DxBusinessException("500", "未知文件类型:" + fileType); throw new DxBusinessException("500", "未知文件类型:" + fileType);
...@@ -64,7 +69,7 @@ public class ExtFileTemplateManagerServiceImpl implements ExtFileTemplateManager ...@@ -64,7 +69,7 @@ public class ExtFileTemplateManagerServiceImpl implements ExtFileTemplateManager
//创建采购计划列表.xlsx 文件 //创建采购计划列表.xlsx 文件
FileUtils.inputToFile(inputStream, filePath); FileUtils.inputToFile(inputStream, filePath);
//导出数据 //导出数据
FileUtils.exportFile(response, new FileInputStream(filePath), "application/vnd.ms-excel;charset=utf-8", "计划模板.xlsx"); FileUtils.exportFile(response, new FileInputStream(filePath), "application/vnd.ms-excel;charset=utf-8", fileName);
//删除临时目录 //删除临时目录
FileUtil.del(dir); FileUtil.del(dir);
return ApiResult.SUCCESS; return ApiResult.SUCCESS;
......
...@@ -6,6 +6,7 @@ import lombok.extern.slf4j.Slf4j; ...@@ -6,6 +6,7 @@ import lombok.extern.slf4j.Slf4j;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.*; import java.io.*;
import java.net.URLEncoder;
/** /**
* @author xfchai * @author xfchai
...@@ -38,7 +39,7 @@ public class FileUtils { ...@@ -38,7 +39,7 @@ public class FileUtils {
BufferedOutputStream bouts = new BufferedOutputStream(outs); BufferedOutputStream bouts = new BufferedOutputStream(outs);
response.setContentType(exportType); response.setContentType(exportType);
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition"); response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
response.setHeader("Content-disposition", "attachment;filename=" + name); response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode(name,"UTF-8"));
//修正 Excel在“xxx.xlsx”中发现不可读取的内容。是否恢复此工作薄的内容?如果信任此工作簿的来源,请点击"是" //修正 Excel在“xxx.xlsx”中发现不可读取的内容。是否恢复此工作薄的内容?如果信任此工作簿的来源,请点击"是"
OutputStream out = response.getOutputStream(); OutputStream out = response.getOutputStream();
byte[] b = new byte[2048]; byte[] b = new byte[2048];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment