Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
bailuntec-cost
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
huluobin
bailuntec-cost
Commits
46e11868
Commit
46e11868
authored
Jul 21, 2021
by
liyanlin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
parent
612c585f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
4 deletions
+18
-4
CostPlanController.java
.../blt/other/module/cost/controller/CostPlanController.java
+18
-4
No files found.
cost-service/src/main/java/com/blt/other/module/cost/controller/CostPlanController.java
View file @
46e11868
...
...
@@ -19,11 +19,14 @@ 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
javax.annotation.Resource
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.ByteArrayInputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.math.BigDecimal
;
import
java.nio.charset.StandardCharsets
;
import
java.util.List
;
...
...
@@ -85,9 +88,20 @@ public class CostPlanController {
GetCostPlanResp
byPlanNo
=
costPlanService
.
getByPlanNo
(
costPlanNo
);
String
filePath
=
byPlanNo
.
getCostPlan
().
getFilePath
();
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
();
headers
.
add
(
"Cache-Control"
,
"no-cache, no-store, must-revalidate"
);
// new String(fileName.getBytes("UTF-8"),"iso-8859-1") 解决文件下载的时候文件名乱码的问题
...
...
@@ -98,8 +112,8 @@ public class CostPlanController {
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
));
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment