|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
package com.glxp.api.controller.sync;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
|
|
import com.glxp.api.common.enums.ResultEnum;
|
|
|
|
|
import com.glxp.api.common.res.BaseResponse;
|
|
|
|
@ -18,6 +19,13 @@ import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import javax.servlet.ServletOutputStream;
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.net.URLEncoder;
|
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
@ -80,6 +88,62 @@ public class SpsSyncDownloadController {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@GetMapping("/sps/sync/download/info/file")
|
|
|
|
|
public void downloadFile(HttpServletResponse response, String id){
|
|
|
|
|
if (StrUtil.isBlank(id)) {
|
|
|
|
|
throw new RuntimeException("缺少唯一标识");
|
|
|
|
|
}
|
|
|
|
|
BasicDownloadStatusEntity info = basicDownloadService.getById(id);
|
|
|
|
|
if (info == null) {
|
|
|
|
|
throw new RuntimeException("数据不存在");
|
|
|
|
|
}
|
|
|
|
|
if (StrUtil.isBlank(info.getCacheFilePath())) {
|
|
|
|
|
throw new RuntimeException("文件未生成");
|
|
|
|
|
}
|
|
|
|
|
File file = new File(info.getCacheFilePath());
|
|
|
|
|
if (!file.exists()) {
|
|
|
|
|
throw new RuntimeException("文件丢失");
|
|
|
|
|
}
|
|
|
|
|
String[] split = info.getCacheFilePath().split("/");
|
|
|
|
|
String enFileName = URLEncoder.encode(split[split.length - 1], StandardCharsets.UTF_8);
|
|
|
|
|
// 设值返回文件属性,浏览器会根据属性调用下载文件方法
|
|
|
|
|
response.addHeader("Content-Disposition", "attachment;filename=" + enFileName);
|
|
|
|
|
// 前端获取文件名,需要解码
|
|
|
|
|
response.addHeader("downLoadName", enFileName);
|
|
|
|
|
// 定义输出流
|
|
|
|
|
ServletOutputStream outputStream = null;
|
|
|
|
|
FileInputStream fileInputStream = null;
|
|
|
|
|
try {
|
|
|
|
|
outputStream = response.getOutputStream();
|
|
|
|
|
// 定义输出类型为二进制流输出
|
|
|
|
|
response.setContentType("application/octet-stream");
|
|
|
|
|
fileInputStream = new FileInputStream(file);
|
|
|
|
|
byte[] bytes = new byte[fileInputStream.available()];
|
|
|
|
|
fileInputStream.read(bytes);
|
|
|
|
|
// 把流写入response
|
|
|
|
|
outputStream.write(bytes);
|
|
|
|
|
// flush落盘
|
|
|
|
|
outputStream.flush();
|
|
|
|
|
// 关闭输出流
|
|
|
|
|
outputStream.close();
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
} finally {
|
|
|
|
|
if (outputStream != null) {
|
|
|
|
|
try {
|
|
|
|
|
outputStream.close();
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (fileInputStream != null) {
|
|
|
|
|
try {
|
|
|
|
|
fileInputStream.close();
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|