Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
device-new-platform
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
赵啸非
device-new-platform
Commits
bf12a8da
Commit
bf12a8da
authored
Nov 21, 2024
by
赵啸非
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加巴中经开区windows shell
parent
a1005789
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
93 additions
and
3 deletions
+93
-3
device-manager/src/main/java/com/mortals/xhx/base/system/upload/web/UploadController.java
.../mortals/xhx/base/system/upload/web/UploadController.java
+93
-3
No files found.
device-manager/src/main/java/com/mortals/xhx/base/system/upload/web/UploadController.java
View file @
bf12a8da
package
com.mortals.xhx.base.system.upload.web
;
import
cn.hutool.core.io.FileUtil
;
import
cn.hutool.core.util.StrUtil
;
import
com.alibaba.fastjson.JSONObject
;
import
com.mortals.framework.annotation.UnAuth
;
import
com.mortals.framework.exception.AppException
;
import
com.mortals.framework.web.BaseController
;
import
com.mortals.xhx.base.system.upload.service.UploadService
;
import
com.mortals.xhx.module.device.model.DeviceModuleDistributeEntity
;
import
com.mortals.xhx.module.device.model.DeviceModuleDistributeQuery
;
import
com.mortals.xhx.module.device.service.DeviceModuleDistributeService
;
import
com.mortals.xhx.module.product.model.ProductVersionEntity
;
import
com.mortals.xhx.module.product.service.ProductVersionService
;
import
org.apache.commons.io.IOUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.multipart.MultipartFile
;
import
javax.annotation.Resource
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.ByteArrayOutputStream
;
import
java.io.File
;
import
java.io.IOException
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.zip.ZipEntry
;
import
java.util.zip.ZipOutputStream
;
/**
* 上传文件
...
...
@@ -27,6 +42,11 @@ public class UploadController extends BaseController {
@Resource
private
UploadService
uploadService
;
@Autowired
private
ProductVersionService
productVersionService
;
@Autowired
private
DeviceModuleDistributeService
deviceModuleDistributeService
;
@RequestMapping
(
value
=
"upload"
)
@UnAuth
...
...
@@ -55,7 +75,7 @@ public class UploadController extends BaseController {
@RequestMapping
(
value
=
"commonupload"
)
@UnAuth
public
String
doFileUpload
(
MultipartFile
file
,
@RequestParam
(
value
=
"prePath"
,
defaultValue
=
"file/fileupload"
)
String
prePath
)
{
public
String
doFileUpload
(
MultipartFile
file
,
@RequestParam
(
value
=
"prePath"
,
defaultValue
=
"file/fileupload"
)
String
prePath
)
{
Map
<
String
,
Object
>
model
=
new
HashMap
<>();
String
jsonStr
=
""
;
try
{
...
...
@@ -100,7 +120,7 @@ public class UploadController extends BaseController {
* @param fileName 文件名称
*/
@GetMapping
(
"preview/{fileName}"
)
public
void
preView
(
@PathVariable
(
value
=
"fileName"
)
String
fileName
,
HttpServletResponse
response
)
{
public
void
preView
(
@PathVariable
(
value
=
"fileName"
)
String
fileName
,
HttpServletResponse
response
)
{
try
{
uploadService
.
preview
(
fileName
,
response
);
}
catch
(
Exception
e
)
{
...
...
@@ -114,7 +134,7 @@ public class UploadController extends BaseController {
* @param fileName 文件名称
*/
@GetMapping
(
"fileupload/{fileName}"
)
public
void
fileupload
(
@PathVariable
(
value
=
"fileName"
)
String
fileName
,
HttpServletResponse
response
)
{
public
void
fileupload
(
@PathVariable
(
value
=
"fileName"
)
String
fileName
,
HttpServletResponse
response
)
{
try
{
uploadService
.
uploadDownload
(
fileName
,
response
);
}
catch
(
Exception
e
)
{
...
...
@@ -123,4 +143,74 @@ public class UploadController extends BaseController {
}
/**
* 获取所有相关资源文件并压缩打包成zip
*/
@GetMapping
(
value
=
"zip"
)
@UnAuth
public
void
zip
()
{
JSONObject
jsonObject
=
new
JSONObject
();
try
{
ByteArrayOutputStream
outputStream
=
new
ByteArrayOutputStream
();
ZipOutputStream
zip
=
new
ZipOutputStream
(
outputStream
);
List
<
ProductVersionEntity
>
productVersionEntities
=
productVersionService
.
find
(
new
ProductVersionEntity
());
for
(
ProductVersionEntity
productVersionEntity
:
productVersionEntities
)
{
String
filePath
=
productVersionEntity
.
getFilePath
();
filePath
=
uploadService
.
getFilePath
(
filePath
);
File
file
=
new
File
(
filePath
);
if
(
file
.
exists
())
{
try
{
zip
.
putNextEntry
(
new
ZipEntry
(
StrUtil
.
removePrefix
(
filePath
,
"/"
)));
IOUtils
.
write
(
FileUtil
.
readBytes
(
file
),
zip
);
zip
.
flush
();
zip
.
closeEntry
();
}
catch
(
Exception
e
)
{
log
.
error
(
"异常"
,
e
);
}
}
}
List
<
DeviceModuleDistributeEntity
>
deviceModuleDistributeEntities
=
deviceModuleDistributeService
.
find
(
new
DeviceModuleDistributeQuery
().
siteId
(
1L
));
for
(
DeviceModuleDistributeEntity
deviceModuleDistributeEntity
:
deviceModuleDistributeEntities
)
{
String
filePath
=
deviceModuleDistributeEntity
.
getFilePath
();
filePath
=
uploadService
.
getFilePath
(
filePath
);
File
file
=
new
File
(
filePath
);
if
(
file
.
exists
())
{
try
{
zip
.
putNextEntry
(
new
ZipEntry
(
StrUtil
.
removePrefix
(
filePath
,
"/"
)));
IOUtils
.
write
(
FileUtil
.
readBytes
(
file
),
zip
);
zip
.
flush
();
zip
.
closeEntry
();
}
catch
(
Exception
e
)
{
log
.
error
(
"异常"
,
e
);
}
}
}
IOUtils
.
closeQuietly
(
zip
);
byte
[]
bytes
=
outputStream
.
toByteArray
();
genCode
(
response
,
bytes
);
jsonObject
.
put
(
KEY_RESULT_CODE
,
VALUE_RESULT_SUCCESS
);
jsonObject
.
put
(
KEY_RESULT_MSG
,
"压缩文件成功!"
);
}
catch
(
Exception
e
)
{
log
.
error
(
"获取异常"
,
e
);
jsonObject
.
put
(
KEY_RESULT_CODE
,
VALUE_RESULT_FAILURE
);
}
}
/**
* 生成zip文件
*/
private
void
genCode
(
HttpServletResponse
response
,
byte
[]
data
)
throws
IOException
{
response
.
reset
();
response
.
addHeader
(
"Access-Control-Allow-Origin"
,
"*"
);
response
.
addHeader
(
"Access-Control-Expose-Headers"
,
"Content-Disposition"
);
response
.
setHeader
(
"Content-Disposition"
,
"attachment; filename=\"skin.zip\""
);
response
.
addHeader
(
"Content-Length"
,
""
+
data
.
length
);
response
.
setContentType
(
"application/octet-stream; charset=UTF-8"
);
IOUtils
.
write
(
data
,
response
.
getOutputStream
());
}
}
\ No newline at end of file
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