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
86bab055
Commit
86bab055
authored
Apr 04, 2020
by
luzhuang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pdf分节 默认400页一节
parent
99d98eb2
Changes
8
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
283 additions
and
43 deletions
+283
-43
BChapterController.java
...soft/business/bchapter/controller/BChapterController.java
+2
-2
BChapterRepository.java
...org/rcisoft/business/bchapter/dao/BChapterRepository.java
+30
-0
FileToPdfAtViewDTO.java
...org/rcisoft/business/bchapter/dto/FileToPdfAtViewDTO.java
+16
-0
BChapterService.java
...rg/rcisoft/business/bchapter/service/BChapterService.java
+1
-1
BChapterServiceImpl.java
...t/business/bchapter/service/impl/BChapterServiceImpl.java
+206
-29
BFileRepository.java
.../java/org/rcisoft/business/bfile/dao/BFileRepository.java
+14
-0
CutPdfUtil.java
src/main/java/org/rcisoft/core/util/CutPdfUtil.java
+9
-3
FileReadableUtil.java
src/main/java/org/rcisoft/core/util/FileReadableUtil.java
+5
-8
No files found.
src/main/java/org/rcisoft/business/bchapter/controller/BChapterController.java
View file @
86bab055
...
@@ -137,11 +137,11 @@ public class BChapterController extends PaginationController<BChapter> {
...
@@ -137,11 +137,11 @@ public class BChapterController extends PaginationController<BChapter> {
@ApiOperation
(
value
=
"207 预览文件"
,
notes
=
"(预览时传)"
)
@ApiOperation
(
value
=
"207 预览文件"
,
notes
=
"(预览时传)"
)
@GetMapping
(
"/getFileAtView"
)
@GetMapping
(
"/getFileAtView"
)
public
Result
getFileAtView
(
CurUser
curUser
,
@Valid
BFile
file
,
BindingResult
br
)
throws
IOException
{
public
Result
getFileAtView
(
CurUser
curUser
,
@Valid
BFile
file
,
BindingResult
br
)
throws
IOException
{
String
newFileUrl
=
bChapterService
.
changeFileToPdfAtView
(
file
);
FileToPdfAtViewDTO
dto
=
bChapterService
.
changeFileToPdfAtView
(
file
);
return
Result
.
builder
(
new
PersistModel
(
1
),
return
Result
.
builder
(
new
PersistModel
(
1
),
MessageConstant
.
MESSAGE_ALERT_SUCCESS
,
MessageConstant
.
MESSAGE_ALERT_SUCCESS
,
MessageConstant
.
MESSAGE_ALERT_ERROR
,
MessageConstant
.
MESSAGE_ALERT_ERROR
,
newFileUrl
);
dto
);
}
}
@ApiOperation
(
value
=
"208 下载文件 返回服务器地址"
,
notes
=
"下载文件 返回服务器地址"
)
@ApiOperation
(
value
=
"208 下载文件 返回服务器地址"
,
notes
=
"下载文件 返回服务器地址"
)
...
...
src/main/java/org/rcisoft/business/bchapter/dao/BChapterRepository.java
View file @
86bab055
...
@@ -450,5 +450,35 @@ public interface BChapterRepository extends BaseMapper<BChapter> {
...
@@ -450,5 +450,35 @@ public interface BChapterRepository extends BaseMapper<BChapter> {
@Update
(
"update b_chapter set chapter_name = #{name} where business_id = #{id}"
)
@Update
(
"update b_chapter set chapter_name = #{name} where business_id = #{id}"
)
int
updateChapterName
(
@Param
(
"name"
)
String
name
,
@Param
(
"id"
)
String
id
);
int
updateChapterName
(
@Param
(
"name"
)
String
name
,
@Param
(
"id"
)
String
id
);
/**
* 根据chapterid查询分割pdf章节的chapterIdList
* @param chapterId
* @return
*/
@Select
(
"SELECT business_id "
+
"from b_chapter where business_id in( "
+
" SELECT chapter_id from b_file where video_url = ( "
+
" select video_url from b_file where chapter_id = #{chapterId} and del_flag != 1 and flag =1) "
+
" and del_flag != 1 and flag =1) "
+
"ORDER BY sort"
)
List
<
String
>
getPdfIdList
(
@Param
(
"chapterId"
)
String
chapterId
);
/**
* 新增节时 pdf分节查询出之前 排序大于修改节的chapterId
* @param chapterId
* @return
*/
@Select
(
"select business_id from b_chapter where sort > ( "
+
"select sort from b_chapter where business_id = #{chapterId} and del_flag != 1 and flag =1) "
+
"and del_flag != 1 and flag =1 "
+
"and pid = #{pid}"
)
List
<
String
>
getPDFSortList
(
@Param
(
"chapterId"
)
String
chapterId
,
@Param
(
"pid"
)
String
pid
);
@Update
(
"<script>"
+
"<foreach collection=\"ids\" item=\"item\" separator=\";\">"
+
"update b_chapter set sort = (sort+#{num}) where business_id = #{item}"
+
"</foreach></script>"
)
int
updatePdfSort
(
@Param
(
"ids"
)
List
<
String
>
ids
,
@Param
(
"num"
)
int
num
);
}
}
src/main/java/org/rcisoft/business/bchapter/dto/FileToPdfAtViewDTO.java
0 → 100644
View file @
86bab055
package
org
.
rcisoft
.
business
.
bchapter
.
dto
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
java.util.List
;
@Data
public
class
FileToPdfAtViewDTO
{
@ApiModelProperty
(
value
=
"预览地址"
)
private
String
url
;
@ApiModelProperty
(
value
=
"切割pdf数量"
)
private
int
pdfNum
;
}
src/main/java/org/rcisoft/business/bchapter/service/BChapterService.java
View file @
86bab055
...
@@ -97,7 +97,7 @@ public interface BChapterService{
...
@@ -97,7 +97,7 @@ public interface BChapterService{
* @param bFile
* @param bFile
* @return
* @return
*/
*/
String
changeFileToPdfAtView
(
BFile
bFile
);
FileToPdfAtViewDTO
changeFileToPdfAtView
(
BFile
bFile
);
/**
/**
* 下载文件
* 下载文件
...
...
src/main/java/org/rcisoft/business/bchapter/service/impl/BChapterServiceImpl.java
View file @
86bab055
This diff is collapsed.
Click to expand it.
src/main/java/org/rcisoft/business/bfile/dao/BFileRepository.java
View file @
86bab055
...
@@ -51,6 +51,20 @@ public interface BFileRepository extends BaseMapper<BFile> {
...
@@ -51,6 +51,20 @@ public interface BFileRepository extends BaseMapper<BFile> {
"VALUES (#{businessId}, #{lessonId}, #{chapterId}, #{fileName}, #{videoUrl}, #{fileUrl}, #{type}, #{flag}, #{delFlag}, #{remarks}, #{createBy}, #{updateBy}, #{updateDate}, #{createDate},#{fileSize},#{fileTime})"
)
"VALUES (#{businessId}, #{lessonId}, #{chapterId}, #{fileName}, #{videoUrl}, #{fileUrl}, #{type}, #{flag}, #{delFlag}, #{remarks}, #{createBy}, #{updateBy}, #{updateDate}, #{createDate},#{fileSize},#{fileTime})"
)
int
insertUploadFile
(
BFile
bFile
);
int
insertUploadFile
(
BFile
bFile
);
/**
* 添加文件信息到file表
* @return
*/
@Insert
(
"<script>"
+
"INSERT INTO `b_file` "
+
"(business_id,lesson_id,chapter_id,file_name,video_url,file_url,type,flag,del_flag,remarks,create_by,update_by,update_date,create_date,file_size,file_time) "
+
"VALUES "
+
"<foreach collection=\"list\" item=\"item\" separator=\",\">"
+
"(#{item.businessId}, #{item.lessonId}, #{item.chapterId}, #{item.fileName}, #{item.videoUrl}, #{item.fileUrl}, #{item.type}, "
+
"#{item.flag}, #{item.delFlag}, #{item.remarks}, #{item.createBy}, #{item.updateBy}, #{item.updateDate}, #{item.createDate},#{item.fileSize},#{item.fileTime})"
+
"</foreach></script>"
)
int
insertUploadFileList
(
List
<
BFile
>
bFiles
);
@Update
(
"update b_file set "
+
@Update
(
"update b_file set "
+
"file_name = #{fileName} , "
+
"file_name = #{fileName} , "
+
"video_url = #{videoUrl} ,"
+
"video_url = #{videoUrl} ,"
+
...
...
src/main/java/org/rcisoft/core/util/CutPdfUtil.java
View file @
86bab055
...
@@ -8,6 +8,7 @@ import com.itextpdf.text.pdf.PdfReader;
...
@@ -8,6 +8,7 @@ import com.itextpdf.text.pdf.PdfReader;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.text.SimpleDateFormat
;
import
java.text.SimpleDateFormat
;
...
@@ -23,7 +24,7 @@ import java.util.List;
...
@@ -23,7 +24,7 @@ import java.util.List;
public
class
CutPdfUtil
{
public
class
CutPdfUtil
{
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
try
{
try
{
List
<
String
>
pdfList
=
toCutPdf
(
"F:\\桌面整理\\文件
归纳\\QQ下载\\xx文字+图片-100页.pdf"
,
3
);
List
<
String
>
pdfList
=
toCutPdf
(
"F:\\桌面整理\\文件
\\测试资料\\06_API常用类.pdf"
,
"06_API常用类.pdf"
,
20
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
...
@@ -37,7 +38,7 @@ public class CutPdfUtil {
...
@@ -37,7 +38,7 @@ public class CutPdfUtil {
* @return
* @return
* @throws Exception
* @throws Exception
*/
*/
public
static
List
<
String
>
toCutPdf
(
String
filePath
,
int
page
)
throws
Exception
{
public
static
List
<
String
>
toCutPdf
(
String
filePath
,
String
fileName
,
int
page
)
throws
Exception
{
List
<
String
>
pdfList
=
new
ArrayList
<>();
List
<
String
>
pdfList
=
new
ArrayList
<>();
long
l1
=
System
.
currentTimeMillis
();
long
l1
=
System
.
currentTimeMillis
();
int
i
=
0
;
int
i
=
0
;
...
@@ -46,7 +47,8 @@ public class CutPdfUtil {
...
@@ -46,7 +47,8 @@ public class CutPdfUtil {
PdfReader
reader
=
new
PdfReader
(
filePath
);
PdfReader
reader
=
new
PdfReader
(
filePath
);
int
pageNum
=
reader
.
getNumberOfPages
();
int
pageNum
=
reader
.
getNumberOfPages
();
do
{
do
{
String
newFilePath
=
filePath
.
substring
(
0
,
filePath
.
lastIndexOf
(
"."
))
+
"-"
+
j
+
".pdf"
;
String
path
=
filePath
.
replace
(
fileName
,
"pdf-"
+
fileName
);
String
newFilePath
=
path
.
substring
(
0
,
path
.
lastIndexOf
(
"."
))
+
File
.
separator
+
fileName
.
substring
(
0
,
fileName
.
lastIndexOf
(
"."
))+
"-"
+
j
+
".pdf"
;
int
end
=
i
+
page
;
int
end
=
i
+
page
;
if
(
end
>=
pageNum
)
{
if
(
end
>=
pageNum
)
{
end
=
pageNum
;
end
=
pageNum
;
...
@@ -76,7 +78,11 @@ public class CutPdfUtil {
...
@@ -76,7 +78,11 @@ public class CutPdfUtil {
String
newFilePath
,
int
from
,
int
end
)
{
String
newFilePath
,
int
from
,
int
end
)
{
Document
document
=
null
;
Document
document
=
null
;
PdfCopy
copy
=
null
;
PdfCopy
copy
=
null
;
File
newFile
=
new
File
(
newFilePath
);
try
{
try
{
if
(!
newFile
.
getParentFile
().
exists
())
{
newFile
.
getParentFile
().
mkdirs
();
}
document
=
new
Document
(
reader
.
getPageSize
(
1
));
document
=
new
Document
(
reader
.
getPageSize
(
1
));
copy
=
new
PdfCopy
(
document
,
new
FileOutputStream
(
newFilePath
));
copy
=
new
PdfCopy
(
document
,
new
FileOutputStream
(
newFilePath
));
document
.
open
();
document
.
open
();
...
...
src/main/java/org/rcisoft/core/util/FileReadableUtil.java
View file @
86bab055
...
@@ -136,7 +136,7 @@ public class FileReadableUtil {
...
@@ -136,7 +136,7 @@ public class FileReadableUtil {
}
}
p
rivate
static
Integer
pdfReadable
(
String
path
){
p
ublic
static
Integer
pdfReadable
(
String
path
){
Integer
pages
;
Integer
pages
;
PDDocument
doc
=
null
;
PDDocument
doc
=
null
;
try
{
try
{
...
@@ -155,7 +155,7 @@ public class FileReadableUtil {
...
@@ -155,7 +155,7 @@ public class FileReadableUtil {
}
}
FileReadableUtil
.
closeOtherStream
(
doc
);
FileReadableUtil
.
closeOtherStream
(
doc
);
}
}
return
1
;
return
pages
;
}
}
private
static
Integer
docxReadable
(
String
path
){
private
static
Integer
docxReadable
(
String
path
){
Integer
pages
;
Integer
pages
;
...
@@ -190,7 +190,7 @@ public class FileReadableUtil {
...
@@ -190,7 +190,7 @@ public class FileReadableUtil {
}
}
public
static
void
fileReadable
(
String
path
,
Long
fileMaxSize
,
Long
pdfMaxSize
,
Long
txtMaxSize
,
Integer
fileMaxPages
)
{
public
static
int
fileReadable
(
String
path
,
Long
fileMaxSize
,
Long
pdfMaxSize
,
Long
txtMaxSize
,
Integer
fileMaxPages
)
{
LogUtil
.
fileChangeLog
(
"-----------FileReadableUtil-路径------------"
+
path
);
LogUtil
.
fileChangeLog
(
"-----------FileReadableUtil-路径------------"
+
path
);
File
file
=
new
File
(
path
);
File
file
=
new
File
(
path
);
Long
size
=
file
.
length
();
Long
size
=
file
.
length
();
...
@@ -237,13 +237,10 @@ public class FileReadableUtil {
...
@@ -237,13 +237,10 @@ public class FileReadableUtil {
break
;
break
;
}
}
if
(
pages
!=
-
1
&&
pages
>
fileMaxPages
)
{
if
(
pages
!=
-
1
&&
pages
>
fileMaxPages
&&
!
"pdf"
.
equals
(
path
.
substring
(
path
.
lastIndexOf
(
"."
)
+
1
))
)
{
throw
new
ServiceException
(
400
,
"该文件超过最多"
+
fileMaxPages
+
"页限制"
);
throw
new
ServiceException
(
400
,
"该文件超过最多"
+
fileMaxPages
+
"页限制"
);
}
}
return
pages
;
// if (!CheckFileHeaderUtil.toCheck(path)){
// throw new ServiceException(ResultServiceEnums.FILE_UNREADABLE);
// }
}
}
public
File
TXTHandler
(
File
file
)
{
public
File
TXTHandler
(
File
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