|
|
@@ -15,9 +15,10 @@ import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.springframework.mock.web.MockMultipartFile; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
import java.io.FileInputStream; |
|
|
|
import java.io.IOException; |
|
|
|
import javax.servlet.ServletOutputStream; |
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import java.io.*; |
|
|
|
import java.nio.file.Files; |
|
|
|
|
|
|
|
/** |
|
|
|
* @Classname MhXchxFileHelper |
|
|
@@ -66,4 +67,27 @@ public class MhXchxFileHelper { |
|
|
|
return JSONUtil.toJsonStr(retFileInfo); |
|
|
|
} |
|
|
|
|
|
|
|
public void exportReport(String reportFile, HttpServletResponse response){ |
|
|
|
if (StrUtils.isBlank(reportFile)) { |
|
|
|
throw BizException.wrap("信创报告文件不能为空"); |
|
|
|
} |
|
|
|
|
|
|
|
File file = mhFileClient.downloadToTmpFile(reportFile); |
|
|
|
// 设置响应的内容类型和头信息 |
|
|
|
response.setContentType("application/octet-stream"); |
|
|
|
response.setHeader("Content-Disposition", "attachment;filename=\"" + file.getName() + "\""); |
|
|
|
|
|
|
|
// 使用ServletOutputStream写文件内容 |
|
|
|
try (InputStream in = Files.newInputStream(file.toPath()); |
|
|
|
ServletOutputStream out = response.getOutputStream()) { |
|
|
|
byte[] buffer = new byte[1024]; |
|
|
|
int bytesRead; |
|
|
|
while ((bytesRead = in.read(buffer)) != -1) { |
|
|
|
out.write(buffer, 0, bytesRead); |
|
|
|
} |
|
|
|
} catch (IOException e) { |
|
|
|
throw new RuntimeException(e); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |