Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
H
hg-smart
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
platform
hg-smart
Commits
cbb3f91b
Commit
cbb3f91b
authored
Jun 21, 2024
by
liuyang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
2024-06-21 附件预览
parent
98f1ce71
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
80 additions
and
2 deletions
+80
-2
FileDownloadController.java
.../com/baosight/hggp/controller/FileDownloadController.java
+80
-2
No files found.
src/main/java/com/baosight/hggp/controller/FileDownloadController.java
View file @
cbb3f91b
package
com
.
baosight
.
hggp
.
controller
;
package
com
.
baosight
.
hggp
.
controller
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baosight.hggp.core.tools.ThreadLocalTools
;
import
com.baosight.hggp.core.tools.ThreadLocalTools
;
import
com.baosight.hggp.util.FileUtils
;
import
com.baosight.hggp.util.FileUtils
;
import
com.baosight.hggp.util.LogUtils
;
import
com.baosight.hggp.util.LogUtils
;
import
com.baosight.hggp.util.MapUtils
;
import
com.baosight.hggp.util.MapUtils
;
import
com.baosight.hggp.util.StringUtils
;
import
com.baosight.hggp.util.StringUtils
;
import
com.baosight.iplat4j.config.AdminFactoryConfig
;
import
com.baosight.iplat4j.core.ei.EiConstant
;
import
com.baosight.iplat4j.core.ei.EiConstant
;
import
com.baosight.iplat4j.core.ei.EiInfo
;
import
com.baosight.iplat4j.core.ei.EiInfo
;
import
com.baosight.iplat4j.core.exception.PlatException
;
import
com.baosight.iplat4j.core.exception.PlatException
;
import
com.baosight.iplat4j.core.service.soa.XServiceManager
;
import
com.baosight.iplat4j.core.service.soa.XServiceManager
;
import
com.baosight.iplat4j.eu.dm.document.bos.s3.api.signed.SignedBosHelp
;
import
com.baosight.iplat4j.eu.dm.document.bos.s3.api.signed.SignedBosHelp
;
import
com.baosight.iplat4j.eu.dm.document.bos.s3.param.BosParamHelp
;
import
com.baosight.iplat4j.eu.dm.document.bos.s3.param.BosParamHelp
;
import
com.baosight.iplat4j.eu.dm.util.IFileUploader
;
import
com.google.common.base.Joiner
;
import
com.google.common.base.Joiner
;
import
org.activiti.engine.impl.util.json.JSONString
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.CrossOrigin
;
import
org.springframework.web.bind.annotation.CrossOrigin
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.PathVariable
;
...
@@ -19,8 +25,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
...
@@ -19,8 +25,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
import
java.io.*
;
import
java.io.UnsupportedEncodingException
;
import
java.net.URL
;
import
java.net.URL
;
import
java.net.URLEncoder
;
import
java.net.URLEncoder
;
import
java.util.HashMap
;
import
java.util.HashMap
;
...
@@ -81,6 +86,21 @@ public class FileDownloadController {
...
@@ -81,6 +86,21 @@ public class FileDownloadController {
response
.
getWriter
().
write
(
msg
);
response
.
getWriter
().
write
(
msg
);
}
}
}
}
@RequestMapping
({
"docId/{docId}"
})
public
void
downloadUrls
(
@PathVariable
String
docId
,
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
IOException
{
String
docJson
=
AdminFactoryConfig
.
getFileUpLoadInterface
().
getDocJSONById
(
docId
);
Map
document
=
(
Map
)
JSON
.
parseObject
(
docJson
,
Map
.
class
);
String
docName
=
document
.
get
(
"docName"
).
toString
();
String
chgName
=
document
.
get
(
"chgName"
).
toString
();
String
docPath
=
document
.
get
(
"realPath"
).
toString
();
String
filePath
=
docPath
+
"/"
+
chgName
;
try
{
this
.
httpDownload
(
response
,
filePath
,
docName
);
}
catch
(
Exception
e
)
{
String
msg
=
String
.
format
(
"下载文件【%s】失败!原因:%s"
,
docId
,
LogUtils
.
getMsg
(
e
));
response
.
getWriter
().
write
(
msg
);
}
}
private
String
getReturnUrlByParam
(
Map
<
String
,
String
[]>
parameterMap
,
String
returnUrl
)
private
String
getReturnUrlByParam
(
Map
<
String
,
String
[]>
parameterMap
,
String
returnUrl
)
throws
UnsupportedEncodingException
{
throws
UnsupportedEncodingException
{
...
@@ -139,4 +159,62 @@ public class FileDownloadController {
...
@@ -139,4 +159,62 @@ public class FileDownloadController {
return
strBuilder
.
toString
();
return
strBuilder
.
toString
();
}
}
private
void
httpDownload
(
HttpServletResponse
response
,
String
filePath
,
String
downloadFileName
)
throws
Exception
{
File
file
=
new
File
(
filePath
);
FileInputStream
fileInputStream
=
new
FileInputStream
(
file
);
Throwable
var6
=
null
;
try
{
OutputStream
outputStream
=
response
.
getOutputStream
();
Throwable
var8
=
null
;
try
{
downloadFileName
=
URLEncoder
.
encode
(
downloadFileName
,
"UTF-8"
);
downloadFileName
=
downloadFileName
.
replaceAll
(
"\\+"
,
"%20"
);
response
.
reset
();
response
.
setContentType
(
"application/octet-stream"
);
response
.
setHeader
(
"Content-Disposition"
,
"attachment;filename*=utf-8''"
+
downloadFileName
);
byte
[]
buffer
=
new
byte
[
1024
];
int
i
;
while
((
i
=
fileInputStream
.
read
(
buffer
))
>
0
)
{
outputStream
.
write
(
buffer
,
0
,
i
);
}
}
catch
(
Throwable
var32
)
{
var8
=
var32
;
throw
var32
;
}
finally
{
if
(
outputStream
!=
null
)
{
if
(
var8
!=
null
)
{
try
{
outputStream
.
close
();
}
catch
(
Throwable
var31
)
{
var8
.
addSuppressed
(
var31
);
}
}
else
{
outputStream
.
close
();
}
}
}
}
catch
(
Throwable
var34
)
{
var6
=
var34
;
throw
var34
;
}
finally
{
if
(
fileInputStream
!=
null
)
{
if
(
var6
!=
null
)
{
try
{
fileInputStream
.
close
();
}
catch
(
Throwable
var30
)
{
var6
.
addSuppressed
(
var30
);
}
}
else
{
fileInputStream
.
close
();
}
}
}
}
}
}
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