Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
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
a6b5ebe1
Commit
a6b5ebe1
authored
Mar 25, 2021
by
wzp
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/master'
parents
d15c18f3
a3bd1b70
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
98 additions
and
24 deletions
+98
-24
FastDFSUtils.java
...cn/wisenergy/chnmuseum/party/common/dfs/FastDFSUtils.java
+17
-8
FileTypeEnum.java
.../wisenergy/chnmuseum/party/common/enums/FileTypeEnum.java
+1
-0
FileTypeUtil.java
...n/wisenergy/chnmuseum/party/common/util/FileTypeUtil.java
+0
-5
UeditorServiceFastdfsImpl.java
...nmuseum/party/service/impl/UeditorServiceFastdfsImpl.java
+3
-3
AssetController.java
...nergy/chnmuseum/party/web/controller/AssetController.java
+0
-1
AssetTypeController.java
...y/chnmuseum/party/web/controller/AssetTypeController.java
+10
-2
FileUploadController.java
.../chnmuseum/party/web/controller/FileUploadController.java
+67
-5
No files found.
src/main/java/cn/wisenergy/chnmuseum/party/common/dfs/FastDFSUtils.java
View file @
a6b5ebe1
...
...
@@ -25,7 +25,10 @@ import java.io.ByteArrayInputStream;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.util.*
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.Map
;
import
java.util.Set
;
@Slf4j
@Component
...
...
@@ -51,10 +54,16 @@ public class FastDFSUtils {
FastDFSUtils
.
imageConfig
=
thumbImageConfig
;
}
/**
* 字节流方式上传
*/
public
static
Map
<
String
,
Object
>
uploadImage
(
InputStream
inputStream
,
long
fileSize
,
String
fileName
)
{
public
static
String
uploadFile
(
InputStream
inputStream
,
long
size
,
String
fileName
)
{
final
Set
<
MetaData
>
metaDataSet
=
new
HashSet
<>();
metaDataSet
.
add
(
new
MetaData
(
"fileName"
,
fileName
));
metaDataSet
.
add
(
new
MetaData
(
"fileSize"
,
size
+
""
));
metaDataSet
.
add
(
new
MetaData
(
"fileExtName"
,
FilenameUtils
.
getExtension
(
fileName
)));
final
StorePath
storePath
=
storageClient
.
uploadFile
(
inputStream
,
size
,
FilenameUtils
.
getExtension
(
fileName
),
metaDataSet
);
return
dfsFileAccessBasePath
+
"/"
+
storePath
.
getFullPath
();
}
public
static
Map
<
String
,
Object
>
uploadUeImage
(
InputStream
inputStream
,
long
fileSize
,
String
fileName
)
{
boolean
isImage
=
FileTypeUtil
.
isImageByExtension
(
fileName
);
if
(
isImage
)
{
String
mimeType
=
FileUtil
.
getMimeType
(
fileName
);
...
...
@@ -71,13 +80,13 @@ public class FastDFSUtils {
throw
new
InterfaceException
(
"400"
,
"文件不是图片类型"
);
}
public
static
String
upload
File
(
InputStream
inputStream
,
long
size
,
String
fileName
)
{
public
static
String
upload
Video
(
InputStream
inputStream
,
long
size
,
String
fileName
)
{
Map
<
String
,
Object
>
map
=
CopyStreamUtils
.
copyInputStream
(
inputStream
);
String
md5
=
(
String
)
map
.
get
(
"md5"
);
InputStream
is
=
(
InputStream
)
map
.
get
(
"inputStream"
);
final
LinkedHashSet
<
MetaData
>
metaDataSet
=
new
Linked
HashSet
<>();
metaDataSet
.
add
(
new
MetaData
(
"fileName"
,
"fileName"
));
final
Set
<
MetaData
>
metaDataSet
=
new
HashSet
<>();
metaDataSet
.
add
(
new
MetaData
(
"fileName"
,
fileName
));
metaDataSet
.
add
(
new
MetaData
(
"fileSize"
,
size
+
""
));
metaDataSet
.
add
(
new
MetaData
(
"fileExtName"
,
FilenameUtils
.
getExtension
(
fileName
)));
metaDataSet
.
add
(
new
MetaData
(
"MD5"
,
md5
));
...
...
src/main/java/cn/wisenergy/chnmuseum/party/common/enums/FileTypeEnum.java
View file @
a6b5ebe1
...
...
@@ -2,6 +2,7 @@ package cn.wisenergy.chnmuseum.party.common.enums;
public
enum
FileTypeEnum
{
DATUM
(
"Datum"
,
"资料"
),
IMAGE
(
"Image"
,
"图片"
),
AUDIO
(
"Audio"
,
"音频"
),
VIDEO
(
"Video"
,
"视频"
);
...
...
src/main/java/cn/wisenergy/chnmuseum/party/common/util/FileTypeUtil.java
View file @
a6b5ebe1
...
...
@@ -95,8 +95,6 @@ public class FileTypeUtil {
is
.
read
(
b
);
fileType
=
getFileTypeByStream
(
b
);
is
.
close
();
}
catch
(
FileNotFoundException
e
)
{
e
.
printStackTrace
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
...
...
@@ -140,9 +138,6 @@ public class FileTypeUtil {
ImageReader
reader
=
iter
.
next
();
iis
.
close
();
return
reader
.
getFormatName
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
return
null
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
null
;
...
...
src/main/java/cn/wisenergy/chnmuseum/party/service/impl/UeditorServiceFastdfsImpl.java
View file @
a6b5ebe1
...
...
@@ -47,7 +47,7 @@ public class UeditorServiceFastdfsImpl implements UeditorService {
}
Map
<
String
,
Object
>
uploadResult
;
String
originalFileName
=
multipartFile
.
getOriginalFilename
();
uploadResult
=
FastDFSUtils
.
uploadImage
(
multipartFile
.
getInputStream
(),
multipartFile
.
getSize
(),
originalFileName
);
uploadResult
=
FastDFSUtils
.
upload
Ue
Image
(
multipartFile
.
getInputStream
(),
multipartFile
.
getSize
(),
originalFileName
);
if
((
Boolean
)
uploadResult
.
get
(
"status"
))
{
state
=
new
BaseState
(
true
);
state
.
putInfo
(
"size"
,
uploadResult
.
get
(
"size"
).
toString
());
...
...
@@ -65,7 +65,7 @@ public class UeditorServiceFastdfsImpl implements UeditorService {
public
State
saveBinaryFile
(
InputStream
inputStream
,
long
fileSize
,
String
fileName
)
{
State
state
;
Map
<
String
,
Object
>
uploadResult
=
FastDFSUtils
.
uploadImage
(
inputStream
,
fileSize
,
fileName
);
Map
<
String
,
Object
>
uploadResult
=
FastDFSUtils
.
upload
Ue
Image
(
inputStream
,
fileSize
,
fileName
);
if
((
Boolean
)
uploadResult
.
get
(
"status"
))
{
state
=
new
BaseState
(
true
);
state
.
putInfo
(
"size"
,
uploadResult
.
get
(
"size"
).
toString
());
...
...
@@ -83,7 +83,7 @@ public class UeditorServiceFastdfsImpl implements UeditorService {
State
state
;
ByteArrayInputStream
baos
=
new
ByteArrayInputStream
(
data
);
Map
<
String
,
Object
>
uploadResult
=
FastDFSUtils
.
uploadImage
(
baos
,
0L
,
fileName
);
Map
<
String
,
Object
>
uploadResult
=
FastDFSUtils
.
upload
Ue
Image
(
baos
,
0L
,
fileName
);
if
((
Boolean
)
uploadResult
.
get
(
"status"
))
{
state
=
new
BaseState
(
true
);
state
.
putInfo
(
"size"
,
uploadResult
.
get
(
"size"
).
toString
());
...
...
src/main/java/cn/wisenergy/chnmuseum/party/web/controller/AssetController.java
View file @
a6b5ebe1
...
...
@@ -95,7 +95,6 @@ public class AssetController extends BaseController {
final
List
<
VideoVo
>
filesMetadata
=
new
ArrayList
<>(
asset
.
getVideoUrlList
().
size
());
final
List
<
String
>
videoUrlList
=
asset
.
getVideoUrlList
();
for
(
String
videoUrl
:
videoUrlList
)
{
// 原始文件名
final
Set
<
MetaData
>
metaData
=
FastDFSUtils
.
getFileMetaData
(
videoUrl
);
String
fileName
=
metaData
.
stream
().
filter
(
x
->
"fileName"
.
equals
(
x
.
getName
())).
map
(
MetaData:
:
getValue
).
findFirst
().
get
();
Long
fileSize
=
metaData
.
stream
().
filter
(
x
->
"fileSize"
.
equals
(
x
.
getName
())).
map
(
MetaData:
:
getValue
).
map
(
Long:
:
parseLong
).
findFirst
().
get
();
...
...
src/main/java/cn/wisenergy/chnmuseum/party/web/controller/AssetTypeController.java
View file @
a6b5ebe1
...
...
@@ -4,6 +4,7 @@ import cn.wisenergy.chnmuseum.party.common.validator.groups.Add;
import
cn.wisenergy.chnmuseum.party.common.vo.GenericPageParam
;
import
cn.wisenergy.chnmuseum.party.model.Asset
;
import
cn.wisenergy.chnmuseum.party.model.AssetType
;
import
cn.wisenergy.chnmuseum.party.model.CopyrightOwner
;
import
cn.wisenergy.chnmuseum.party.service.AssetService
;
import
cn.wisenergy.chnmuseum.party.service.AssetTypeService
;
import
cn.wisenergy.chnmuseum.party.service.CopyrightOwnerService
;
...
...
@@ -25,6 +26,7 @@ import org.springframework.web.bind.annotation.*;
import
javax.annotation.Resource
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
/**
* <pre>
...
...
@@ -132,8 +134,14 @@ public class AssetTypeController extends BaseController {
AssetType:
:
getUpdateTime
);
Page
<
AssetType
>
page
=
this
.
assetTypeService
.
page
(
getPage
(),
queryWrapper
);
for
(
AssetType
assetType
:
page
.
getRecords
())
{
LambdaQueryWrapper
<
Asset
>
lambdaQueryWrapper
=
Wrappers
.<
Asset
>
lambdaQuery
().
eq
(
Asset:
:
getAssetTypeId
,
assetType
.
getId
());
//lambdaQueryWrapper.eq(Asset::getAuditStatusAdd)
lambdaQueryWrapper
=
lambdaQueryWrapper
.
select
(
Asset:
:
getId
).
select
(
Asset:
:
getAssetCopyrightOwnerId
);
List
<
Asset
>
assetList
=
this
.
assetService
.
list
(
lambdaQueryWrapper
);
final
List
<
String
>
assetCopyrightOwnerIdList
=
assetList
.
stream
().
map
(
Asset:
:
getAssetCopyrightOwnerId
).
collect
(
Collectors
.
toList
());
List
<
CopyrightOwner
>
copyrightOwnerList
=
this
.
copyrightOwnerService
.
listByIds
(
assetCopyrightOwnerIdList
);
String
copyrightOwnerName
=
copyrightOwnerList
.
stream
().
map
(
CopyrightOwner:
:
getName
).
collect
(
Collectors
.
joining
(
"、"
));
assetType
.
setCopyrightOwnerName
(
copyrightOwnerName
);
}
return
getResult
(
page
);
}
...
...
src/main/java/cn/wisenergy/chnmuseum/party/web/controller/FileUploadController.java
View file @
a6b5ebe1
...
...
@@ -45,6 +45,9 @@ public class FileUploadController {
// 允许上传的格式
private
static
final
String
[]
VIDEO_TYPE
=
new
String
[]{
"MP4"
,
"FLV"
};
// 允许上传的格式
private
static
final
String
[]
DATUM_TYPE
=
new
String
[]{
"PDF"
,
"DOC"
,
"DOCX"
,
"XLS"
,
"XLSX"
,
"PPT"
,
"PPTX"
,
"JPG"
,
"JPEG"
,
"PNG"
,
"BMP"
,
"WBMP"
,
"MP4"
,
"FLV"
};
// @RequestMapping(value = "/upload", method = RequestMethod.POST)
// public ResponseEntity<PicUploadResult> upload(@RequestParam(value = "bc_cover", required = true) MultipartFile uploadFile, HttpServletResponse response) throws Exception {
// // 校验文件扩展名
...
...
@@ -95,8 +98,67 @@ public class FileUploadController {
// return ResponseEntity.status(HttpStatus.CREATED).body(fileUploadResult);
// }
@ApiImplicitParams
({
@ApiImplicitParam
(
name
=
"file"
,
value
=
"资料"
,
paramType
=
"form"
,
dataType
=
"__file"
,
collectionFormat
=
"array"
,
allowMultiple
=
true
)
})
@PostMapping
(
value
=
"/datum/upload"
,
headers
=
"content-type=multipart/form-data"
,
consumes
=
MediaType
.
MULTIPART_FORM_DATA_VALUE
)
@ApiOperation
(
value
=
"资料上传"
,
notes
=
"资料上传"
)
public
ResponseEntity
<
BatchUploadResVO
>
uploadFile
(
@RequestPart
(
value
=
"file"
,
required
=
false
)
MultipartFile
[]
files
)
throws
IOException
{
if
(
files
.
length
==
0
)
{
throw
new
InterfaceException
(
RESPONSE_CODE_ENUM
.
REQUEST_PARAMS_ERROR
.
getCode
(),
"没有文件可供上传"
);
}
int
successCount
=
0
;
int
failureCount
=
0
;
List
<
BatchUploadResVO
.
HandleResult
>
handleList
=
new
ArrayList
<>();
List
<
String
>
videoUrlList
=
new
ArrayList
<>();
for
(
MultipartFile
file
:
files
)
{
// 当前维度表下线结果
BatchUploadResVO
.
HandleResult
handleResult
=
new
BatchUploadResVO
.
HandleResult
();
// 原始文件名
String
originalFilename
=
file
.
getOriginalFilename
();
if
(
StringUtils
.
isBlank
(
originalFilename
))
{
handleResult
.
setFileName
(
""
);
handleResult
.
setFileType
(
FileTypeEnum
.
DATUM
.
getName
());
handleResult
.
setFileUrl
(
""
);
handleResult
.
setHandleResult
(
HANDLE_STATUS_ENUM
.
FAILURE
.
getName
());
handleResult
.
setDescription
(
"文件名为空"
);
failureCount
++;
continue
;
}
handleResult
.
setFileName
(
originalFilename
);
handleResult
.
setFileType
(
FileTypeEnum
.
DATUM
.
getName
());
handleResult
.
setHandleResult
(
HANDLE_STATUS_ENUM
.
SUCCESS
.
getName
());
boolean
anyMatch
=
Arrays
.
stream
(
DATUM_TYPE
).
anyMatch
(
s
->
Objects
.
equals
(
s
,
FilenameUtils
.
getExtension
(
originalFilename
).
toUpperCase
()));
if
(
anyMatch
)
{
String
url
=
FastDFSUtils
.
uploadFile
(
file
.
getInputStream
(),
file
.
getSize
(),
originalFilename
);
handleResult
.
setFileUrl
(
url
);
handleResult
.
setDescription
(
"操作成功"
);
videoUrlList
.
add
(
url
);
successCount
++;
}
else
{
handleResult
.
setFileUrl
(
""
);
handleResult
.
setDescription
(
"文件格式不支持"
);
failureCount
++;
}
// 设置处理的业务表信息
handleList
.
add
(
handleResult
);
}
BatchUploadResVO
batchUploadResVO
=
new
BatchUploadResVO
();
batchUploadResVO
.
setFailureCount
(
failureCount
);
batchUploadResVO
.
setSuccessCount
(
successCount
);
batchUploadResVO
.
setTotal
(
files
.
length
);
batchUploadResVO
.
setHandleList
(
handleList
);
batchUploadResVO
.
setUrlList
(
videoUrlList
);
return
ResponseEntity
.
status
(
HttpStatus
.
CREATED
).
body
(
batchUploadResVO
);
}
@PostMapping
(
value
=
"/image/upload"
,
headers
=
"content-type=multipart/form-data"
,
consumes
=
MediaType
.
MULTIPART_FORM_DATA_VALUE
)
public
ResponseEntity
<
ImageUploadResult
>
uploadFile
(
@RequestParam
(
value
=
"cover"
)
MultipartFile
uploadFile
)
throws
Exception
{
@RequiresPermissions
(
"image:upload"
)
@ApiOperation
(
value
=
"单图片上传"
,
notes
=
"单图片上传"
)
public
ResponseEntity
<
ImageUploadResult
>
uploadImage
(
@RequestParam
(
value
=
"file"
)
MultipartFile
uploadFile
)
throws
Exception
{
if
(
uploadFile
==
null
||
uploadFile
.
getSize
()
==
0
)
{
throw
new
InterfaceException
(
RESPONSE_CODE_ENUM
.
REQUEST_PARAMS_ERROR
.
getCode
(),
"没有文件可供上传"
);
}
...
...
@@ -120,12 +182,12 @@ public class FileUploadController {
}
@ApiImplicitParams
({
@ApiImplicitParam
(
name
=
"file
s
"
,
value
=
"视频文件"
,
paramType
=
"form"
,
dataType
=
"__file"
,
collectionFormat
=
"array"
,
allowMultiple
=
true
)
@ApiImplicitParam
(
name
=
"file"
,
value
=
"视频文件"
,
paramType
=
"form"
,
dataType
=
"__file"
,
collectionFormat
=
"array"
,
allowMultiple
=
true
)
})
@PostMapping
(
value
=
"/video/upload"
,
headers
=
"content-type=multipart/form-data"
,
consumes
=
MediaType
.
MULTIPART_FORM_DATA_VALUE
)
@RequiresPermissions
(
"video:upload"
)
@ApiOperation
(
value
=
"多视频上传"
,
notes
=
"多视频上传"
)
public
ResponseEntity
<
BatchUploadResVO
>
upload
File
(
@RequestPart
(
value
=
"files
"
,
required
=
false
)
MultipartFile
[]
files
)
throws
IOException
{
public
ResponseEntity
<
BatchUploadResVO
>
upload
Video
(
@RequestPart
(
value
=
"file
"
,
required
=
false
)
MultipartFile
[]
files
)
throws
IOException
{
if
(
files
.
length
==
0
)
{
throw
new
InterfaceException
(
RESPONSE_CODE_ENUM
.
REQUEST_PARAMS_ERROR
.
getCode
(),
"没有文件可供上传"
);
}
...
...
@@ -156,10 +218,10 @@ public class FileUploadController {
handleResult
.
setFileName
(
originalFilename
);
handleResult
.
setFileType
(
FileTypeEnum
.
VIDEO
.
getName
());
handleResult
.
setHandleResult
(
HANDLE_STATUS_ENUM
.
FAILURE
.
getName
());
handleResult
.
setHandleResult
(
HANDLE_STATUS_ENUM
.
SUCCESS
.
getName
());
boolean
anyMatch
=
Arrays
.
stream
(
VIDEO_TYPE
).
anyMatch
(
s
->
Objects
.
equals
(
s
,
FilenameUtils
.
getExtension
(
originalFilename
).
toUpperCase
()));
if
(
anyMatch
)
{
String
url
=
FastDFSUtils
.
upload
File
(
file
.
getInputStream
(),
file
.
getSize
(),
originalFilename
);
String
url
=
FastDFSUtils
.
upload
Video
(
file
.
getInputStream
(),
file
.
getSize
(),
originalFilename
);
handleResult
.
setFileUrl
(
url
);
handleResult
.
setDescription
(
"操作成功"
);
videoUrlList
.
add
(
url
);
...
...
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