Commit 612c585f by liyanlin

fix

parent 7c46287b
......@@ -19,8 +19,11 @@ import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
@Api(tags = "付款计划详情接口")
......@@ -93,16 +96,29 @@ public class CostPlanTempController {
CostPlanTempDomain temp = costPlanTempService.getByTempNo(tempNo);
String filePath = temp.getFilePath();
String fileName = null;
InputStream inputStream = null;
long contentLength = 0;
if (null != filePath) {
String[] split = filePath.split("&");
if (split.length >= 1) {
fileName = split[split.length - 1];
if(filePath.startsWith("http")){
fileName = filePath.substring(filePath.lastIndexOf("/") + 1);
RestTemplate restTemplate = new RestTemplate();
byte[] bytes = restTemplate.getForObject(filePath, byte[].class);
inputStream = new ByteArrayInputStream(bytes);
contentLength = bytes.length;
}
else {
String[] split = filePath.split("&");
if (split.length >= 1) {
fileName = split[split.length - 1];
assert filePath != null;
FileSystemResource file = new FileSystemResource(filePath);
inputStream = file.getInputStream();
contentLength = file.contentLength();
}
}
}
assert filePath != null;
FileSystemResource file = new FileSystemResource(filePath);
HttpHeaders headers = new HttpHeaders();
headers.add("Cache-Control", "no-cache, no-store, must-revalidate");
// new String(fileName.getBytes("UTF-8"),"iso-8859-1") 解决文件下载的时候文件名乱码的问题
......@@ -113,9 +129,9 @@ public class CostPlanTempController {
return ResponseEntity
.ok()
.headers(headers)
.contentLength(file.contentLength())
.contentLength(contentLength)
.contentType(MediaType.parseMediaType("application/octet-stream"))
.body(new InputStreamResource(file.getInputStream()));
.body(new InputStreamResource(inputStream));
}
}
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