Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
chnmuseum-party
Project
Project
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
liqin
chnmuseum-party
Commits
5ec5ccf0
Commit
5ec5ccf0
authored
4 years ago
by
liqin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bug fixed
parent
c74324d4
master
1.0
dev
No related merge requests found
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
125 additions
and
19 deletions
+125
-19
FastDFSUtils.java
...cn/wisenergy/chnmuseum/party/common/dfs/FastDFSUtils.java
+2
-2
VideoEncryptUtil.java
...energy/chnmuseum/party/common/video/VideoEncryptUtil.java
+2
-6
BatchUploadResVO.java
...wisenergy/chnmuseum/party/common/vo/BatchUploadResVO.java
+2
-1
ShiroConfig.java
...n/java/cn/wisenergy/chnmuseum/party/conf/ShiroConfig.java
+1
-0
Asset.java
src/main/java/cn/wisenergy/chnmuseum/party/model/Asset.java
+18
-0
AssetController.java
...nergy/chnmuseum/party/web/controller/AssetController.java
+80
-6
FileUploadController.java
.../chnmuseum/party/web/controller/FileUploadController.java
+20
-4
No files found.
src/main/java/cn/wisenergy/chnmuseum/party/common/dfs/FastDFSUtils.java
View file @
5ec5ccf0
...
...
@@ -105,11 +105,11 @@ public class FastDFSUtils {
/**
* 下载文件(字节数组)
*/
public
static
BufferedInputStream
downloadFile
(
String
fileUrl
,
OutputStream
outputStream
)
{
public
static
void
downloadFile
(
String
fileUrl
,
OutputStream
outputStream
)
{
fileUrl
=
fileUrl
.
replace
(
dfsFileAccessBasePath
+
"/"
,
""
);
String
groupName
=
fileUrl
.
substring
(
0
,
fileUrl
.
indexOf
(
"/"
));
String
path
=
fileUrl
.
substring
(
fileUrl
.
indexOf
(
"/"
)
+
1
);
return
storageClient
.
downloadFile
(
groupName
,
path
,
new
DownloadFileStream
(
outputStream
));
storageClient
.
downloadFile
(
groupName
,
path
,
new
DownloadFileStream
(
outputStream
));
}
/**
...
...
This diff is collapsed.
Click to expand it.
src/main/java/cn/wisenergy/chnmuseum/party/common/video/VideoEncryptUtil.java
View file @
5ec5ccf0
package
cn
.
wisenergy
.
chnmuseum
.
party
.
common
.
video
;
import
lombok.extern.slf4j.Slf4j
;
import
java.io.ByteArrayInputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.nio.charset.StandardCharsets
;
@Slf4j
public
class
VideoEncryptUtil
{
//此为AES128位,如果要求AES256位,需要更新jdk内的包,jdk8发布版本默认不支持
p
rivate
static
final
String
cipher
=
"3348c95c60520be7"
;
p
ublic
static
final
String
cipher
=
"3348c95c60520be7"
;
private
static
final
int
dataLength
=
4096
;
public
static
InputStream
main
(
InputStream
fis
,
String
cipher
)
throws
IOException
{
public
static
InputStream
encrypt
(
InputStream
fis
,
String
cipher
)
throws
IOException
{
final
ByteArrayOutputStream
[]
outputStream
=
new
ByteArrayOutputStream
[
1
];
AesCipherDataSink
encryptingDataSink
=
new
AesCipherDataSink
(
cipher
.
getBytes
(
StandardCharsets
.
UTF_8
),
new
DataSink
()
{
...
...
@@ -42,7 +39,6 @@ public class VideoEncryptUtil {
}
encryptingDataSink
.
close
();
fis
.
close
();
log
.
info
(
"加解密完成"
);
return
new
ByteArrayInputStream
(
outputStream
[
0
].
toByteArray
());
}
...
...
This diff is collapsed.
Click to expand it.
src/main/java/cn/wisenergy/chnmuseum/party/common/vo/BatchUploadResVO.java
View file @
5ec5ccf0
...
...
@@ -7,6 +7,7 @@ import lombok.Data;
import
lombok.experimental.Accessors
;
import
java.util.List
;
import
java.util.Set
;
/**
* 批量操作响应结果
...
...
@@ -34,7 +35,7 @@ public class BatchUploadResVO {
private
List
<
HandleResult
>
handleList
;
@ApiModelProperty
(
"成功上传的文件集合"
)
private
Lis
t
<
Asset
>
fileList
;
private
Se
t
<
Asset
>
fileList
;
@Data
public
static
class
HandleResult
{
...
...
This diff is collapsed.
Click to expand it.
src/main/java/cn/wisenergy/chnmuseum/party/conf/ShiroConfig.java
View file @
5ec5ccf0
...
...
@@ -94,6 +94,7 @@ public class ShiroConfig {
filterChainDefinitionMap
.
put
(
"/loginByQrCode"
,
"anon"
);
filterChainDefinitionMap
.
put
(
"/doc.html"
,
"anon"
);
filterChainDefinitionMap
.
put
(
"/swagger-ui.html"
,
"anon"
);
filterChainDefinitionMap
.
put
(
"/asset/download1"
,
"anon"
);
filterChainDefinitionMap
.
put
(
"/404"
,
"anon"
);
filterChainDefinitionMap
.
put
(
"/500"
,
"anon"
);
...
...
This diff is collapsed.
Click to expand it.
src/main/java/cn/wisenergy/chnmuseum/party/model/Asset.java
View file @
5ec5ccf0
...
...
@@ -8,6 +8,7 @@ import lombok.experimental.Accessors;
import
java.io.Serializable
;
import
java.time.LocalDateTime
;
import
java.util.Objects
;
/**
* <p>
...
...
@@ -105,4 +106,21 @@ public class Asset implements Serializable {
@TableField
(
exist
=
false
)
private
String
videoContentCopyrightOwnerName
;
@Override
public
boolean
equals
(
Object
o
)
{
if
(
this
==
o
)
{
return
true
;
}
if
(
o
==
null
||
getClass
()
!=
o
.
getClass
())
{
return
false
;
}
Asset
asset
=
(
Asset
)
o
;
return
md5
.
equals
(
asset
.
md5
);
}
@Override
public
int
hashCode
()
{
return
Objects
.
hash
(
md5
);
}
}
This diff is collapsed.
Click to expand it.
src/main/java/cn/wisenergy/chnmuseum/party/web/controller/AssetController.java
View file @
5ec5ccf0
package
cn
.
wisenergy
.
chnmuseum
.
party
.
web
.
controller
;
import
cn.hutool.core.util.ZipUtil
;
import
cn.wisenergy.chnmuseum.party.common.dfs.FastDFSUtils
;
import
cn.wisenergy.chnmuseum.party.common.video.VideoEncryptUtil
;
import
cn.wisenergy.chnmuseum.party.common.vo.GenericPageParam
;
import
cn.wisenergy.chnmuseum.party.model.Asset
;
import
cn.wisenergy.chnmuseum.party.service.AssetService
;
import
cn.wisenergy.chnmuseum.party.web.controller.base.BaseController
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.github.tobato.fastdfs.domain.fdfs.MetaData
;
import
com.sun.xml.internal.messaging.saaj.util.ByteOutputStream
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiImplicitParams
;
...
...
@@ -14,12 +18,19 @@ import io.swagger.annotations.ApiOperation;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.shiro.authz.annotation.RequiresAuthentication
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.web.bind.annotation.*
;
import
javax.annotation.Resource
;
import
javax.servlet.ServletOutputStream
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.net.URLEncoder
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
/**
* <pre>
...
...
@@ -78,19 +89,82 @@ public class AssetController extends BaseController {
@ApiImplicitParam
(
name
=
"idList"
,
value
=
"视频文件标识ID集合"
,
dataType
=
"String"
,
paramType
=
"path"
)
})
@PostMapping
(
"/download"
)
@RequiresAuthentication
//@RequiresPermissions("asset:download")
public
void
download
(
@RequestParam
(
"idList"
)
List
<
String
>
idList
)
{
//@RequiresAuthentication
public
void
download
(
@RequestParam
(
"idList"
)
List
<
String
>
idList
,
HttpServletResponse
response
)
throws
IOException
{
response
.
setContentType
(
"application/octet-stream"
);
//保证下载时文件名为指定文件名,避免中文文件名乱码
response
.
addHeader
(
HttpHeaders
.
CONTENT_DISPOSITION
,
"attachment; filename=\""
+
URLEncoder
.
encode
(
"1.zip"
,
"UTF-8"
)
+
"\""
);
final
List
<
Asset
>
assetList
=
assetService
.
listByIds
(
idList
);
InputStream
[]
inputStreams
=
new
InputStream
[
idList
.
size
()];
for
(
Asset
asset
:
assetList
)
{
final
InputStream
[]
inputStreams
=
new
InputStream
[
idList
.
size
()];
final
String
[]
paths
=
new
String
[
idList
.
size
()];
for
(
int
i
=
0
;
i
<
assetList
.
size
();
i
++)
{
final
Asset
asset
=
assetList
.
get
(
i
);
final
String
fileUrl
=
asset
.
getFileUrl
();
final
InputStream
inputStream
=
FastDFSUtils
.
downloadFile
(
fileUrl
);
ByteOutputStream
byteOutputStream
=
new
ByteOutputStream
();
FastDFSUtils
.
downloadFile
(
fileUrl
,
byteOutputStream
);
inputStreams
[
i
]
=
VideoEncryptUtil
.
encrypt
(
byteOutputStream
.
newInputStream
(),
VideoEncryptUtil
.
cipher
);
final
Set
<
MetaData
>
fileMetaData
=
FastDFSUtils
.
getFileMetaData
(
fileUrl
);
String
md5
=
fileMetaData
.
stream
().
filter
(
x
->
"MD5"
.
equals
(
x
.
getName
())).
map
(
MetaData:
:
getValue
).
findFirst
().
get
();
paths
[
i
]
=
md5
+
".chnmuseum"
;
}
ServletOutputStream
outputStream
=
response
.
getOutputStream
();
ZipUtil
.
zip
(
outputStream
,
paths
,
inputStreams
);
}
@ApiOperation
(
value
=
"视频文件汇出"
,
notes
=
"视频文件汇出"
)
@ApiImplicitParams
({
@ApiImplicitParam
(
name
=
"idList"
,
value
=
"视频文件标识ID集合"
,
dataType
=
"String"
,
paramType
=
"path"
)
})
@GetMapping
(
"/download1"
)
//@RequiresAuthentication
public
void
download1
(
@RequestParam
(
"idList"
)
List
<
String
>
idList
,
HttpServletResponse
response
)
throws
IOException
{
response
.
setContentType
(
"application/octet-stream"
);
//保证下载时文件名为指定文件名,避免中文文件名乱码
response
.
addHeader
(
HttpHeaders
.
CONTENT_DISPOSITION
,
"attachment; filename=\""
+
URLEncoder
.
encode
(
"1.zip"
,
"UTF-8"
)
+
"\""
);
final
List
<
Asset
>
assetList
=
assetService
.
listByIds
(
idList
);
final
InputStream
[]
inputStreams
=
new
InputStream
[
idList
.
size
()];
final
String
[]
paths
=
new
String
[
idList
.
size
()];
for
(
int
i
=
0
;
i
<
assetList
.
size
();
i
++)
{
final
Asset
asset
=
assetList
.
get
(
i
);
final
String
fileUrl
=
asset
.
getFileUrl
();
ByteOutputStream
byteOutputStream
=
new
ByteOutputStream
();
FastDFSUtils
.
downloadFile
(
fileUrl
,
byteOutputStream
);
inputStreams
[
i
]
=
VideoEncryptUtil
.
encrypt
(
byteOutputStream
.
newInputStream
(),
VideoEncryptUtil
.
cipher
);
final
Set
<
MetaData
>
fileMetaData
=
FastDFSUtils
.
getFileMetaData
(
fileUrl
);
String
md5
=
fileMetaData
.
stream
().
filter
(
x
->
"MD5"
.
equals
(
x
.
getName
())).
map
(
MetaData:
:
getValue
).
findFirst
().
get
();
paths
[
i
]
=
md5
+
".chnmuseum"
;
}
ServletOutputStream
outputStream
=
response
.
getOutputStream
();
ZipUtil
.
zip
(
outputStream
,
paths
,
inputStreams
);
}
@ApiOperation
(
value
=
"视频文件汇出"
,
notes
=
"视频文件汇出"
)
@ApiImplicitParams
({
@ApiImplicitParam
(
name
=
"idList"
,
value
=
"视频文件标识ID集合"
,
dataType
=
"String"
,
paramType
=
"path"
)
})
@GetMapping
(
"/download2"
)
//@RequiresAuthentication
public
void
download2
(
@RequestParam
(
"idList"
)
List
<
String
>
idList
,
HttpServletResponse
response
)
throws
IOException
{
response
.
setContentType
(
"application/octet-stream"
);
//保证下载时文件名为指定文件名,避免中文文件名乱码
response
.
addHeader
(
HttpHeaders
.
CONTENT_DISPOSITION
,
"attachment; filename=\""
+
URLEncoder
.
encode
(
"1.zip"
,
"UTF-8"
)
+
"\""
);
final
Map
<
String
,
InputStream
>
map
=
new
LinkedHashMap
<>(
idList
.
size
()
+
1
);
final
List
<
Asset
>
assetList
=
assetService
.
listByIds
(
idList
);
for
(
final
Asset
asset
:
assetList
)
{
final
String
fileUrl
=
asset
.
getFileUrl
();
ByteOutputStream
byteOutputStream
=
new
ByteOutputStream
();
FastDFSUtils
.
downloadFile
(
fileUrl
,
byteOutputStream
);
final
Set
<
MetaData
>
fileMetaData
=
FastDFSUtils
.
getFileMetaData
(
fileUrl
);
String
fileName
=
fileMetaData
.
stream
().
filter
(
x
->
"MD5"
.
equals
(
x
.
getName
())).
map
(
MetaData:
:
getValue
).
findFirst
().
get
()
+
".chnmuseum"
;
map
.
put
(
fileName
,
byteOutputStream
.
newInputStream
());
}
ServletOutputStream
outputStream
=
response
.
getOutputStream
();
String
[]
paths
=
map
.
keySet
().
toArray
(
new
String
[
0
]);
InputStream
[]
ins
=
map
.
values
().
toArray
(
new
InputStream
[
0
]);
ZipUtil
.
zip
(
outputStream
,
paths
,
ins
);
}
}
...
...
This diff is collapsed.
Click to expand it.
src/main/java/cn/wisenergy/chnmuseum/party/web/controller/FileUploadController.java
View file @
5ec5ccf0
...
...
@@ -10,6 +10,7 @@ import cn.wisenergy.chnmuseum.party.common.vo.ImageUploadResult;
import
cn.wisenergy.chnmuseum.party.model.Asset
;
import
cn.wisenergy.chnmuseum.party.service.AssetService
;
import
cn.wisenergy.chnmuseum.party.web.controller.base.BaseController
;
import
com.baomidou.mybatisplus.core.toolkit.Wrappers
;
import
com.github.tobato.fastdfs.domain.fdfs.FileInfo
;
import
com.github.tobato.fastdfs.domain.fdfs.MetaData
;
import
io.swagger.annotations.Api
;
...
...
@@ -80,7 +81,7 @@ public class FileUploadController extends BaseController {
int
failureCount
=
0
;
List
<
BatchUploadResVO
.
HandleResult
>
handleList
=
new
ArrayList
<>();
List
<
Asset
>
datumUrlList
=
new
ArrayLis
t
<>();
Set
<
Asset
>
datumUrlList
=
new
LinkedHashSe
t
<>();
for
(
MultipartFile
file
:
files
)
{
// 当前维度表下线结果
BatchUploadResVO
.
HandleResult
handleResult
=
new
BatchUploadResVO
.
HandleResult
();
...
...
@@ -268,7 +269,7 @@ public class FileUploadController extends BaseController {
int
failureCount
=
0
;
List
<
BatchUploadResVO
.
HandleResult
>
handleList
=
new
ArrayList
<>();
List
<
Asset
>
videoUrlList
=
new
ArrayLis
t
<>();
Set
<
Asset
>
videoUrlList
=
new
LinkedHashSe
t
<>();
for
(
MultipartFile
file
:
files
)
{
// 当前维度表下线结果
BatchUploadResVO
.
HandleResult
handleResult
=
new
BatchUploadResVO
.
HandleResult
();
...
...
@@ -380,7 +381,7 @@ public class FileUploadController extends BaseController {
int
failureCount
=
0
;
List
<
BatchUploadResVO
.
HandleResult
>
handleList
=
new
ArrayList
<>();
List
<
Asset
>
fileList
=
new
ArrayLis
t
<>();
Set
<
Asset
>
fileList
=
new
LinkedHashSe
t
<>();
for
(
MultipartFile
file
:
files
)
{
// 当前维度表下线结果
BatchUploadResVO
.
HandleResult
handleResult
=
new
BatchUploadResVO
.
HandleResult
();
...
...
@@ -433,6 +434,21 @@ public class FileUploadController extends BaseController {
final
FileInfo
fileInfo
=
FastDFSUtils
.
getFileInfo
(
fileUrl
);
final
Set
<
MetaData
>
fileMetaData
=
FastDFSUtils
.
getFileMetaData
(
fileUrl
);
String
md5
=
fileMetaData
.
stream
().
filter
(
x
->
"MD5"
.
equals
(
x
.
getName
())).
map
(
MetaData:
:
getValue
).
findFirst
().
get
();
final
Asset
one
=
this
.
assetService
.
getOne
(
Wrappers
.<
Asset
>
lambdaQuery
().
eq
(
Asset:
:
getMd5
,
md5
));
if
(
one
!=
null
)
{
FastDFSUtils
.
deleteFile
(
fileUrl
);
fileList
.
add
(
one
);
handleResult
.
setFileUrl
(
fileUrl
);
handleResult
.
setFileName
(
originalFilename
);
handleResult
.
setFileType
(
FileTypeEnum
.
VIDEO
.
getName
());
handleResult
.
setHandleResult
(
HANDLE_STATUS_ENUM
.
SUCCESS
.
getName
());
handleResult
.
setDescription
(
""
);
successCount
++;
handleList
.
add
(
handleResult
);
continue
;
}
final
LocalDateTime
createTime
=
TimeUtils
.
getDateTimeOfTimestamp
(
fileInfo
.
getCreateTime
()
*
1000
);
final
long
fileSize
=
fileInfo
.
getFileSize
();
final
Asset
asset
=
Asset
.
builder
()
...
...
@@ -490,7 +506,7 @@ public class FileUploadController extends BaseController {
int
failureCount
=
0
;
List
<
BatchUploadResVO
.
HandleResult
>
handleList
=
new
ArrayList
<>();
List
<
Asset
>
fileList
=
new
ArrayLis
t
<>();
Set
<
Asset
>
fileList
=
new
LinkedHashSe
t
<>();
for
(
MultipartFile
file
:
files
)
{
// 当前维度表下线结果
BatchUploadResVO
.
HandleResult
handleResult
=
new
BatchUploadResVO
.
HandleResult
();
...
...
This diff is collapsed.
Click to expand it.
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