Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
cloud-web
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hqzhdj
cloud-web
Commits
442e7700
Commit
442e7700
authored
Jun 12, 2025
by
梅存智
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
返回文件流
parent
ad2c382f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
117 additions
and
0 deletions
+117
-0
cloud-web-manage/src/main/java/com/yizhi/application/accountUtil/FileReadController.java
+114
-0
cloud-web-student/src/main/java/com/yizhi/application/project/controller/TpCommentApiController.java
+3
-0
No files found.
cloud-web-manage/src/main/java/com/yizhi/application/accountUtil/FileReadController.java
0 → 100644
View file @
442e7700
package
com
.
yizhi
.
application
.
accountUtil
;
import
java.io.ByteArrayOutputStream
;
import
java.io.InputStream
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
import
java.net.URLEncoder
;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
com.alibaba.fastjson.JSON
;
import
com.yizhi.core.application.context.ContextHolder
;
import
com.yizhi.core.application.context.RequestContext
;
import
com.yizhi.util.application.domain.EncryptParam
;
import
com.yizhi.util.application.sm2.SM2_NEW
;
/**
* @since 2025/05/29 11:51
*/
@RestController
@RequestMapping
(
"/public/file"
)
public
class
FileReadController
{
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
FileReadController
.
class
);
@GetMapping
(
"/read"
)
public
ResponseEntity
<
byte
[]>
getObject
(
@RequestParam
(
"filePath"
)
String
filePath
)
{
logger
.
info
(
"---------public file read start---------"
);
if
(
StringUtils
.
isEmpty
(
filePath
)){
logger
.
info
(
"---------public file read end filePath error---------"
);
return
ResponseEntity
.
ok
().
contentType
(
MediaType
.
TEXT_EVENT_STREAM
).
body
(
new
byte
[
1
]);
}
EncryptParam
param
=
JSON
.
parseObject
(
SM2_NEW
.
decrypt
(
filePath
),
EncryptParam
.
class
);
if
(
param
==
null
||
StringUtils
.
isEmpty
(
param
.
getData
())
||
param
.
getKey
()
==
null
)
{
logger
.
info
(
"---------public file read end param error---------"
);
return
ResponseEntity
.
ok
().
contentType
(
MediaType
.
TEXT_EVENT_STREAM
).
body
(
new
byte
[
1
]);
}
logger
.
info
(
"---------public file read start param---------{}"
,
JSON
.
toJSONString
(
param
));
RequestContext
requestContext
=
ContextHolder
.
get
();
if
(
requestContext
==
null
||
requestContext
.
getAccountId
()
==
null
){
logger
.
info
(
"---------public file read end requestContext error---------"
);
return
ResponseEntity
.
ok
().
contentType
(
MediaType
.
TEXT_EVENT_STREAM
).
body
(
new
byte
[
1
]);
}
Long
accountId
=
requestContext
.
getAccountId
();
logger
.
info
(
"---------public file read accountId:{}---------"
,
accountId
);
/*if(!accountId.equals(param.getKey())){
logger.info("---------public file read end accountId error---------accountId:{}, key:{}", accountId, param.getKey());
return ResponseEntity.ok().contentType(MediaType.TEXT_EVENT_STREAM).body(new byte[1]);
}*/
URL
url
=
null
;
HttpURLConnection
conn
=
null
;
InputStream
inputStream
=
null
;
ByteArrayOutputStream
baos
=
null
;
String
fileName
=
""
;
byte
[]
bytes
=
null
;
try
{
String
strUrl
=
param
.
getData
();
fileName
=
strUrl
.
substring
(
strUrl
.
lastIndexOf
(
"prefix="
)
+
7
);
logger
.
info
(
"---------public file read start strUrl---------{}, fileName:{}"
,
strUrl
,
fileName
);
url
=
new
URL
(
strUrl
);
conn
=
(
HttpURLConnection
)
url
.
openConnection
();
conn
.
setRequestProperty
(
"User-Agent"
,
"Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)"
);
inputStream
=
conn
.
getInputStream
();
baos
=
new
ByteArrayOutputStream
();
byte
[]
buff
=
new
byte
[
1024
];
int
len
;
while
((
len
=
inputStream
.
read
(
buff
))
!=
-
1
)
{
baos
.
write
(
buff
,
0
,
len
);
}
bytes
=
baos
.
toByteArray
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
try
{
if
(
baos
!=
null
){
baos
.
close
();
}
if
(
inputStream
!=
null
){
inputStream
.
close
();
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
if
(
bytes
==
null
){
logger
.
info
(
"---------public file read end bytes error---------"
);
return
ResponseEntity
.
ok
().
contentType
(
MediaType
.
TEXT_EVENT_STREAM
).
body
(
new
byte
[
1
]);
}
try
{
fileName
=
URLEncoder
.
encode
(
fileName
,
"UTF-8"
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
//设置响应头
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
add
(
HttpHeaders
.
CONTENT_DISPOSITION
,
"attachment; filename="
+
fileName
);
headers
.
setContentType
(
MediaType
.
APPLICATION_OCTET_STREAM
);
headers
.
setContentLength
(
conn
.
getContentLengthLong
());
return
ResponseEntity
.
ok
().
headers
(
headers
).
body
(
bytes
);
}
}
cloud-web-student/src/main/java/com/yizhi/application/project/controller/TpCommentApiController.java
View file @
442e7700
...
...
@@ -137,6 +137,9 @@ public class TpCommentApiController {
@ApiOperation
(
value
=
"PC端培训项目展现我的评论列表"
)
Response
<
PageCommentVo
>
tpCommentMyList
(
@ApiParam
(
value
=
"trCommentVo"
)
@RequestBody
TrCommentVo
trCommentVo
)
{
RequestContext
requestContext
=
ContextHolder
.
get
();
if
(
trCommentVo
.
getBizType
()
==
null
)
{
trCommentVo
.
setBizType
(
10
);
}
Page
<
PageCommentVo
>
commentVoPage
=
tpCommentClient
.
listByMyself
(
trCommentVo
.
getTrainingProjectId
(),
trCommentVo
.
getBizType
(),
requestContext
.
getAccountId
(),
trCommentVo
.
getPageNo
(),
trCommentVo
.
getPageSize
(),
1
);
commentVoPage
=
workUtil
.
fillData
(
commentVoPage
,
requestContext
);
Pair
pair
=
PageTools
.
split
(
commentVoPage
);
...
...
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