Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
education
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
李丛阳
education
Commits
35c3993f
Commit
35c3993f
authored
Jan 09, 2020
by
zhangqingle
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改批量下载打zip包 增加定时删除zip文件 增加配置
parent
61f31932
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
94 additions
and
22 deletions
+94
-22
BChapterController.java
...soft/business/bchapter/controller/BChapterController.java
+4
-4
BChapterServiceImpl.java
...t/business/bchapter/service/impl/BChapterServiceImpl.java
+9
-4
Global.java
src/main/java/org/rcisoft/common/component/Global.java
+3
-0
DeleteZipTask.java
src/main/java/org/rcisoft/core/task/DeleteZipTask.java
+35
-0
ZipMultiFile.java
src/main/java/org/rcisoft/core/util/ZipMultiFile.java
+38
-14
application-mt.yml
src/main/resources/application-mt.yml
+5
-0
No files found.
src/main/java/org/rcisoft/business/bchapter/controller/BChapterController.java
View file @
35c3993f
...
...
@@ -145,7 +145,7 @@ public class BChapterController extends PaginationController<BChapter> {
}
@ApiOperation
(
value
=
"208 下载文件 返回服务器地址"
,
notes
=
"下载文件 返回服务器地址"
)
@
Ge
tMapping
(
"/getDownLoadUrl"
)
@
Pos
tMapping
(
"/getDownLoadUrl"
)
public
Result
getDownLoadUrl
(
CurUser
curUser
,
@Valid
BFile
file
,
BindingResult
br
)
throws
IOException
{
String
newFileUrl
=
bChapterService
.
getDownLoadUrl
(
file
);
return
Result
.
builder
(
new
PersistModel
(
1
),
...
...
@@ -183,9 +183,9 @@ public class BChapterController extends PaginationController<BChapter> {
file
.
getOriginalFilename
());
}
@Api
Operation
(
value
=
"208 下载文件 返回服务器地址"
,
notes
=
"下载文件 返回服务器地址
"
)
@
Ge
tMapping
(
"/getBatchDownload"
)
@ApiOperation
(
value
=
"212 批量下载文件 返回服务器Zip包地址"
,
notes
=
"下载文件 批量返回服务器Zip包地址"
)
@Api
ImplicitParam
(
name
=
"businessId"
,
value
=
"文件json"
,
required
=
true
,
dataType
=
"varchar
"
)
@
Pos
tMapping
(
"/getBatchDownload"
)
public
Result
getBatchDownload
(
CurUser
curUser
,
@Valid
String
fileJson
,
BindingResult
br
)
throws
IOException
{
String
newFileUrl
=
bChapterService
.
getBatchDownload
(
fileJson
);
return
Result
.
builder
(
new
PersistModel
(
1
),
...
...
src/main/java/org/rcisoft/business/bchapter/service/impl/BChapterServiceImpl.java
View file @
35c3993f
...
...
@@ -679,6 +679,7 @@ public class BChapterServiceImpl implements BChapterService {
if
(
fileList
==
null
||
fileList
.
size
()
<
1
){
throw
new
ServiceException
(
ResultServiceEnums
.
NOT_DOWNLOAD_FILE
);
}
//判断文件是否存在 不存在下载 并将这些文件包装成File
fileList
.
forEach
(
bFile
->
{
if
(
StringUtils
.
isEmpty
(
bFile
.
getVideoUrl
())
||
StringUtils
.
isEmpty
(
bFile
.
getLessonId
()))
{
return
;
...
...
@@ -698,10 +699,14 @@ public class BChapterServiceImpl implements BChapterService {
if
(
bFiles
.
size
()
<
1
){
throw
new
ServiceException
(
ResultServiceEnums
.
NOT_DOWNLOAD_FILE
);
}
File
[]
bFileArray
=
(
File
[])
bFiles
.
toArray
();
File
zipFile
=
new
File
(
global
.
getRETURN_UPLOAD_SERVER_LOCATION
()
+
global
.
getCOURSE_LOCATION
()
+
File
.
separator
+
"Zip"
+
File
.
separator
+
IdGen
.
uuid
());
return
ZipMultiFile
.
zipFiles
(
bFileArray
,
zipFile
);
String
uuid
=
IdGen
.
uuid
();
//文件打包地址
File
zipFile
=
new
File
(
global
.
getBASE_UPLOAD_SERVER_LOCATION
()
+
global
.
getCOURSE_LOCATION
()
+
File
.
separator
+
global
.
getZIP_LOCATION
()
+
File
.
separator
+
uuid
+
".zip"
);
//返回地址
String
returnAddress
=
global
.
getRETURN_UPLOAD_SERVER_LOCATION
()
+
global
.
getCOURSE_LOCATION
()
+
File
.
separator
+
global
.
getZIP_LOCATION
()
+
File
.
separator
+
uuid
+
".zip"
;
//打包
ZipMultiFile
.
zipFiles
(
bFiles
,
zipFile
);
return
returnAddress
;
}
@Override
...
...
src/main/java/org/rcisoft/common/component/Global.java
View file @
35c3993f
...
...
@@ -98,6 +98,9 @@ public class Global {
@Value
(
"${global.path.cource_logo_location}"
)
private
String
COURSE_LOGO_LOCATION
;
/*压缩文件路径*/
@Value
(
"${global.path.zip_location:zip}"
)
private
String
ZIP_LOCATION
;
/*是否是服务器(为1代表是服务器)*/
...
...
src/main/java/org/rcisoft/core/task/DeleteZipTask.java
0 → 100644
View file @
35c3993f
package
org
.
rcisoft
.
core
.
task
;
import
lombok.extern.slf4j.Slf4j
;
import
org.rcisoft.common.component.Global
;
import
org.rcisoft.core.util.DeleteFileUtil
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.io.File
;
@Component
@ConditionalOnProperty
(
prefix
=
"deleteZipJob"
,
name
=
{
"openTask"
},
havingValue
=
"true"
)
@Slf4j
public
class
DeleteZipTask
{
@Autowired
private
Global
global
;
@Scheduled
(
cron
=
"${deleteZipJob.taskInterval:0 0 2 * * ?}"
)
@Transactional
(
propagation
=
Propagation
.
REQUIRED
,
readOnly
=
false
)
public
void
work
()
throws
Exception
{
String
filePath
=
global
.
getBASE_UPLOAD_SERVER_LOCATION
()
+
global
.
getCOURSE_LOCATION
()
+
File
.
separator
+
global
.
getZIP_LOCATION
();
DeleteFileUtil
.
delAllFile
(
filePath
);
}
}
src/main/java/org/rcisoft/core/util/ZipMultiFile.java
View file @
35c3993f
package
org
.
rcisoft
.
core
.
util
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
lombok.extern.slf4j.Slf4j
;
import
java.io.*
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.zip.ZipEntry
;
import
java.util.zip.ZipOutputStream
;
...
...
@@ -12,17 +13,23 @@ import java.util.zip.ZipOutputStream;
* @author zfc
* @date 2018年1月11日 下午8:34:00
*/
@Slf4j
public
class
ZipMultiFile
{
public
static
void
main
(
String
[]
args
)
{
File
[]
srcFiles
=
{
new
File
(
"C:\\Users\\三\\Desktop\\暂时\\deleteFile\\新建文件夹\\avi.mp4"
),
new
File
(
"C:\\Users\\三\\Desktop\\暂时\\deleteFile\\新建文件夹\\新建文件夹\\攻防思路.pptx"
),
new
File
(
"C:\\Users\\三\\Desktop\\暂时\\deleteFile\\新建文件夹\\新建文件夹\\音频.mp3"
)
};
File
zipFile
=
new
File
(
"C:\\Users\\三\\Desktop\\暂时\\deleteFile\\ZipFile.zip"
);
File
zipFile
=
new
File
(
"C:\\Users\\三\\Desktop\\暂时\\deleteFile\\
1234\\
ZipFile.zip"
);
// 调用压缩方法
zipFiles
(
srcFiles
,
zipFile
);
zipFiles
(
Arrays
.
asList
(
srcFiles
),
zipFile
);
}
public
static
String
zipFiles
(
File
[]
srcFiles
,
File
zipFile
)
{
public
static
String
zipFiles
(
List
<
File
>
srcFiles
,
File
zipFile
)
{
// 判断压缩后的文件存在不,不存在则创建
if
(!
zipFile
.
getParentFile
().
exists
()){
zipFile
.
getParentFile
().
mkdirs
();
}
if
(!
zipFile
.
exists
())
{
try
{
zipFile
.
createNewFile
();
...
...
@@ -45,11 +52,11 @@ public class ZipMultiFile {
// 创建 ZipEntry 对象
ZipEntry
zipEntry
=
null
;
// 遍历源文件数组
for
(
int
i
=
0
;
i
<
srcFiles
.
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
srcFiles
.
size
()
;
i
++)
{
// 将源文件数组中的当前文件读入 FileInputStream 流中
fileInputStream
=
new
FileInputStream
(
srcFiles
[
i
]
);
fileInputStream
=
new
FileInputStream
(
srcFiles
.
get
(
i
)
);
// 实例化 ZipEntry 对象,源文件数组中的当前文件
zipEntry
=
new
ZipEntry
(
srcFiles
[
i
]
.
getName
());
zipEntry
=
new
ZipEntry
(
srcFiles
.
get
(
i
)
.
getName
());
zipOutputStream
.
putNextEntry
(
zipEntry
);
// 该变量记录每次真正读的字节个数
int
len
;
...
...
@@ -58,14 +65,31 @@ public class ZipMultiFile {
while
((
len
=
fileInputStream
.
read
(
buffer
))
>
0
)
{
zipOutputStream
.
write
(
buffer
,
0
,
len
);
}
fileInputStream
.
close
();
}
zipOutputStream
.
closeEntry
();
zipOutputStream
.
close
();
fileInputStream
.
close
();
fileOutputStream
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
finally
{
try
{
zipOutputStream
.
closeEntry
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
closeStream
(
zipOutputStream
);
closeStream
(
fileInputStream
);
closeStream
(
fileOutputStream
);
}
return
zipFile
.
getPath
();
}
private
static
void
closeStream
(
Closeable
stream
){
try
{
if
(
stream
!=
null
){
stream
.
close
();
}
}
catch
(
Exception
e
){
log
.
error
(
"关闭流错误!"
,
e
);
}
}
}
\ No newline at end of file
src/main/resources/application-mt.yml
View file @
35c3993f
...
...
@@ -91,6 +91,7 @@ global:
pdf_location
:
pdf
cut_pdf_location
:
cutPdf
cource_logo_location
:
/course/logo
zip_location
:
zip
other
:
is_server_linux
:
5
cut_pdf_num
:
30
...
...
@@ -106,6 +107,10 @@ deleteFileJob:
delFlag
:
0
#0仅删除mp4 mp3(默认) 1删除全部
openTask
:
true
#删除文件定时任务是否开启
deleteZipJob
:
taskInterval
:
0 0 2 * * ?
#执行时间 默认每天凌晨2点执行
openTask
:
true
#删除文件定时任务是否开启
libreoffice
:
ip
:
mt_libre
port
:
8997
...
...
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