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
4b313cb2
Commit
4b313cb2
authored
Jun 29, 2020
by
luzhuang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: banner企业限制、批量下载课程课件
parent
1dd8a08c
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
207 additions
and
13 deletions
+207
-13
BBannerRepository.java
...a/org/rcisoft/business/bbanner/dao/BBannerRepository.java
+1
-0
BChapterController.java
...soft/business/bchapter/controller/BChapterController.java
+12
-0
BChapterService.java
...rg/rcisoft/business/bchapter/service/BChapterService.java
+6
-0
BChapterServiceImpl.java
...t/business/bchapter/service/impl/BChapterServiceImpl.java
+49
-0
BFileRepository.java
.../java/org/rcisoft/business/bfile/dao/BFileRepository.java
+12
-0
ZipMultiFile.java
src/main/java/org/rcisoft/core/util/ZipMultiFile.java
+127
-13
No files found.
src/main/java/org/rcisoft/business/bbanner/dao/BBannerRepository.java
View file @
4b313cb2
...
@@ -74,6 +74,7 @@ public interface BBannerRepository extends BaseMapper<BBanner> {
...
@@ -74,6 +74,7 @@ public interface BBannerRepository extends BaseMapper<BBanner> {
@Select
(
"<script>select count(1) from b_banner where "
+
@Select
(
"<script>select count(1) from b_banner where "
+
" del_flag = 0 and flag = 1 "
+
" del_flag = 0 and flag = 1 "
+
" and corp_id = #{corpId} "
+
" and corp_id = #{corpId} "
+
" and is_push != 1"
+
"</script>"
)
"</script>"
)
int
selectCountBanner
(
AddOrUpdateDTO
param
);
int
selectCountBanner
(
AddOrUpdateDTO
param
);
...
...
src/main/java/org/rcisoft/business/bchapter/controller/BChapterController.java
View file @
4b313cb2
...
@@ -194,6 +194,18 @@ public class BChapterController extends PaginationController<BChapter> {
...
@@ -194,6 +194,18 @@ public class BChapterController extends PaginationController<BChapter> {
newFileUrl
);
newFileUrl
);
}
}
@ApiOperation
(
value
=
"213 根据传入的课程ids 批量下载文件 返回服务器Zip包地址"
,
notes
=
"下载文件 批量返回服务器Zip包地址"
)
@ApiImplicitParam
(
name
=
"ids"
,
value
=
"课程ids(用英文逗号隔开)"
,
required
=
true
,
dataType
=
"varchar"
)
@PostMapping
(
"/getBatchsDownload"
)
public
Result
getBatchsDownload
(
CurUser
curUser
,
@RequestParam
String
ids
,
BindingResult
br
)
throws
IOException
{
String
newFileUrl
=
bChapterService
.
getBatchsDownload
(
ids
);
return
Result
.
builder
(
new
PersistModel
(
1
),
MessageConstant
.
MESSAGE_ALERT_SUCCESS
,
MessageConstant
.
MESSAGE_ALERT_ERROR
,
newFileUrl
);
}
// @ApiOperation(value = "209 查询章节带进度(外部分享)", notes = "查询章节带进度(外部分享)", response = QueryChapterListResDTO.class)
// @ApiOperation(value = "209 查询章节带进度(外部分享)", notes = "查询章节带进度(外部分享)", response = QueryChapterListResDTO.class)
// @GetMapping(value = "/queryShareBChaptersWithProgress")
// @GetMapping(value = "/queryShareBChaptersWithProgress")
// public Result queryShareBChaptersWithProgress(CurUser curUser, @RequestParam String lessonId, BindingResult br) {
// public Result queryShareBChaptersWithProgress(CurUser curUser, @RequestParam String lessonId, BindingResult br) {
...
...
src/main/java/org/rcisoft/business/bchapter/service/BChapterService.java
View file @
4b313cb2
...
@@ -112,6 +112,12 @@ public interface BChapterService{
...
@@ -112,6 +112,12 @@ public interface BChapterService{
* @return
* @return
*/
*/
String
getBatchDownload
(
String
bFileJson
);
String
getBatchDownload
(
String
bFileJson
);
/**
* 下载文件
* @param bFileJson
* @return
*/
String
getBatchsDownload
(
String
bFileJson
);
/**
/**
* 判断文件是否
* 判断文件是否
...
...
src/main/java/org/rcisoft/business/bchapter/service/impl/BChapterServiceImpl.java
View file @
4b313cb2
...
@@ -804,6 +804,55 @@ public class BChapterServiceImpl implements BChapterService {
...
@@ -804,6 +804,55 @@ public class BChapterServiceImpl implements BChapterService {
return
returnAddress
;
return
returnAddress
;
}
}
@Override
public
String
getBatchsDownload
(
String
ids
)
{
// 拆分ids
String
[]
lessonIds
=
ids
.
split
(
","
);
String
batchUDID
=
IdGen
.
uuid
();
//遍历每个id
for
(
String
id
:
lessonIds
){
List
<
BFile
>
fileList
=
bFileRepository
.
getFileByLessonId
(
id
);
//批量打包下载
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
;
}
String
filePath
=
global
.
getBASE_UPLOAD_SERVER_LOCATION
()
+
global
.
getCOURSE_LOCATION
()
+
File
.
separator
+
batchUDID
+
File
.
separator
+
bFile
.
getLessonId
();
File
file
=
new
File
(
filePath
);
downLoadFile
(
bFile
,
file
,
filePath
);
});
if
(
fileList
.
size
()
<
1
)
{
throw
new
ServiceException
(
ResultServiceEnums
.
NOT_DOWNLOAD_FILE
);
}
}
String
uuid
=
IdGen
.
uuid
();
//文件打包地址
File
zipFilePath
=
new
File
(
global
.
getBASE_UPLOAD_SERVER_LOCATION
()
+
global
.
getCOURSE_LOCATION
()
+
File
.
separator
+
global
.
getZIP_LOCATION
());
if
(!
zipFilePath
.
exists
())
zipFilePath
.
mkdirs
();
File
zipFile
=
new
File
(
zipFilePath
.
getPath
()
+
File
.
separator
+
uuid
+
".zip"
);
//返回地址
String
returnAddress
=
global
.
getRETURN_UPLOAD_SERVER_LOCATION
()
+
global
.
getCOURSE_LOCATION
()
+
File
.
separator
+
global
.
getZIP_LOCATION
()
+
File
.
separator
+
uuid
+
".zip"
;
try
{
String
zipUrl
=
global
.
getBASE_UPLOAD_SERVER_LOCATION
()
+
global
.
getCOURSE_LOCATION
()
+
File
.
separator
+
batchUDID
;
//打包
ZipMultiFile
.
toZip
(
zipUrl
,
new
FileOutputStream
(
zipFile
),
true
);
//删除 文件夹
ZipMultiFile
.
deleteDirectory
(
new
File
(
zipUrl
));
}
catch
(
FileNotFoundException
e
)
{
e
.
printStackTrace
();
}
return
returnAddress
;
}
@Override
@Override
public
String
fileReadable
(
BFile
bFile
)
{
public
String
fileReadable
(
BFile
bFile
)
{
String
flag
=
"1"
;
String
flag
=
"1"
;
...
...
src/main/java/org/rcisoft/business/bfile/dao/BFileRepository.java
View file @
4b313cb2
...
@@ -78,5 +78,17 @@ public interface BFileRepository extends BaseMapper<BFile> {
...
@@ -78,5 +78,17 @@ public interface BFileRepository extends BaseMapper<BFile> {
int
updateUploadFile
(
BFile
bFile
);
int
updateUploadFile
(
BFile
bFile
);
/**
* 根据 课程id 查询 文件集合
* @param id
* @return
*/
@Select
(
" select * from b_file "
+
" where chapter_id in (select business_id from b_chapter where lesson_id = #{id} and del_flag != 1 and flag = 1 and chapter_level = 2) "
+
" and del_flag != 1 and flag = 1 "
)
@ResultMap
(
value
=
"BaseResultMap"
)
List
<
BFile
>
getFileByLessonId
(
String
id
);
}
}
src/main/java/org/rcisoft/core/util/ZipMultiFile.java
View file @
4b313cb2
...
@@ -10,24 +10,31 @@ import java.util.zip.ZipEntry;
...
@@ -10,24 +10,31 @@ import java.util.zip.ZipEntry;
import
java.util.zip.ZipOutputStream
;
import
java.util.zip.ZipOutputStream
;
/**
/**
* @describe 压缩多个文件
* @author zfc
* @author zfc
* @describe 压缩多个文件
* @date 2018年1月11日 下午8:34:00
* @date 2018年1月11日 下午8:34:00
*/
*/
@Slf4j
@Slf4j
public
class
ZipMultiFile
{
public
class
ZipMultiFile
{
public
static
void
main
(
String
[]
args
)
{
private
static
final
int
BUFFER_SIZE
=
2
*
1024
;
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\\1234\\ZipFile.zip"
);
public
static
void
main
(
String
[]
args
)
throws
Exception
{
// 调用压缩方法
/** 测试压缩方法 */
File
file
=
new
File
(
"E:\\5dd3f8a94309408889613d2eac423902.zip"
);
FileOutputStream
fos1
=
new
FileOutputStream
(
file
);
System
.
out
.
println
(
file
.
getPath
());
toZip
(
"E:\\maven"
,
fos1
,
true
);
//
// File file2 = new File("F:\\working\\test");
// deleteDirectory(file2);
// zipFiles(Arrays.asList(srcFiles), zipFile);
}
}
public
static
String
zipFiles
(
List
<
BFile
>
srcFiles
,
File
zipFile
)
{
public
static
String
zipFiles
(
List
<
BFile
>
srcFiles
,
File
zipFile
)
{
// 判断压缩后的文件存在不,不存在则创建
// 判断压缩后的文件存在不,不存在则创建
if
(!
zipFile
.
getParentFile
().
exists
()){
if
(!
zipFile
.
getParentFile
().
exists
())
{
zipFile
.
getParentFile
().
mkdirs
();
zipFile
.
getParentFile
().
mkdirs
();
}
}
...
@@ -57,7 +64,7 @@ public class ZipMultiFile {
...
@@ -57,7 +64,7 @@ public class ZipMultiFile {
// 将源文件数组中的当前文件读入 FileInputStream 流中
// 将源文件数组中的当前文件读入 FileInputStream 流中
fileInputStream
=
new
FileInputStream
(
new
File
(
srcFiles
.
get
(
i
).
getFileUrl
()));
fileInputStream
=
new
FileInputStream
(
new
File
(
srcFiles
.
get
(
i
).
getFileUrl
()));
// 实例化 ZipEntry 对象,源文件数组中的当前文件
// 实例化 ZipEntry 对象,源文件数组中的当前文件
zipEntry
=
new
ZipEntry
(
srcFiles
.
get
(
i
).
getFileName
()
+
srcFiles
.
get
(
i
).
getFileUrl
().
substring
(
srcFiles
.
get
(
i
).
getFileUrl
().
lastIndexOf
(
"."
)));
zipEntry
=
new
ZipEntry
(
srcFiles
.
get
(
i
).
getFileName
()
+
srcFiles
.
get
(
i
).
getFileUrl
().
substring
(
srcFiles
.
get
(
i
).
getFileUrl
().
lastIndexOf
(
"."
)));
zipOutputStream
.
putNextEntry
(
zipEntry
);
zipOutputStream
.
putNextEntry
(
zipEntry
);
// 该变量记录每次真正读的字节个数
// 该变量记录每次真正读的字节个数
int
len
;
int
len
;
...
@@ -71,7 +78,7 @@ public class ZipMultiFile {
...
@@ -71,7 +78,7 @@ public class ZipMultiFile {
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
finally
{
}
finally
{
try
{
try
{
zipOutputStream
.
closeEntry
();
zipOutputStream
.
closeEntry
();
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
...
@@ -84,13 +91,120 @@ public class ZipMultiFile {
...
@@ -84,13 +91,120 @@ public class ZipMultiFile {
return
zipFile
.
getPath
();
return
zipFile
.
getPath
();
}
}
private
static
void
closeStream
(
Closeable
stream
){
private
static
void
closeStream
(
Closeable
stream
)
{
try
{
try
{
if
(
stream
!=
null
)
{
if
(
stream
!=
null
)
{
stream
.
close
();
stream
.
close
();
}
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
"关闭流错误!"
,
e
);
log
.
error
(
"关闭流错误!"
,
e
);
}
}
}
}
/**
* 压缩成ZIP 方法 * @param srcDir 压缩文件夹路径
*
* @param out 压缩文件输出流
* @param KeepDirStructure 是否保留原来的目录结构,true:保留目录结构;
* false:所有文件跑到压缩包根目录下(注意:不保留目录结构可能会出现同名文件,会压缩失败)
* @throws RuntimeException 压缩失败会抛出运行时异常
*/
public
static
void
toZip
(
String
srcDir
,
OutputStream
out
,
boolean
KeepDirStructure
)
throws
RuntimeException
{
long
start
=
System
.
currentTimeMillis
();
ZipOutputStream
zos
=
null
;
try
{
zos
=
new
ZipOutputStream
(
out
);
File
sourceFile
=
new
File
(
srcDir
);
compress
(
sourceFile
,
zos
,
sourceFile
.
getName
(),
KeepDirStructure
);
long
end
=
System
.
currentTimeMillis
();
log
.
info
(
"压缩完成,耗时:"
+
(
end
-
start
)
+
" ms"
);
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
"zip error from ZipUtils"
,
e
);
}
finally
{
if
(
zos
!=
null
)
{
try
{
zos
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
}
/**
* 递归压缩方法
*
* @param sourceFile 源文件
* @param zos zip输出流
* @param name 压缩后的名称
* @param KeepDirStructure 是否保留原来的目录结构,true:保留目录结构;
* false:所有文件跑到压缩包根目录下(注意:不保留目录结构可能会出现同名文件,会压缩失败)
* @throws Exception
*/
private
static
void
compress
(
File
sourceFile
,
ZipOutputStream
zos
,
String
name
,
boolean
KeepDirStructure
)
throws
Exception
{
byte
[]
buf
=
new
byte
[
BUFFER_SIZE
];
if
(
sourceFile
.
isFile
())
{
// 向zip输出流中添加一个zip实体,构造器中name为zip实体的文件的名字
zos
.
putNextEntry
(
new
ZipEntry
(
name
));
// copy文件到zip输出流中
int
len
;
FileInputStream
in
=
new
FileInputStream
(
sourceFile
);
while
((
len
=
in
.
read
(
buf
))
!=
-
1
)
{
zos
.
write
(
buf
,
0
,
len
);
}
// Complete the entry
zos
.
closeEntry
();
in
.
close
();
}
else
{
//是文件夹
File
[]
listFiles
=
sourceFile
.
listFiles
();
if
(
listFiles
==
null
||
listFiles
.
length
==
0
)
{
// 需要保留原来的文件结构时,需要对空文件夹进行处理
if
(
KeepDirStructure
)
{
// 空文件夹的处理
zos
.
putNextEntry
(
new
ZipEntry
(
name
+
"/"
));
// 没有文件,不需要文件的copy
zos
.
closeEntry
();
}
}
else
{
for
(
File
file
:
listFiles
)
{
// 判断是否需要保留原来的文件结构
if
(
KeepDirStructure
)
{
// 注意:file.getName()前面需要带上父文件夹的名字加一斜杠,
// 不然最后压缩包中就不能保留原来的文件结构,即:所有文件都跑到压缩包根目录下了
compress
(
file
,
zos
,
name
+
"/"
+
file
.
getName
(),
KeepDirStructure
);
}
else
{
compress
(
file
,
zos
,
file
.
getName
(),
KeepDirStructure
);
}
}
}
}
}
/**
* 删除文件夹的内容
* @param file
*/
public
static
void
deleteDirectory
(
File
file
)
{
if
(
file
.
isFile
())
{
file
.
delete
();
//清理文件
}
else
{
File
list
[]
=
file
.
listFiles
();
if
(
list
!=
null
)
{
for
(
File
f
:
list
)
{
deleteDirectory
(
f
);
}
file
.
delete
();
//清理目录
}
}
}
}
}
\ 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