Commit 46e11868 by liyanlin

fix

parent 612c585f
...@@ -19,11 +19,14 @@ import org.springframework.http.HttpHeaders; ...@@ -19,11 +19,14 @@ import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.List; import java.util.List;
...@@ -85,9 +88,20 @@ public class CostPlanController { ...@@ -85,9 +88,20 @@ public class CostPlanController {
GetCostPlanResp byPlanNo = costPlanService.getByPlanNo(costPlanNo); GetCostPlanResp byPlanNo = costPlanService.getByPlanNo(costPlanNo);
String filePath = byPlanNo.getCostPlan().getFilePath(); String filePath = byPlanNo.getCostPlan().getFilePath();
String fileName = byPlanNo.getFileName(); String fileName = byPlanNo.getFileName();
InputStream inputStream;
long contentLength = 0;
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{
FileSystemResource file = new FileSystemResource(filePath);
contentLength = file.contentLength();
inputStream = file.getInputStream();
}
FileSystemResource file = new FileSystemResource(filePath);
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
headers.add("Cache-Control", "no-cache, no-store, must-revalidate"); headers.add("Cache-Control", "no-cache, no-store, must-revalidate");
// new String(fileName.getBytes("UTF-8"),"iso-8859-1") 解决文件下载的时候文件名乱码的问题 // new String(fileName.getBytes("UTF-8"),"iso-8859-1") 解决文件下载的时候文件名乱码的问题
...@@ -98,8 +112,8 @@ public class CostPlanController { ...@@ -98,8 +112,8 @@ public class CostPlanController {
return ResponseEntity return ResponseEntity
.ok() .ok()
.headers(headers) .headers(headers)
.contentLength(file.contentLength()) .contentLength(contentLength)
.contentType(MediaType.parseMediaType("application/octet-stream")) .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