Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation
This project
Loading...
Sign in
李苗
/
Vion-DevOps
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit c90ad753
authored
Jan 11, 2025
by
HlQ
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
[fix] 文件下载文件名问题处理
[feat] 巡检类型任务,文件单独处理
1 parent
6c2d2058
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
5 deletions
src/main/java/vion/controller/FileController.java
src/main/java/vion/controller/TaskController.java
src/main/java/vion/service/impl/TaskServiceImpl.java
src/main/java/vion/controller/FileController.java
View file @
c90ad75
...
...
@@ -11,6 +11,7 @@ import org.dromara.hutool.core.date.TimeUtil;
import
org.dromara.hutool.core.io.file.FileNameUtil
;
import
org.dromara.hutool.core.io.file.FileUtil
;
import
org.dromara.hutool.core.lang.Assert
;
import
org.dromara.hutool.core.net.url.UrlEncoder
;
import
org.dromara.hutool.core.text.StrUtil
;
import
org.dromara.hutool.core.util.ObjUtil
;
import
org.dromara.hutool.crypto.SecureUtil
;
...
...
@@ -30,6 +31,7 @@ import vion.vo.FileInfoVO;
import
java.io.File
;
import
java.io.IOException
;
import
java.nio.charset.StandardCharsets
;
import
java.time.LocalDateTime
;
@RestController
...
...
@@ -67,7 +69,7 @@ public class FileController {
@SaCheckPermission
(
value
=
"file:download"
,
orRole
=
"admin"
)
public
ResponseEntity
<
FileSystemResource
>
download
(
Long
id
)
{
var
fileInfo
=
fileService
.
getById
(
id
);
if
(
ObjUtil
.
isN
otN
ull
(
fileInfo
))
{
if
(
ObjUtil
.
isNull
(
fileInfo
))
{
return
ResponseEntity
.
notFound
().
build
();
}
var
file
=
FileUtil
.
file
(
fileInfo
.
getUrl
());
...
...
@@ -79,7 +81,8 @@ public class FileController {
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
setContentType
(
MediaType
.
valueOf
(
MediaType
.
APPLICATION_OCTET_STREAM_VALUE
));
headers
.
setContentDisposition
(
ContentDisposition
.
attachment
().
filename
(
file
.
getName
()).
build
());
headers
.
setContentDisposition
(
ContentDisposition
.
attachment
().
filename
(
UrlEncoder
.
encodeAll
(
file
.
getName
(),
StandardCharsets
.
UTF_8
).
replace
(
"+"
,
"%20"
)).
build
());
return
ResponseEntity
.
ok
()
.
headers
(
headers
)
...
...
src/main/java/vion/controller/TaskController.java
View file @
c90ad75
...
...
@@ -13,6 +13,7 @@ import lombok.extern.slf4j.Slf4j;
import
org.apache.poi.ss.usermodel.Workbook
;
import
org.dromara.hutool.core.date.TimeUtil
;
import
org.dromara.hutool.core.io.file.FileUtil
;
import
org.dromara.hutool.core.net.url.UrlEncoder
;
import
org.dromara.hutool.core.text.StrUtil
;
import
org.dromara.hutool.core.util.ObjUtil
;
import
org.springframework.core.io.FileSystemResource
;
...
...
@@ -36,6 +37,7 @@ import vion.vo.UserVO;
import
java.awt.*
;
import
java.io.IOException
;
import
java.nio.charset.StandardCharsets
;
import
java.time.LocalDate
;
import
java.time.LocalDateTime
;
import
java.util.List
;
...
...
@@ -206,7 +208,7 @@ public class TaskController {
.
eq
(
FileInfo:
:
getSourceType
,
35
)
.
eq
(
FileInfo:
:
getSourceId
,
taskId
)
.
one
();
if
(
ObjUtil
.
isN
otN
ull
(
fileInfo
))
{
if
(
ObjUtil
.
isNull
(
fileInfo
))
{
return
ResponseEntity
.
notFound
().
build
();
}
var
file
=
FileUtil
.
file
(
fileInfo
.
getUrl
());
...
...
@@ -218,7 +220,8 @@ public class TaskController {
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
setContentType
(
MediaType
.
valueOf
(
MediaType
.
APPLICATION_OCTET_STREAM_VALUE
));
headers
.
setContentDisposition
(
ContentDisposition
.
attachment
().
filename
(
file
.
getName
()).
build
());
headers
.
setContentDisposition
(
ContentDisposition
.
attachment
().
filename
(
UrlEncoder
.
encodeAll
(
file
.
getName
(),
StandardCharsets
.
UTF_8
).
replace
(
"+"
,
"%20"
)).
build
());
return
ResponseEntity
.
ok
()
.
headers
(
headers
)
...
...
src/main/java/vion/service/impl/TaskServiceImpl.java
View file @
c90ad75
...
...
@@ -373,7 +373,12 @@ public class TaskServiceImpl extends MPJBaseServiceImpl<TaskMapper, Task> implem
String
fileExt
=
FileNameUtil
.
extName
(
orgName
);
String
filename
=
StrUtil
.
format
(
"{}_{}.{}"
,
mainName
,
TimeUtil
.
format
(
LocalDateTime
.
now
(),
"yyyyMMdd_HHmmssSSS"
),
fileExt
);
// 默认工单文件路径
String
path
=
fileUrl
+
FileUtil
.
FILE_SEPARATOR
+
task
.
getStoreId
()
+
FileUtil
.
FILE_SEPARATOR
+
task
.
getId
()
+
FileUtil
.
FILE_SEPARATOR
+
filename
;
if
(
task
.
getFaultType
()
==
5
)
{
// 巡检报告单独处理
path
=
fileUrl
+
FileUtil
.
FILE_SEPARATOR
+
task
.
getStoreId
()
+
FileUtil
.
FILE_SEPARATOR
+
task
.
getId
()
+
FileUtil
.
FILE_SEPARATOR
+
"inspection"
+
FileUtil
.
FILE_SEPARATOR
+
filename
;
}
File
file
=
FileUtil
.
touch
(
path
);
try
{
infile
.
transferTo
(
file
);
...
...
@@ -384,7 +389,7 @@ public class TaskServiceImpl extends MPJBaseServiceImpl<TaskMapper, Task> implem
FileInfo
fileInfo
=
new
FileInfo
();
fileInfo
.
setStoreId
(
task
.
getStoreId
());
fileInfo
.
setSourceId
(
task
.
getId
());
fileInfo
.
setSourceType
(
3
);
fileInfo
.
setSourceType
(
task
.
getFaultType
()
==
5
?
35
:
3
);
fileInfo
.
setName
(
filename
);
fileInfo
.
setUrl
(
path
);
fileInfo
.
setType
(
FileNameUtil
.
extName
(
file
));
...
...
Write
Preview
Markdown
is supported
Attach a file
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 post a comment