记得上下班打卡 | git大法好,push需谨慎
Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
liquidnet-bus-v1
Project
Project
Details
Activity
Releases
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
董敬伟
liquidnet-bus-v1
Commits
17c04adc
Commit
17c04adc
authored
Mar 16, 2022
by
胡佳晨
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/jxl_0303_upload_appraisal' into dev_performance_paytxt
parents
d1f58e82
59a3d15c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
76 additions
and
43 deletions
+76
-43
FilesUtils.java
...main/java/com/liquidnet/commons/lang/util/FilesUtils.java
+5
-8
pom.xml
...-service-platform/liquidnet-service-platform-impl/pom.xml
+5
-0
AlOssController.java
...ce/platform/controller/basicServices/AlOssController.java
+65
-34
bootstrap-test.yml
...rvice-platform-impl/src/main/resources/bootstrap-test.yml
+1
-1
No files found.
liquidnet-bus-common/liquidnet-common-base/src/main/java/com/liquidnet/commons/lang/util/FilesUtils.java
View file @
17c04adc
...
...
@@ -27,14 +27,11 @@ public class FilesUtils {
*/
public
static
File
multipartFileToFile
(
MultipartFile
file
)
{
try
{
File
toFile
=
null
;
if
(!
file
.
equals
(
""
)
&&
file
.
getSize
()
>
0
)
{
InputStream
ins
=
null
;
ins
=
file
.
getInputStream
();
toFile
=
new
File
(
file
.
getOriginalFilename
());
inputStreamToFile
(
ins
,
toFile
);
ins
.
close
();
}
InputStream
ins
=
null
;
ins
=
file
.
getInputStream
();
File
toFile
=
new
File
(
file
.
getOriginalFilename
());
inputStreamToFile
(
ins
,
toFile
);
ins
.
close
();
return
toFile
;
}
catch
(
Exception
e
)
{
log
.
error
(
"multipartFileToFileError"
,
e
);
...
...
liquidnet-bus-service/liquidnet-service-platform/liquidnet-service-platform-impl/pom.xml
View file @
17c04adc
...
...
@@ -115,6 +115,11 @@
<artifactId>
liquidnet-api-feign-stone
</artifactId>
<version>
1.0-SNAPSHOT
</version>
</dependency>
<dependency>
<groupId>
com.liquidnet
</groupId>
<artifactId>
liquidnet-common-third-shumei
</artifactId>
<version>
1.0-SNAPSHOT
</version>
</dependency>
</dependencies>
<build>
...
...
liquidnet-bus-service/liquidnet-service-platform/liquidnet-service-platform-impl/src/main/java/com/liquidnet/service/platform/controller/basicServices/AlOssController.java
View file @
17c04adc
package
com
.
liquidnet
.
service
.
platform
.
controller
.
basicServices
;
import
com.aliyun.oss.ClientException
;
import
com.aliyun.oss.OSS
;
import
com.aliyun.oss.OSSClientBuilder
;
import
com.aliyun.oss.OSSException
;
import
com.aliyun.oss.common.utils.BinaryUtil
;
import
com.aliyun.oss.model.GenericResult
;
import
com.aliyun.oss.model.ProcessObjectRequest
;
import
com.aliyun.oss.model.PutObjectRequest
;
import
com.baomidou.mybatisplus.core.toolkit.CollectionUtils
;
import
com.baomidou.mybatisplus.core.toolkit.Wrappers
;
import
com.liquidnet.common.third.shumei.util.ShumeiUtil
;
import
com.liquidnet.commons.lang.util.DateUtil
;
import
com.liquidnet.commons.lang.util.FilesUtils
;
import
com.liquidnet.commons.lang.util.IDGenerator
;
...
...
@@ -19,6 +22,7 @@ import io.swagger.annotations.Api;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiImplicitParams
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
...
...
@@ -29,6 +33,7 @@ import org.springframework.web.bind.annotation.RestController;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.File
;
import
java.io.IOException
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.time.LocalDateTime
;
...
...
@@ -45,6 +50,7 @@ import java.util.UUID;
* @since 2021-07-09
*/
@Api
(
tags
=
"basicServices"
)
@Slf4j
@RestController
@RequestMapping
(
"basicServices/alOss"
)
public
class
AlOssController
{
...
...
@@ -61,6 +67,9 @@ public class AlOssController {
@Autowired
private
PlatformOssFilesMapper
platformOssFilesMapper
;
@Autowired
private
ShumeiUtil
shumeiUtil
;
@PostMapping
(
"/upload"
)
@ApiOperation
(
"阿里云上传"
)
@ApiImplicitParams
({
...
...
@@ -77,24 +86,34 @@ public class AlOssController {
@RequestParam
(
defaultValue
=
"0"
,
required
=
false
)
int
resize
,
@RequestParam
(
defaultValue
=
"0"
,
required
=
false
)
int
isCutFrame
)
{
if
(
file
.
equals
(
""
)
||
file
.
getSize
()
<=
0
)
{
return
ResponseDto
.
failure
(
"不能上传大小为0的文件"
);
}
File
fileNew
=
FilesUtils
.
multipartFileToFile
(
file
);
if
(
null
==
fileNew
)
{
return
ResponseDto
.
failure
(
"
上传失败
"
);
return
ResponseDto
.
failure
(
"
multipartFileToFile Error
"
);
}
// 是否上传过 有直接返回
PlatformOssFiles
ossFile
=
this
.
getOldOssFile
(
fileNew
);
UploadVo
uploadVo
=
new
UploadVo
();
if
(
null
==
ossFile
)
{
// 上传
ossFile
=
this
.
uploadOssFile
(
file
,
pathName
,
buckType
,
resize
,
fileNew
,
isCutFrame
);
try
{
if
(
null
==
ossFile
||
(
isCutFrame
>
0
&&
ossFile
.
getVideoImg
().
isEmpty
()))
{
//保证上传过的文件也能截帧
// 上传
ossFile
=
this
.
uploadOssFile
(
file
,
pathName
,
buckType
,
resize
,
fileNew
,
isCutFrame
);
}
}
finally
{
// 删除临时文件 因为老文件也生成了所以也要删除
FilesUtils
.
deleteTempFile
(
fileNew
);
}
BeanUtils
.
copyProperties
(
ossFile
,
uploadVo
);
// 删除临时文件 因为老文件也生成了所以也要删除
FilesUtils
.
deleteTempFile
(
fileNew
);
return
ResponseDto
.
success
(
uploadVo
);
if
(
null
==
ossFile
)
{
return
ResponseDto
.
failure
(
"上传失败,该文件不合规,请勿上传带有联系方式、色情、涉政、广告等敏感文件"
);
}
else
{
BeanUtils
.
copyProperties
(
ossFile
,
uploadVo
);
return
ResponseDto
.
success
(
uploadVo
);
}
}
/**
...
...
@@ -108,6 +127,7 @@ public class AlOssController {
List
<
PlatformOssFiles
>
platformOssFiles
=
platformOssFilesMapper
.
selectList
(
Wrappers
.
lambdaQuery
(
PlatformOssFiles
.
class
)
.
eq
(
PlatformOssFiles:
:
getMd5str
,
fileMD5
)
.
orderByDesc
(
PlatformOssFiles:
:
getMid
)
);
if
(
CollectionUtils
.
isEmpty
(
platformOssFiles
))
{
return
null
;
...
...
@@ -128,38 +148,49 @@ public class AlOssController {
*/
private
PlatformOssFiles
uploadOssFile
(
MultipartFile
file
,
String
pathName
,
int
buckType
,
int
resize
,
File
fileNew
,
int
isCutFrame
)
{
OSS
ossClient
=
new
OSSClientBuilder
().
build
(
endpoint
,
accessKeyId
,
accessKeySecret
);
String
filename
=
""
;
String
contentType
=
""
;
int
size
=
0
;
if
(
null
==
file
)
{
filename
=
fileNew
.
getName
();
Path
fileNewPath
=
new
File
(
fileNew
.
getPath
()).
toPath
();
try
{
String
filename
,
contentType
,
uploadPath
=
""
;
PlatformOssFiles
ossFileVideoImg
=
null
;
try
{
if
(
null
==
file
)
{
filename
=
fileNew
.
getName
();
Path
fileNewPath
=
new
File
(
fileNew
.
getPath
()).
toPath
();
contentType
=
Files
.
probeContentType
(
fileNewPath
);
}
catch
(
Exception
e
)
{
size
=
(
int
)
fileNew
.
length
();
}
else
{
filename
=
file
.
getResource
().
getFilename
();
contentType
=
file
.
getContentType
();
size
=
(
int
)
file
.
getSize
();
}
uploadPath
=
FilesUtils
.
getUploadPath
(
pathName
,
filename
);
String
bucketName
=
FilesUtils
.
getBucketName
(
buckType
);
PutObjectRequest
putObjectRequest
=
new
PutObjectRequest
(
bucketName
,
uploadPath
,
fileNew
);
ossClient
.
putObject
(
putObjectRequest
);
if
(
contentType
.
contains
(
"image"
)
&&
!
contentType
.
equals
(
"image/vnd.adobe.photoshop"
))
{
if
(!
shumeiUtil
.
checkImage
(
IDGenerator
.
nextSnowId
(),
imgUrl
.
concat
(
uploadPath
)))
{
ossClient
.
deleteObject
(
bucketName
,
uploadPath
);
return
null
;
}
}
size
=
(
int
)
fileNew
.
length
();
}
else
{
filename
=
file
.
getResource
().
getFilename
();
contentType
=
file
.
getContentType
();
size
=
(
int
)
file
.
getSize
();
}
String
uploadPath
=
FilesUtils
.
getUploadPath
(
pathName
,
filename
);
String
bucketName
=
FilesUtils
.
getBucketName
(
buckType
);
PutObjectRequest
putObjectRequest
=
new
PutObjectRequest
(
bucketName
,
uploadPath
,
fileNew
);
ossClient
.
putObject
(
putObjectRequest
);
if
(
resize
>
0
)
{
// 裁切
this
.
ossFileResize
(
resize
,
uploadPath
,
bucketName
,
ossClient
);
}
if
(
resize
>
0
)
{
// 裁切
this
.
ossFileResize
(
resize
,
uploadPath
,
bucketName
,
ossClient
);
}
PlatformOssFiles
ossFileVideoImg
=
null
;
if
(
isCutFrame
>
0
)
{
// 截取帧数
ossFileVideoImg
=
this
.
ossFileCutFrame
(
uploadPath
,
pathName
,
buckType
);
}
if
(
isCutFrame
>
0
&&
contentType
.
contains
(
"video"
))
{
// 截取帧数
ossFileVideoImg
=
this
.
ossFileCutFrame
(
uploadPath
,
pathName
,
buckType
);
}
ossClient
.
shutdown
();
ossClient
.
shutdown
();
}
catch
(
OSSException
|
ClientException
|
IOException
e
)
{
log
.
error
(
"alOssUploadEx [e:{}]"
,
e
);
return
null
;
}
finally
{
if
(
ossClient
!=
null
)
{
ossClient
.
shutdown
();
}
}
// 入库
PlatformOssFiles
platformOssFilesDate
=
new
PlatformOssFiles
();
...
...
liquidnet-bus-service/liquidnet-service-platform/liquidnet-service-platform-impl/src/main/resources/bootstrap-test.yml
View file @
17c04adc
...
...
@@ -16,4 +16,4 @@ liquidnet:
spring
:
profiles
:
include
:
service-platform
include
:
service-platform
\ 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