@@ -23,6 +23,7 @@ import org.springframework.validation.annotation.Validated; | |||||
import org.springframework.web.bind.annotation.*; | import org.springframework.web.bind.annotation.*; | ||||
import javax.servlet.http.HttpServletResponse; | import javax.servlet.http.HttpServletResponse; | ||||
import java.io.UnsupportedEncodingException; | |||||
import java.util.List; | import java.util.List; | ||||
/** | /** | ||||
@@ -153,7 +154,7 @@ public class PurchaseController { | |||||
@GetMapping("/exportXcfhFile/{code}") | @GetMapping("/exportXcfhFile/{code}") | ||||
@ApiOperation("直接导出信创文件") | @ApiOperation("直接导出信创文件") | ||||
public void exportXcfhFile(@PathVariable String code,HttpServletResponse response) { | |||||
public void exportXcfhFile(@PathVariable String code,HttpServletResponse response) throws UnsupportedEncodingException { | |||||
purchaseManage.exportXcfhFile(code,response); | purchaseManage.exportXcfhFile(code,response); | ||||
} | } | ||||
@@ -18,6 +18,7 @@ import org.springframework.stereotype.Component; | |||||
import javax.servlet.ServletOutputStream; | import javax.servlet.ServletOutputStream; | ||||
import javax.servlet.http.HttpServletResponse; | import javax.servlet.http.HttpServletResponse; | ||||
import java.io.*; | import java.io.*; | ||||
import java.net.URLEncoder; | |||||
import java.nio.file.Files; | import java.nio.file.Files; | ||||
/** | /** | ||||
@@ -67,15 +68,15 @@ public class MhXchxFileHelper { | |||||
return JSONUtil.toJsonStr(retFileInfo); | return JSONUtil.toJsonStr(retFileInfo); | ||||
} | } | ||||
public void exportReport(String reportFile, HttpServletResponse response){ | |||||
public void exportReport(String reportFile, HttpServletResponse response) throws UnsupportedEncodingException { | |||||
if (StrUtils.isBlank(reportFile)) { | if (StrUtils.isBlank(reportFile)) { | ||||
throw BizException.wrap("信创报告文件不能为空"); | throw BizException.wrap("信创报告文件不能为空"); | ||||
} | } | ||||
File file = mhFileClient.downloadToTmpFile(reportFile); | File file = mhFileClient.downloadToTmpFile(reportFile); | ||||
// 设置响应的内容类型和头信息 | // 设置响应的内容类型和头信息 | ||||
response.setContentType("application/octet-stream"); | |||||
response.setHeader("Content-Disposition", "attachment;filename=\"" + file.getName() + "\""); | |||||
response.setContentType("application/pdf"); | |||||
response.setHeader("Content-Disposition", "attachment;filename=\"" + URLEncoder.encode(file.getName(),"utf-8") + "\""); | |||||
// 使用ServletOutputStream写文件内容 | // 使用ServletOutputStream写文件内容 | ||||
try (InputStream in = Files.newInputStream(file.toPath()); | try (InputStream in = Files.newInputStream(file.toPath()); | ||||
@@ -80,6 +80,7 @@ import org.springframework.stereotype.Component; | |||||
import org.springframework.transaction.annotation.Transactional; | import org.springframework.transaction.annotation.Transactional; | ||||
import javax.servlet.http.HttpServletResponse; | import javax.servlet.http.HttpServletResponse; | ||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.io.UnsupportedEncodingException; | |||||
import java.math.BigDecimal; | import java.math.BigDecimal; | ||||
import java.math.RoundingMode; | import java.math.RoundingMode; | ||||
import java.time.LocalDateTime; | import java.time.LocalDateTime; | ||||
@@ -755,7 +756,7 @@ public class PurchaseManage { | |||||
return mhXchxFileHelper.getXchxFile(code, null); | return mhXchxFileHelper.getXchxFile(code, null); | ||||
} | } | ||||
public void exportXcfhFile(String code,HttpServletResponse response) { | |||||
public void exportXcfhFile(String code,HttpServletResponse response) throws UnsupportedEncodingException { | |||||
mhXchxFileHelper.exportReport(code, response); | mhXchxFileHelper.exportReport(code, response); | ||||
} | } | ||||
} | } |