Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
legobackend
/
lego-manage
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
6ef5a1a3
authored
2025-08-10 15:08:24 +0800
by
chentao
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
加密资源
1 parent
b397102b
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
719 additions
and
7 deletions
lego-admin/src/main/java/com/lego/web/controller/core/CourseController.java
lego-system/src/main/java/com/lego/system/service/impl/SysOssServiceImpl.java
lego-admin/src/main/java/com/lego/web/controller/core/CourseController.java
View file @
6ef5a1a
package
com
.
lego
.
web
.
controller
.
core
;
import
cn.hutool.core.bean.BeanUtil
;
import
cn.hutool.core.io.IoUtil
;
import
cn.hutool.core.util.ObjectUtil
;
import
com.lego.common.annotation.RepeatSubmit
;
import
com.lego.common.core.controller.BaseController
;
import
com.lego.common.core.domain.R
;
import
com.lego.common.core.page.TableDataInfo
;
import
com.lego.common.core.service.ConfigService
;
import
com.lego.common.exception.ServiceException
;
import
com.lego.common.utils.EncryptUtils
;
import
com.lego.common.utils.StringUtils
;
import
com.lego.common.utils.spring.SpringUtils
;
import
com.lego.core.domin.Course
;
import
com.lego.core.domin.bo.BuildingBlockBo
;
import
com.lego.core.domin.bo.BuildingBlockQueryBo
;
import
com.lego.core.domin.bo.CourseBo
;
import
com.lego.core.domin.bo.CourseQueryBo
;
import
com.lego.core.domin.vo.BuildingBlockVo
;
import
com.lego.core.domin.vo.CourseVo
;
import
com.lego.core.mapper.CourseMapper
;
import
com.lego.core.service.IBuildingBlockService
;
import
com.lego.core.service.ICourseService
;
import
com.lego.oss.core.OssClient
;
import
com.lego.oss.entity.UploadResult
;
import
com.lego.oss.factory.OssFactory
;
import
com.lego.system.domain.vo.SysOssVo
;
import
com.lego.system.service.ISysOssService
;
import
com.lego.system.service.impl.SysOssServiceImpl
;
import
lombok.RequiredArgsConstructor
;
import
org.springframework.web.bind.annotation.*
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.validation.Valid
;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.rmi.ServerException
;
import
java.util.List
;
import
java.util.Objects
;
/**
* 课程 信息操作处理
...
...
@@ -31,6 +52,8 @@ import java.util.List;
@RequestMapping
(
"/core/course"
)
public
class
CourseController
extends
BaseController
{
private
final
ICourseService
service
;
private
final
SysOssServiceImpl
sysOssService
;
private
final
CourseMapper
baseMapper
;
/**
* 查询列表数据(带分页)
...
...
@@ -66,6 +89,694 @@ public class CourseController extends BaseController {
return
R
.
ok
(
service
.
getById
(
id
));
}
@GetMapping
(
"/encrypt"
)
public
R
<
String
>
encrypt
()
{
List
<
CourseVo
>
list
=
baseMapper
.
selectVoList
(
null
);
OssClient
storage
=
OssFactory
.
instance
();
for
(
CourseVo
courseVo
:
list
)
{
String
ossIds
=
courseVo
.
getTwoDimensionalType
();
StringBuffer
newOssIds
=
new
StringBuffer
(
""
);
if
(
StringUtils
.
isNotBlank
(
ossIds
)){
String
[]
arr
=
ossIds
.
split
(
","
);
for
(
String
ossId
:
arr
)
{
SysOssVo
sysOss
=
sysOssService
.
getById
(
Long
.
valueOf
(
ossId
));
if
(
ObjectUtil
.
isNull
(
sysOss
))
{
}
else
{
String
originalfileName
=
sysOss
.
getOriginalName
();
String
suffix
=
StringUtils
.
substring
(
originalfileName
,
originalfileName
.
lastIndexOf
(
"."
),
originalfileName
.
length
());
UploadResult
uploadResult
=
null
;
if
(
".pdf"
.
equals
(
suffix
))
{
byte
[]
fileBytes
=
null
;
try
(
InputStream
inputStream
=
storage
.
getObjectContent
(
sysOss
.
getUrl
()))
{
ByteArrayOutputStream
byteArrayOutputStream
=
new
ByteArrayOutputStream
();
byte
[]
buffer
=
new
byte
[
8192
];
// 或者根据实际情况选择合适的缓冲区大小
int
bytesRead
;
while
((
bytesRead
=
inputStream
.
read
(
buffer
))
!=
-
1
)
{
byteArrayOutputStream
.
write
(
buffer
,
0
,
bytesRead
);
}
byteArrayOutputStream
.
flush
();
fileBytes
=
byteArrayOutputStream
.
toByteArray
();
}
catch
(
IOException
e
)
{
System
.
out
.
println
(
e
.
getMessage
());
}
byte
[]
encryptBytes
=
EncryptUtils
.
encryptByAes
(
fileBytes
);
uploadResult
=
storage
.
uploadSuffix
(
encryptBytes
,
suffix
,
"application/pdf"
);
}
else
if
(
".mp4"
.
equals
(
suffix
))
{
byte
[]
fileBytes
=
null
;
try
(
InputStream
inputStream
=
storage
.
getObjectContent
(
sysOss
.
getUrl
()))
{
ByteArrayOutputStream
byteArrayOutputStream
=
new
ByteArrayOutputStream
();
byte
[]
buffer
=
new
byte
[
8192
];
// 或者根据实际情况选择合适的缓冲区大小
int
bytesRead
;
while
((
bytesRead
=
inputStream
.
read
(
buffer
))
!=
-
1
)
{
byteArrayOutputStream
.
write
(
buffer
,
0
,
bytesRead
);
}
byteArrayOutputStream
.
flush
();
fileBytes
=
byteArrayOutputStream
.
toByteArray
();
}
catch
(
IOException
e
)
{
System
.
out
.
println
(
e
.
getMessage
());
}
byte
[]
encryptBytes
=
EncryptUtils
.
encryptByAes
(
fileBytes
);
uploadResult
=
storage
.
uploadSuffix
(
encryptBytes
,
suffix
,
"video/mpeg4"
);
}
else
if
(
".json"
.
equals
(
suffix
))
{
byte
[]
fileBytes
=
null
;
try
(
InputStream
inputStream
=
storage
.
getObjectContent
(
sysOss
.
getUrl
()))
{
ByteArrayOutputStream
byteArrayOutputStream
=
new
ByteArrayOutputStream
();
byte
[]
buffer
=
new
byte
[
8192
];
// 或者根据实际情况选择合适的缓冲区大小
int
bytesRead
;
while
((
bytesRead
=
inputStream
.
read
(
buffer
))
!=
-
1
)
{
byteArrayOutputStream
.
write
(
buffer
,
0
,
bytesRead
);
}
byteArrayOutputStream
.
flush
();
fileBytes
=
byteArrayOutputStream
.
toByteArray
();
}
catch
(
IOException
e
)
{
System
.
out
.
println
(
e
.
getMessage
());
}
byte
[]
encryptBytes
=
EncryptUtils
.
encryptByAes
(
fileBytes
);
uploadResult
=
storage
.
uploadSuffix
(
encryptBytes
,
suffix
,
"text/plain"
);
}
else
if
(
".ldr"
.
equals
(
suffix
))
{
byte
[]
fileBytes
=
null
;
try
(
InputStream
inputStream
=
storage
.
getObjectContent
(
sysOss
.
getUrl
()))
{
ByteArrayOutputStream
byteArrayOutputStream
=
new
ByteArrayOutputStream
();
byte
[]
buffer
=
new
byte
[
8192
];
// 或者根据实际情况选择合适的缓冲区大小
int
bytesRead
;
while
((
bytesRead
=
inputStream
.
read
(
buffer
))
!=
-
1
)
{
byteArrayOutputStream
.
write
(
buffer
,
0
,
bytesRead
);
}
byteArrayOutputStream
.
flush
();
fileBytes
=
byteArrayOutputStream
.
toByteArray
();
}
catch
(
IOException
e
)
{
System
.
out
.
println
(
e
.
getMessage
());
}
byte
[]
encryptBytes
=
EncryptUtils
.
encryptByAes
(
fileBytes
);
uploadResult
=
storage
.
uploadSuffix
(
encryptBytes
,
suffix
,
"text/plain"
);
}
if
(
Objects
.
nonNull
(
uploadResult
))
{
// 保存文件信息
SysOssVo
vo
=
sysOssService
.
buildResultEntity
(
originalfileName
,
suffix
,
storage
.
getConfigKey
(),
uploadResult
);
newOssIds
.
append
(
vo
.
getOssId
()).
append
(
","
);
}
}
}
if
(
newOssIds
.
toString
().
lastIndexOf
(
","
)
!=
-
1
){
newOssIds
.
deleteCharAt
(
newOssIds
.
length
()-
1
);
}
if
(
StringUtils
.
isNotBlank
(
newOssIds
.
toString
()))
{
courseVo
.
setTwoDimensionalType
(
newOssIds
.
toString
());
CourseBo
courseBo
=
BeanUtil
.
toBean
(
courseVo
,
CourseBo
.
class
);
try
{
service
.
updateCourse
(
courseBo
);
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
e
.
getMessage
());
}
}
}
ossIds
=
courseVo
.
getTwoDimensionalUrl
();
newOssIds
=
new
StringBuffer
(
""
);
if
(
StringUtils
.
isNotBlank
(
ossIds
)){
String
[]
arr
=
ossIds
.
split
(
","
);
for
(
String
ossId
:
arr
)
{
SysOssVo
sysOss
=
sysOssService
.
getById
(
Long
.
valueOf
(
ossId
));
if
(
ObjectUtil
.
isNull
(
sysOss
))
{
}
else
{
String
originalfileName
=
sysOss
.
getOriginalName
();
String
suffix
=
StringUtils
.
substring
(
originalfileName
,
originalfileName
.
lastIndexOf
(
"."
),
originalfileName
.
length
());
UploadResult
uploadResult
=
null
;
if
(
".pdf"
.
equals
(
suffix
))
{
byte
[]
fileBytes
=
null
;
try
(
InputStream
inputStream
=
storage
.
getObjectContent
(
sysOss
.
getUrl
()))
{
ByteArrayOutputStream
byteArrayOutputStream
=
new
ByteArrayOutputStream
();
byte
[]
buffer
=
new
byte
[
8192
];
// 或者根据实际情况选择合适的缓冲区大小
int
bytesRead
;
while
((
bytesRead
=
inputStream
.
read
(
buffer
))
!=
-
1
)
{
byteArrayOutputStream
.
write
(
buffer
,
0
,
bytesRead
);
}
byteArrayOutputStream
.
flush
();
fileBytes
=
byteArrayOutputStream
.
toByteArray
();
}
catch
(
IOException
e
)
{
System
.
out
.
println
(
e
.
getMessage
());
}
byte
[]
encryptBytes
=
EncryptUtils
.
encryptByAes
(
fileBytes
);
uploadResult
=
storage
.
uploadSuffix
(
encryptBytes
,
suffix
,
"application/pdf"
);
}
else
if
(
".mp4"
.
equals
(
suffix
))
{
byte
[]
fileBytes
=
null
;
try
(
InputStream
inputStream
=
storage
.
getObjectContent
(
sysOss
.
getUrl
()))
{
ByteArrayOutputStream
byteArrayOutputStream
=
new
ByteArrayOutputStream
();
byte
[]
buffer
=
new
byte
[
8192
];
// 或者根据实际情况选择合适的缓冲区大小
int
bytesRead
;
while
((
bytesRead
=
inputStream
.
read
(
buffer
))
!=
-
1
)
{
byteArrayOutputStream
.
write
(
buffer
,
0
,
bytesRead
);
}
byteArrayOutputStream
.
flush
();
fileBytes
=
byteArrayOutputStream
.
toByteArray
();
}
catch
(
IOException
e
)
{
System
.
out
.
println
(
e
.
getMessage
());
}
byte
[]
encryptBytes
=
EncryptUtils
.
encryptByAes
(
fileBytes
);
uploadResult
=
storage
.
uploadSuffix
(
encryptBytes
,
suffix
,
"video/mpeg4"
);
}
else
if
(
".json"
.
equals
(
suffix
))
{
byte
[]
fileBytes
=
null
;
try
(
InputStream
inputStream
=
storage
.
getObjectContent
(
sysOss
.
getUrl
()))
{
ByteArrayOutputStream
byteArrayOutputStream
=
new
ByteArrayOutputStream
();
byte
[]
buffer
=
new
byte
[
8192
];
// 或者根据实际情况选择合适的缓冲区大小
int
bytesRead
;
while
((
bytesRead
=
inputStream
.
read
(
buffer
))
!=
-
1
)
{
byteArrayOutputStream
.
write
(
buffer
,
0
,
bytesRead
);
}
byteArrayOutputStream
.
flush
();
fileBytes
=
byteArrayOutputStream
.
toByteArray
();
}
catch
(
IOException
e
)
{
System
.
out
.
println
(
e
.
getMessage
());
}
byte
[]
encryptBytes
=
EncryptUtils
.
encryptByAes
(
fileBytes
);
uploadResult
=
storage
.
uploadSuffix
(
encryptBytes
,
suffix
,
"text/plain"
);
}
else
if
(
".ldr"
.
equals
(
suffix
))
{
byte
[]
fileBytes
=
null
;
try
(
InputStream
inputStream
=
storage
.
getObjectContent
(
sysOss
.
getUrl
()))
{
ByteArrayOutputStream
byteArrayOutputStream
=
new
ByteArrayOutputStream
();
byte
[]
buffer
=
new
byte
[
8192
];
// 或者根据实际情况选择合适的缓冲区大小
int
bytesRead
;
while
((
bytesRead
=
inputStream
.
read
(
buffer
))
!=
-
1
)
{
byteArrayOutputStream
.
write
(
buffer
,
0
,
bytesRead
);
}
byteArrayOutputStream
.
flush
();
fileBytes
=
byteArrayOutputStream
.
toByteArray
();
}
catch
(
IOException
e
)
{
System
.
out
.
println
(
e
.
getMessage
());
}
byte
[]
encryptBytes
=
EncryptUtils
.
encryptByAes
(
fileBytes
);
uploadResult
=
storage
.
uploadSuffix
(
encryptBytes
,
suffix
,
"text/plain"
);
}
if
(
Objects
.
nonNull
(
uploadResult
))
{
// 保存文件信息
SysOssVo
vo
=
sysOssService
.
buildResultEntity
(
originalfileName
,
suffix
,
storage
.
getConfigKey
(),
uploadResult
);
newOssIds
.
append
(
vo
.
getOssId
()).
append
(
","
);
}
}
}
if
(
newOssIds
.
toString
().
lastIndexOf
(
","
)
!=
-
1
){
newOssIds
.
deleteCharAt
(
newOssIds
.
length
()-
1
);
}
if
(
StringUtils
.
isNotBlank
(
newOssIds
.
toString
()))
{
courseVo
.
setTwoDimensionalUrl
(
newOssIds
.
toString
());
CourseBo
courseBo
=
BeanUtil
.
toBean
(
courseVo
,
CourseBo
.
class
);
try
{
service
.
updateCourse
(
courseBo
);
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
e
.
getMessage
());
}
}
}
ossIds
=
courseVo
.
getThreeDimensionalType
();
newOssIds
=
new
StringBuffer
(
""
);
if
(
StringUtils
.
isNotBlank
(
ossIds
)){
String
[]
arr
=
ossIds
.
split
(
","
);
for
(
String
ossId
:
arr
)
{
SysOssVo
sysOss
=
sysOssService
.
getById
(
Long
.
valueOf
(
ossId
));
if
(
ObjectUtil
.
isNull
(
sysOss
))
{
}
else
{
String
originalfileName
=
sysOss
.
getOriginalName
();
String
suffix
=
StringUtils
.
substring
(
originalfileName
,
originalfileName
.
lastIndexOf
(
"."
),
originalfileName
.
length
());
UploadResult
uploadResult
=
null
;
if
(
".pdf"
.
equals
(
suffix
))
{
byte
[]
fileBytes
=
null
;
try
(
InputStream
inputStream
=
storage
.
getObjectContent
(
sysOss
.
getUrl
()))
{
ByteArrayOutputStream
byteArrayOutputStream
=
new
ByteArrayOutputStream
();
byte
[]
buffer
=
new
byte
[
8192
];
// 或者根据实际情况选择合适的缓冲区大小
int
bytesRead
;
while
((
bytesRead
=
inputStream
.
read
(
buffer
))
!=
-
1
)
{
byteArrayOutputStream
.
write
(
buffer
,
0
,
bytesRead
);
}
byteArrayOutputStream
.
flush
();
fileBytes
=
byteArrayOutputStream
.
toByteArray
();
}
catch
(
IOException
e
)
{
System
.
out
.
println
(
e
.
getMessage
());
}
byte
[]
encryptBytes
=
EncryptUtils
.
encryptByAes
(
fileBytes
);
uploadResult
=
storage
.
uploadSuffix
(
encryptBytes
,
suffix
,
"application/pdf"
);
}
else
if
(
".mp4"
.
equals
(
suffix
))
{
byte
[]
fileBytes
=
null
;
try
(
InputStream
inputStream
=
storage
.
getObjectContent
(
sysOss
.
getUrl
()))
{
ByteArrayOutputStream
byteArrayOutputStream
=
new
ByteArrayOutputStream
();
byte
[]
buffer
=
new
byte
[
8192
];
// 或者根据实际情况选择合适的缓冲区大小
int
bytesRead
;
while
((
bytesRead
=
inputStream
.
read
(
buffer
))
!=
-
1
)
{
byteArrayOutputStream
.
write
(
buffer
,
0
,
bytesRead
);
}
byteArrayOutputStream
.
flush
();
fileBytes
=
byteArrayOutputStream
.
toByteArray
();
}
catch
(
IOException
e
)
{
System
.
out
.
println
(
e
.
getMessage
());
}
byte
[]
encryptBytes
=
EncryptUtils
.
encryptByAes
(
fileBytes
);
uploadResult
=
storage
.
uploadSuffix
(
encryptBytes
,
suffix
,
"video/mpeg4"
);
}
else
if
(
".json"
.
equals
(
suffix
))
{
byte
[]
fileBytes
=
null
;
try
(
InputStream
inputStream
=
storage
.
getObjectContent
(
sysOss
.
getUrl
()))
{
ByteArrayOutputStream
byteArrayOutputStream
=
new
ByteArrayOutputStream
();
byte
[]
buffer
=
new
byte
[
8192
];
// 或者根据实际情况选择合适的缓冲区大小
int
bytesRead
;
while
((
bytesRead
=
inputStream
.
read
(
buffer
))
!=
-
1
)
{
byteArrayOutputStream
.
write
(
buffer
,
0
,
bytesRead
);
}
byteArrayOutputStream
.
flush
();
fileBytes
=
byteArrayOutputStream
.
toByteArray
();
}
catch
(
IOException
e
)
{
System
.
out
.
println
(
e
.
getMessage
());
}
byte
[]
encryptBytes
=
EncryptUtils
.
encryptByAes
(
fileBytes
);
uploadResult
=
storage
.
uploadSuffix
(
encryptBytes
,
suffix
,
"text/plain"
);
}
else
if
(
".ldr"
.
equals
(
suffix
))
{
byte
[]
fileBytes
=
null
;
try
(
InputStream
inputStream
=
storage
.
getObjectContent
(
sysOss
.
getUrl
()))
{
ByteArrayOutputStream
byteArrayOutputStream
=
new
ByteArrayOutputStream
();
byte
[]
buffer
=
new
byte
[
8192
];
// 或者根据实际情况选择合适的缓冲区大小
int
bytesRead
;
while
((
bytesRead
=
inputStream
.
read
(
buffer
))
!=
-
1
)
{
byteArrayOutputStream
.
write
(
buffer
,
0
,
bytesRead
);
}
byteArrayOutputStream
.
flush
();
fileBytes
=
byteArrayOutputStream
.
toByteArray
();
}
catch
(
IOException
e
)
{
System
.
out
.
println
(
e
.
getMessage
());
}
byte
[]
encryptBytes
=
EncryptUtils
.
encryptByAes
(
fileBytes
);
uploadResult
=
storage
.
uploadSuffix
(
encryptBytes
,
suffix
,
"text/plain"
);
}
if
(
Objects
.
nonNull
(
uploadResult
))
{
// 保存文件信息
SysOssVo
vo
=
sysOssService
.
buildResultEntity
(
originalfileName
,
suffix
,
storage
.
getConfigKey
(),
uploadResult
);
newOssIds
.
append
(
vo
.
getOssId
()).
append
(
","
);
}
}
}
if
(
newOssIds
.
toString
().
lastIndexOf
(
","
)
!=
-
1
){
newOssIds
.
deleteCharAt
(
newOssIds
.
length
()-
1
);
}
if
(
StringUtils
.
isNotBlank
(
newOssIds
.
toString
()))
{
courseVo
.
setThreeDimensionalType
(
newOssIds
.
toString
());
CourseBo
courseBo
=
BeanUtil
.
toBean
(
courseVo
,
CourseBo
.
class
);
try
{
service
.
updateCourse
(
courseBo
);
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
e
.
getMessage
());
}
}
}
ossIds
=
courseVo
.
getThreeDimensionalUrl
();
newOssIds
=
new
StringBuffer
(
""
);
if
(
StringUtils
.
isNotBlank
(
ossIds
)){
String
[]
arr
=
ossIds
.
split
(
","
);
for
(
String
ossId
:
arr
)
{
SysOssVo
sysOss
=
sysOssService
.
getById
(
Long
.
valueOf
(
ossId
));
if
(
ObjectUtil
.
isNull
(
sysOss
))
{
}
else
{
String
originalfileName
=
sysOss
.
getOriginalName
();
String
suffix
=
StringUtils
.
substring
(
originalfileName
,
originalfileName
.
lastIndexOf
(
"."
),
originalfileName
.
length
());
UploadResult
uploadResult
=
null
;
if
(
".pdf"
.
equals
(
suffix
))
{
byte
[]
fileBytes
=
null
;
try
(
InputStream
inputStream
=
storage
.
getObjectContent
(
sysOss
.
getUrl
()))
{
ByteArrayOutputStream
byteArrayOutputStream
=
new
ByteArrayOutputStream
();
byte
[]
buffer
=
new
byte
[
8192
];
// 或者根据实际情况选择合适的缓冲区大小
int
bytesRead
;
while
((
bytesRead
=
inputStream
.
read
(
buffer
))
!=
-
1
)
{
byteArrayOutputStream
.
write
(
buffer
,
0
,
bytesRead
);
}
byteArrayOutputStream
.
flush
();
fileBytes
=
byteArrayOutputStream
.
toByteArray
();
}
catch
(
IOException
e
)
{
System
.
out
.
println
(
e
.
getMessage
());
}
byte
[]
encryptBytes
=
EncryptUtils
.
encryptByAes
(
fileBytes
);
uploadResult
=
storage
.
uploadSuffix
(
encryptBytes
,
suffix
,
"application/pdf"
);
}
else
if
(
".mp4"
.
equals
(
suffix
))
{
byte
[]
fileBytes
=
null
;
try
(
InputStream
inputStream
=
storage
.
getObjectContent
(
sysOss
.
getUrl
()))
{
ByteArrayOutputStream
byteArrayOutputStream
=
new
ByteArrayOutputStream
();
byte
[]
buffer
=
new
byte
[
8192
];
// 或者根据实际情况选择合适的缓冲区大小
int
bytesRead
;
while
((
bytesRead
=
inputStream
.
read
(
buffer
))
!=
-
1
)
{
byteArrayOutputStream
.
write
(
buffer
,
0
,
bytesRead
);
}
byteArrayOutputStream
.
flush
();
fileBytes
=
byteArrayOutputStream
.
toByteArray
();
}
catch
(
IOException
e
)
{
System
.
out
.
println
(
e
.
getMessage
());
}
byte
[]
encryptBytes
=
EncryptUtils
.
encryptByAes
(
fileBytes
);
uploadResult
=
storage
.
uploadSuffix
(
encryptBytes
,
suffix
,
"video/mpeg4"
);
}
else
if
(
".json"
.
equals
(
suffix
))
{
byte
[]
fileBytes
=
null
;
try
(
InputStream
inputStream
=
storage
.
getObjectContent
(
sysOss
.
getUrl
()))
{
ByteArrayOutputStream
byteArrayOutputStream
=
new
ByteArrayOutputStream
();
byte
[]
buffer
=
new
byte
[
8192
];
// 或者根据实际情况选择合适的缓冲区大小
int
bytesRead
;
while
((
bytesRead
=
inputStream
.
read
(
buffer
))
!=
-
1
)
{
byteArrayOutputStream
.
write
(
buffer
,
0
,
bytesRead
);
}
byteArrayOutputStream
.
flush
();
fileBytes
=
byteArrayOutputStream
.
toByteArray
();
}
catch
(
IOException
e
)
{
System
.
out
.
println
(
e
.
getMessage
());
}
byte
[]
encryptBytes
=
EncryptUtils
.
encryptByAes
(
fileBytes
);
uploadResult
=
storage
.
uploadSuffix
(
encryptBytes
,
suffix
,
"text/plain"
);
}
else
if
(
".ldr"
.
equals
(
suffix
))
{
byte
[]
fileBytes
=
null
;
try
(
InputStream
inputStream
=
storage
.
getObjectContent
(
sysOss
.
getUrl
()))
{
ByteArrayOutputStream
byteArrayOutputStream
=
new
ByteArrayOutputStream
();
byte
[]
buffer
=
new
byte
[
8192
];
// 或者根据实际情况选择合适的缓冲区大小
int
bytesRead
;
while
((
bytesRead
=
inputStream
.
read
(
buffer
))
!=
-
1
)
{
byteArrayOutputStream
.
write
(
buffer
,
0
,
bytesRead
);
}
byteArrayOutputStream
.
flush
();
fileBytes
=
byteArrayOutputStream
.
toByteArray
();
}
catch
(
IOException
e
)
{
System
.
out
.
println
(
e
.
getMessage
());
}
byte
[]
encryptBytes
=
EncryptUtils
.
encryptByAes
(
fileBytes
);
uploadResult
=
storage
.
uploadSuffix
(
encryptBytes
,
suffix
,
"text/plain"
);
}
if
(
Objects
.
nonNull
(
uploadResult
))
{
// 保存文件信息
SysOssVo
vo
=
sysOssService
.
buildResultEntity
(
originalfileName
,
suffix
,
storage
.
getConfigKey
(),
uploadResult
);
newOssIds
.
append
(
vo
.
getOssId
()).
append
(
","
);
}
}
}
if
(
newOssIds
.
toString
().
lastIndexOf
(
","
)
!=
-
1
){
newOssIds
.
deleteCharAt
(
newOssIds
.
length
()-
1
);
}
if
(
StringUtils
.
isNotBlank
(
newOssIds
.
toString
()))
{
courseVo
.
setThreeDimensionalUrl
(
newOssIds
.
toString
());
CourseBo
courseBo
=
BeanUtil
.
toBean
(
courseVo
,
CourseBo
.
class
);
try
{
service
.
updateCourse
(
courseBo
);
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
e
.
getMessage
());
}
}
}
ossIds
=
courseVo
.
getCaseOssId
();
newOssIds
=
new
StringBuffer
(
""
);
if
(
StringUtils
.
isNotBlank
(
ossIds
)){
String
[]
arr
=
ossIds
.
split
(
","
);
for
(
String
ossId
:
arr
)
{
SysOssVo
sysOss
=
sysOssService
.
getById
(
Long
.
valueOf
(
ossId
));
if
(
ObjectUtil
.
isNull
(
sysOss
))
{
}
else
{
String
originalfileName
=
sysOss
.
getOriginalName
();
String
suffix
=
StringUtils
.
substring
(
originalfileName
,
originalfileName
.
lastIndexOf
(
"."
),
originalfileName
.
length
());
UploadResult
uploadResult
=
null
;
if
(
".pdf"
.
equals
(
suffix
))
{
byte
[]
fileBytes
=
null
;
try
(
InputStream
inputStream
=
storage
.
getObjectContent
(
sysOss
.
getUrl
()))
{
ByteArrayOutputStream
byteArrayOutputStream
=
new
ByteArrayOutputStream
();
byte
[]
buffer
=
new
byte
[
8192
];
// 或者根据实际情况选择合适的缓冲区大小
int
bytesRead
;
while
((
bytesRead
=
inputStream
.
read
(
buffer
))
!=
-
1
)
{
byteArrayOutputStream
.
write
(
buffer
,
0
,
bytesRead
);
}
byteArrayOutputStream
.
flush
();
fileBytes
=
byteArrayOutputStream
.
toByteArray
();
}
catch
(
IOException
e
)
{
System
.
out
.
println
(
e
.
getMessage
());
}
byte
[]
encryptBytes
=
EncryptUtils
.
encryptByAes
(
fileBytes
);
uploadResult
=
storage
.
uploadSuffix
(
encryptBytes
,
suffix
,
"application/pdf"
);
}
else
if
(
".mp4"
.
equals
(
suffix
))
{
byte
[]
fileBytes
=
null
;
try
(
InputStream
inputStream
=
storage
.
getObjectContent
(
sysOss
.
getUrl
()))
{
ByteArrayOutputStream
byteArrayOutputStream
=
new
ByteArrayOutputStream
();
byte
[]
buffer
=
new
byte
[
8192
];
// 或者根据实际情况选择合适的缓冲区大小
int
bytesRead
;
while
((
bytesRead
=
inputStream
.
read
(
buffer
))
!=
-
1
)
{
byteArrayOutputStream
.
write
(
buffer
,
0
,
bytesRead
);
}
byteArrayOutputStream
.
flush
();
fileBytes
=
byteArrayOutputStream
.
toByteArray
();
}
catch
(
IOException
e
)
{
System
.
out
.
println
(
e
.
getMessage
());
}
byte
[]
encryptBytes
=
EncryptUtils
.
encryptByAes
(
fileBytes
);
uploadResult
=
storage
.
uploadSuffix
(
encryptBytes
,
suffix
,
"video/mpeg4"
);
}
else
if
(
".json"
.
equals
(
suffix
))
{
byte
[]
fileBytes
=
null
;
try
(
InputStream
inputStream
=
storage
.
getObjectContent
(
sysOss
.
getUrl
()))
{
ByteArrayOutputStream
byteArrayOutputStream
=
new
ByteArrayOutputStream
();
byte
[]
buffer
=
new
byte
[
8192
];
// 或者根据实际情况选择合适的缓冲区大小
int
bytesRead
;
while
((
bytesRead
=
inputStream
.
read
(
buffer
))
!=
-
1
)
{
byteArrayOutputStream
.
write
(
buffer
,
0
,
bytesRead
);
}
byteArrayOutputStream
.
flush
();
fileBytes
=
byteArrayOutputStream
.
toByteArray
();
}
catch
(
IOException
e
)
{
System
.
out
.
println
(
e
.
getMessage
());
}
byte
[]
encryptBytes
=
EncryptUtils
.
encryptByAes
(
fileBytes
);
uploadResult
=
storage
.
uploadSuffix
(
encryptBytes
,
suffix
,
"text/plain"
);
}
else
if
(
".ldr"
.
equals
(
suffix
))
{
byte
[]
fileBytes
=
null
;
try
(
InputStream
inputStream
=
storage
.
getObjectContent
(
sysOss
.
getUrl
()))
{
ByteArrayOutputStream
byteArrayOutputStream
=
new
ByteArrayOutputStream
();
byte
[]
buffer
=
new
byte
[
8192
];
// 或者根据实际情况选择合适的缓冲区大小
int
bytesRead
;
while
((
bytesRead
=
inputStream
.
read
(
buffer
))
!=
-
1
)
{
byteArrayOutputStream
.
write
(
buffer
,
0
,
bytesRead
);
}
byteArrayOutputStream
.
flush
();
fileBytes
=
byteArrayOutputStream
.
toByteArray
();
}
catch
(
IOException
e
)
{
System
.
out
.
println
(
e
.
getMessage
());
}
byte
[]
encryptBytes
=
EncryptUtils
.
encryptByAes
(
fileBytes
);
uploadResult
=
storage
.
uploadSuffix
(
encryptBytes
,
suffix
,
"text/plain"
);
}
if
(
Objects
.
nonNull
(
uploadResult
))
{
// 保存文件信息
SysOssVo
vo
=
sysOssService
.
buildResultEntity
(
originalfileName
,
suffix
,
storage
.
getConfigKey
(),
uploadResult
);
newOssIds
.
append
(
vo
.
getOssId
()).
append
(
","
);
}
}
}
if
(
newOssIds
.
toString
().
lastIndexOf
(
","
)
!=
-
1
){
newOssIds
.
deleteCharAt
(
newOssIds
.
length
()-
1
);
}
if
(
StringUtils
.
isNotBlank
(
newOssIds
.
toString
()))
{
courseVo
.
setCaseOssId
(
newOssIds
.
toString
());
CourseBo
courseBo
=
BeanUtil
.
toBean
(
courseVo
,
CourseBo
.
class
);
try
{
service
.
updateCourse
(
courseBo
);
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
e
.
getMessage
());
}
}
}
ossIds
=
courseVo
.
getTeachingOssId
();
newOssIds
=
new
StringBuffer
(
""
);
if
(
StringUtils
.
isNotBlank
(
ossIds
)){
String
[]
arr
=
ossIds
.
split
(
","
);
for
(
String
ossId
:
arr
)
{
SysOssVo
sysOss
=
sysOssService
.
getById
(
Long
.
valueOf
(
ossId
));
if
(
ObjectUtil
.
isNull
(
sysOss
))
{
}
else
{
String
originalfileName
=
sysOss
.
getOriginalName
();
String
suffix
=
StringUtils
.
substring
(
originalfileName
,
originalfileName
.
lastIndexOf
(
"."
),
originalfileName
.
length
());
UploadResult
uploadResult
=
null
;
if
(
".pdf"
.
equals
(
suffix
))
{
byte
[]
fileBytes
=
null
;
try
(
InputStream
inputStream
=
storage
.
getObjectContent
(
sysOss
.
getUrl
()))
{
ByteArrayOutputStream
byteArrayOutputStream
=
new
ByteArrayOutputStream
();
byte
[]
buffer
=
new
byte
[
8192
];
// 或者根据实际情况选择合适的缓冲区大小
int
bytesRead
;
while
((
bytesRead
=
inputStream
.
read
(
buffer
))
!=
-
1
)
{
byteArrayOutputStream
.
write
(
buffer
,
0
,
bytesRead
);
}
byteArrayOutputStream
.
flush
();
fileBytes
=
byteArrayOutputStream
.
toByteArray
();
}
catch
(
IOException
e
)
{
System
.
out
.
println
(
e
.
getMessage
());
}
byte
[]
encryptBytes
=
EncryptUtils
.
encryptByAes
(
fileBytes
);
uploadResult
=
storage
.
uploadSuffix
(
encryptBytes
,
suffix
,
"application/pdf"
);
}
else
if
(
".mp4"
.
equals
(
suffix
))
{
byte
[]
fileBytes
=
null
;
try
(
InputStream
inputStream
=
storage
.
getObjectContent
(
sysOss
.
getUrl
()))
{
ByteArrayOutputStream
byteArrayOutputStream
=
new
ByteArrayOutputStream
();
byte
[]
buffer
=
new
byte
[
8192
];
// 或者根据实际情况选择合适的缓冲区大小
int
bytesRead
;
while
((
bytesRead
=
inputStream
.
read
(
buffer
))
!=
-
1
)
{
byteArrayOutputStream
.
write
(
buffer
,
0
,
bytesRead
);
}
byteArrayOutputStream
.
flush
();
fileBytes
=
byteArrayOutputStream
.
toByteArray
();
}
catch
(
IOException
e
)
{
System
.
out
.
println
(
e
.
getMessage
());
}
byte
[]
encryptBytes
=
EncryptUtils
.
encryptByAes
(
fileBytes
);
uploadResult
=
storage
.
uploadSuffix
(
encryptBytes
,
suffix
,
"video/mpeg4"
);
}
else
if
(
".json"
.
equals
(
suffix
))
{
byte
[]
fileBytes
=
null
;
try
(
InputStream
inputStream
=
storage
.
getObjectContent
(
sysOss
.
getUrl
()))
{
ByteArrayOutputStream
byteArrayOutputStream
=
new
ByteArrayOutputStream
();
byte
[]
buffer
=
new
byte
[
8192
];
// 或者根据实际情况选择合适的缓冲区大小
int
bytesRead
;
while
((
bytesRead
=
inputStream
.
read
(
buffer
))
!=
-
1
)
{
byteArrayOutputStream
.
write
(
buffer
,
0
,
bytesRead
);
}
byteArrayOutputStream
.
flush
();
fileBytes
=
byteArrayOutputStream
.
toByteArray
();
}
catch
(
IOException
e
)
{
System
.
out
.
println
(
e
.
getMessage
());
}
byte
[]
encryptBytes
=
EncryptUtils
.
encryptByAes
(
fileBytes
);
uploadResult
=
storage
.
uploadSuffix
(
encryptBytes
,
suffix
,
"text/plain"
);
}
else
if
(
".ldr"
.
equals
(
suffix
))
{
byte
[]
fileBytes
=
null
;
try
(
InputStream
inputStream
=
storage
.
getObjectContent
(
sysOss
.
getUrl
()))
{
ByteArrayOutputStream
byteArrayOutputStream
=
new
ByteArrayOutputStream
();
byte
[]
buffer
=
new
byte
[
8192
];
// 或者根据实际情况选择合适的缓冲区大小
int
bytesRead
;
while
((
bytesRead
=
inputStream
.
read
(
buffer
))
!=
-
1
)
{
byteArrayOutputStream
.
write
(
buffer
,
0
,
bytesRead
);
}
byteArrayOutputStream
.
flush
();
fileBytes
=
byteArrayOutputStream
.
toByteArray
();
}
catch
(
IOException
e
)
{
System
.
out
.
println
(
e
.
getMessage
());
}
byte
[]
encryptBytes
=
EncryptUtils
.
encryptByAes
(
fileBytes
);
uploadResult
=
storage
.
uploadSuffix
(
encryptBytes
,
suffix
,
"text/plain"
);
}
if
(
Objects
.
nonNull
(
uploadResult
))
{
// 保存文件信息
SysOssVo
vo
=
sysOssService
.
buildResultEntity
(
originalfileName
,
suffix
,
storage
.
getConfigKey
(),
uploadResult
);
newOssIds
.
append
(
vo
.
getOssId
()).
append
(
","
);
}
}
}
if
(
newOssIds
.
toString
().
lastIndexOf
(
","
)
!=
-
1
){
newOssIds
.
deleteCharAt
(
newOssIds
.
length
()-
1
);
}
if
(
StringUtils
.
isNotBlank
(
newOssIds
.
toString
()))
{
courseVo
.
setTeachingOssId
(
newOssIds
.
toString
());
CourseBo
courseBo
=
BeanUtil
.
toBean
(
courseVo
,
CourseBo
.
class
);
try
{
service
.
updateCourse
(
courseBo
);
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
e
.
getMessage
());
}
}
}
ossIds
=
courseVo
.
getPptOssId
();
newOssIds
=
new
StringBuffer
(
""
);
if
(
StringUtils
.
isNotBlank
(
ossIds
)){
String
[]
arr
=
ossIds
.
split
(
","
);
for
(
String
ossId
:
arr
)
{
SysOssVo
sysOss
=
sysOssService
.
getById
(
Long
.
valueOf
(
ossId
));
if
(
ObjectUtil
.
isNull
(
sysOss
))
{
}
else
{
String
originalfileName
=
sysOss
.
getOriginalName
();
String
suffix
=
StringUtils
.
substring
(
originalfileName
,
originalfileName
.
lastIndexOf
(
"."
),
originalfileName
.
length
());
UploadResult
uploadResult
=
null
;
if
(
".pdf"
.
equals
(
suffix
))
{
byte
[]
fileBytes
=
null
;
try
(
InputStream
inputStream
=
storage
.
getObjectContent
(
sysOss
.
getUrl
()))
{
ByteArrayOutputStream
byteArrayOutputStream
=
new
ByteArrayOutputStream
();
byte
[]
buffer
=
new
byte
[
8192
];
// 或者根据实际情况选择合适的缓冲区大小
int
bytesRead
;
while
((
bytesRead
=
inputStream
.
read
(
buffer
))
!=
-
1
)
{
byteArrayOutputStream
.
write
(
buffer
,
0
,
bytesRead
);
}
byteArrayOutputStream
.
flush
();
fileBytes
=
byteArrayOutputStream
.
toByteArray
();
}
catch
(
IOException
e
)
{
System
.
out
.
println
(
e
.
getMessage
());
}
byte
[]
encryptBytes
=
EncryptUtils
.
encryptByAes
(
fileBytes
);
uploadResult
=
storage
.
uploadSuffix
(
encryptBytes
,
suffix
,
"application/pdf"
);
}
else
if
(
".mp4"
.
equals
(
suffix
))
{
byte
[]
fileBytes
=
null
;
try
(
InputStream
inputStream
=
storage
.
getObjectContent
(
sysOss
.
getUrl
()))
{
ByteArrayOutputStream
byteArrayOutputStream
=
new
ByteArrayOutputStream
();
byte
[]
buffer
=
new
byte
[
8192
];
// 或者根据实际情况选择合适的缓冲区大小
int
bytesRead
;
while
((
bytesRead
=
inputStream
.
read
(
buffer
))
!=
-
1
)
{
byteArrayOutputStream
.
write
(
buffer
,
0
,
bytesRead
);
}
byteArrayOutputStream
.
flush
();
fileBytes
=
byteArrayOutputStream
.
toByteArray
();
}
catch
(
IOException
e
)
{
System
.
out
.
println
(
e
.
getMessage
());
}
byte
[]
encryptBytes
=
EncryptUtils
.
encryptByAes
(
fileBytes
);
uploadResult
=
storage
.
uploadSuffix
(
encryptBytes
,
suffix
,
"video/mpeg4"
);
}
else
if
(
".json"
.
equals
(
suffix
))
{
byte
[]
fileBytes
=
null
;
try
(
InputStream
inputStream
=
storage
.
getObjectContent
(
sysOss
.
getUrl
()))
{
ByteArrayOutputStream
byteArrayOutputStream
=
new
ByteArrayOutputStream
();
byte
[]
buffer
=
new
byte
[
8192
];
// 或者根据实际情况选择合适的缓冲区大小
int
bytesRead
;
while
((
bytesRead
=
inputStream
.
read
(
buffer
))
!=
-
1
)
{
byteArrayOutputStream
.
write
(
buffer
,
0
,
bytesRead
);
}
byteArrayOutputStream
.
flush
();
fileBytes
=
byteArrayOutputStream
.
toByteArray
();
}
catch
(
IOException
e
)
{
System
.
out
.
println
(
e
.
getMessage
());
}
byte
[]
encryptBytes
=
EncryptUtils
.
encryptByAes
(
fileBytes
);
uploadResult
=
storage
.
uploadSuffix
(
encryptBytes
,
suffix
,
"text/plain"
);
}
else
if
(
".ldr"
.
equals
(
suffix
))
{
byte
[]
fileBytes
=
null
;
try
(
InputStream
inputStream
=
storage
.
getObjectContent
(
sysOss
.
getUrl
()))
{
ByteArrayOutputStream
byteArrayOutputStream
=
new
ByteArrayOutputStream
();
byte
[]
buffer
=
new
byte
[
8192
];
// 或者根据实际情况选择合适的缓冲区大小
int
bytesRead
;
while
((
bytesRead
=
inputStream
.
read
(
buffer
))
!=
-
1
)
{
byteArrayOutputStream
.
write
(
buffer
,
0
,
bytesRead
);
}
byteArrayOutputStream
.
flush
();
fileBytes
=
byteArrayOutputStream
.
toByteArray
();
}
catch
(
IOException
e
)
{
System
.
out
.
println
(
e
.
getMessage
());
}
byte
[]
encryptBytes
=
EncryptUtils
.
encryptByAes
(
fileBytes
);
uploadResult
=
storage
.
uploadSuffix
(
encryptBytes
,
suffix
,
"text/plain"
);
}
if
(
Objects
.
nonNull
(
uploadResult
))
{
// 保存文件信息
SysOssVo
vo
=
sysOssService
.
buildResultEntity
(
originalfileName
,
suffix
,
storage
.
getConfigKey
(),
uploadResult
);
newOssIds
.
append
(
vo
.
getOssId
()).
append
(
","
);
}
}
}
if
(
newOssIds
.
toString
().
lastIndexOf
(
","
)
!=
-
1
){
newOssIds
.
deleteCharAt
(
newOssIds
.
length
()-
1
);
}
if
(
StringUtils
.
isNotBlank
(
newOssIds
.
toString
()))
{
courseVo
.
setPptOssId
(
newOssIds
.
toString
());
CourseBo
courseBo
=
BeanUtil
.
toBean
(
courseVo
,
CourseBo
.
class
);
try
{
service
.
updateCourse
(
courseBo
);
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
e
.
getMessage
());
}
}
}
}
return
R
.
ok
(
"game is over"
);
}
/**
* 新增
*
...
...
lego-system/src/main/java/com/lego/system/service/impl/SysOssServiceImpl.java
View file @
6ef5a1a
...
...
@@ -210,13 +210,14 @@ public class SysOssServiceImpl implements ISysOssService, OssService {
OssClient
storage
=
OssFactory
.
instance
();
UploadResult
uploadResult
;
try
{
if
(
".pdf"
.
equals
(
suffix
)
||
".mp4"
.
equals
(
suffix
)
||
".json"
.
equals
(
suffix
)
||
".ldr"
.
equals
(
suffix
))
{
byte
[]
encryptBytes
=
EncryptUtils
.
encryptByAes
(
file
.
getBytes
());
uploadResult
=
storage
.
uploadSuffix
(
encryptBytes
,
suffix
,
file
.
getContentType
());
}
else
{
// if(".pdf".equals(suffix) || ".mp4".equals(suffix) || ".json".equals(suffix) || ".ldr".equals(suffix)) {
// byte[] encryptBytes = EncryptUtils.encryptByAes(file.getBytes());
// uploadResult = storage.uploadSuffix(encryptBytes, suffix, file.getContentType());
// }
// else{
// uploadResult = storage.upload(file.getBytes(), originalfileName, file.getContentType());
// }
uploadResult
=
storage
.
upload
(
file
.
getBytes
(),
originalfileName
,
file
.
getContentType
());
}
}
catch
(
IOException
e
)
{
throw
new
ServiceException
(
e
.
getMessage
());
}
...
...
@@ -258,7 +259,7 @@ public class SysOssServiceImpl implements ISysOssService, OssService {
return
vo
;
}
p
rivate
SysOssVo
buildResultEntity
(
String
originalfileName
,
String
suffix
,
String
configKey
,
UploadResult
uploadResult
)
{
p
ublic
SysOssVo
buildResultEntity
(
String
originalfileName
,
String
suffix
,
String
configKey
,
UploadResult
uploadResult
)
{
SysOss
oss
=
new
SysOss
();
oss
.
setUrl
(
uploadResult
.
getUrl
());
oss
.
setFileSuffix
(
suffix
);
...
...
Write
Preview
Styling with
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