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
d55febc2
Commit
d55febc2
authored
Apr 04, 2020
by
luzhuang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pdf拆分预览 代码优化
parent
3654656a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
71 deletions
+30
-71
BChapterServiceImpl.java
...t/business/bchapter/service/impl/BChapterServiceImpl.java
+30
-71
No files found.
src/main/java/org/rcisoft/business/bchapter/service/impl/BChapterServiceImpl.java
View file @
d55febc2
...
...
@@ -373,7 +373,7 @@ public class BChapterServiceImpl implements BChapterService {
newBchapter
.
setCommonBusinessId
();
}
newBchapter
.
setSort
(
model
.
getSort
()+
i
-
1
);
newBchapter
.
setChapterName
(
newBchapter
.
getChapterName
()+
"-"
+
i
);
newBchapter
.
setChapterName
(
newBchapter
.
getChapterName
()+
i
);
bChapterList
.
add
(
newBchapter
);
newBfile
.
setCommonBusinessId
();
newBfile
.
setChapterId
(
newBchapter
.
getBusinessId
());
...
...
@@ -883,77 +883,33 @@ public class BChapterServiceImpl implements BChapterService {
File
fileNew
=
new
File
(
filePath
+
File
.
separator
+
newName
);
LogUtil
.
fileChangeLog
(
"------------------判断文件类型-----------------------------"
+
fileNew
.
getPath
());
if
(
FileTypeEnum
.
PDF
.
getCode
().
equals
(
bFile
.
getType
()))
{
String
localPath
=
""
;
if
(
fileOld
.
exists
())
{
LogUtil
.
fileChangeLog
(
"------------------存在直接返回路径----------------------------"
+
fileOld
);
int
pages
=
FileReadableUtil
.
pdfReadable
(
filePath
+
File
.
separator
+
name
);
if
(
pages
>
pdfCutPage
){
if
(
bFile
.
getChapterId
()==
null
||
""
.
equals
(
bFile
.
getChapterId
())){
//预览
try
{
List
<
String
>
pdfUrls
=
CutPdfUtil
.
toCutPdf
(
filePath
+
File
.
separator
+
name
,
name
,
pdfCutPage
);
for
(
String
url
:
pdfUrls
){
pdfOssUrls
.
add
(
url
);
}
dto
.
setUrl
(
pdfUrls
.
get
(
0
).
replace
(
filePath
,
returnBasePath
));
dto
.
setPdfNum
(
pdfUrls
.
size
());
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
dto
;
}
List
<
String
>
chapterIds
=
bChapterRepository
.
getPdfIdList
(
bFile
.
getChapterId
());
int
x
=
0
;
for
(
String
s
:
chapterIds
){
x
++;
if
(
s
.
equals
(
bFile
.
getChapterId
())){
break
;
}
}
String
cutPdf
=
filePath
+
File
.
separator
+
"pdf-"
+
name
.
substring
(
0
,
name
.
lastIndexOf
(
"."
))
+
File
.
separator
+
name
.
substring
(
0
,
name
.
lastIndexOf
(
"."
))+
"-"
+
x
+
".pdf"
;
File
pdf
=
new
File
(
cutPdf
);
if
(
pdf
.
exists
()){
dto
.
setUrl
(
returnBasePath
+
File
.
separator
+
"pdf-"
+
name
.
substring
(
0
,
name
.
lastIndexOf
(
"."
))
+
File
.
separator
+
name
.
substring
(
0
,
name
.
lastIndexOf
(
"."
))+
"-"
+
x
+
".pdf"
);
return
dto
;
}
else
{
try
{
List
<
String
>
pdfUrls
=
CutPdfUtil
.
toCutPdf
(
filePath
+
File
.
separator
+
name
,
name
,
pdfCutPage
);
for
(
String
url
:
pdfUrls
){
pdfOssUrls
.
add
(
url
);
}
dto
.
setUrl
(
returnBasePath
+
File
.
separator
+
"pdf-"
+
name
.
substring
(
0
,
name
.
lastIndexOf
(
"."
))
+
File
.
separator
+
name
.
substring
(
0
,
name
.
lastIndexOf
(
"."
))+
"-"
+
x
+
".pdf"
);
dto
.
setPdfNum
(
pdfUrls
.
size
());
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
}
else
{
dto
.
setUrl
(
returnBasePath
+
File
.
separator
+
name
);
}
return
dto
;
localPath
=
filePath
+
File
.
separator
+
name
;
}
else
{
String
downLoadName
=
downLoadFile
(
bFile
,
file
,
filePath
);
LogUtil
.
fileChangeLog
(
"------------------判断pdf是否可读----------------------------"
+
fileOld
);
int
pages
=
FileReadableUtil
.
fileReadable
(
filePath
+
File
.
separator
+
downLoadName
,
fileMaxSize
,
pdfMaxSize
,
txtMaxSize
,
fileMaxPages
);
LogUtil
.
fileChangeLog
(
"------------------pdf文件可读--返回下载后路径-----------------------------"
+
downLoadName
);
if
(
pages
>
pdfCutPage
){
if
(
bFile
.
getChapterId
()==
null
||
""
.
equals
(
bFile
.
getChapterId
())){
//预览
try
{
List
<
String
>
pdfUrls
=
CutPdfUtil
.
toCutPdf
(
filePath
+
File
.
separator
+
name
,
name
,
pdfCutPage
);
for
(
String
url
:
pdfUrls
){
pdfOssUrls
.
add
(
url
);
}
dto
.
setUrl
(
pdfUrls
.
get
(
0
).
replace
(
filePath
,
returnBasePath
));
dto
.
setPdfNum
(
pdfUrls
.
size
());
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
localPath
=
filePath
+
File
.
separator
+
downLoadName
;
}
int
pages
=
FileReadableUtil
.
pdfReadable
(
localPath
);
/**
* 文件已存在或已下载 服务器相对文件路径 localPath 和 pdf页数 pages
*/
if
(
pages
>
pdfCutPage
){
if
(
bFile
.
getChapterId
()
==
null
||
""
.
equals
(
bFile
.
getChapterId
())){
//第一次 预览
try
{
List
<
String
>
pdfUrls
=
CutPdfUtil
.
toCutPdf
(
filePath
+
File
.
separator
+
name
,
name
,
pdfCutPage
);
for
(
String
url
:
pdfUrls
){
pdfOssUrls
.
add
(
url
);
}
return
dto
;
//返回拆分文件第一个路径
dto
.
setUrl
(
pdfUrls
.
get
(
0
).
replace
(
filePath
,
returnBasePath
));
dto
.
setPdfNum
(
pdfUrls
.
size
());
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
else
{
//step1 根据章节id获取对应 文件的序号 x
List
<
String
>
chapterIds
=
bChapterRepository
.
getPdfIdList
(
bFile
.
getChapterId
());
int
x
=
0
;
for
(
String
s
:
chapterIds
){
...
...
@@ -965,10 +921,10 @@ public class BChapterServiceImpl implements BChapterService {
String
cutPdf
=
filePath
+
File
.
separator
+
"pdf-"
+
name
.
substring
(
0
,
name
.
lastIndexOf
(
"."
))
+
File
.
separator
+
name
.
substring
(
0
,
name
.
lastIndexOf
(
"."
))+
"-"
+
x
+
".pdf"
;
File
pdf
=
new
File
(
cutPdf
);
//step2 判断文件是否已存在 存在(直接返回) 不存在(拆分后返回)
if
(
pdf
.
exists
()){
dto
.
setUrl
(
returnBasePath
+
File
.
separator
+
"pdf-"
+
name
.
substring
(
0
,
name
.
lastIndexOf
(
"."
))
+
File
.
separator
+
name
.
substring
(
0
,
name
.
lastIndexOf
(
"."
))+
"-"
+
x
+
".pdf"
);
return
dto
;
}
else
{
try
{
List
<
String
>
pdfUrls
=
CutPdfUtil
.
toCutPdf
(
filePath
+
File
.
separator
+
name
,
name
,
pdfCutPage
);
...
...
@@ -983,11 +939,14 @@ public class BChapterServiceImpl implements BChapterService {
e
.
printStackTrace
();
}
}
}
else
{
dto
.
setUrl
(
returnBasePath
+
File
.
separator
+
name
);
}
return
dto
;
}
else
{
//pdf页数少不满足切割条件 直接返回服务器绝对地址
dto
.
setUrl
(
returnBasePath
+
File
.
separator
+
name
);
}
return
dto
;
/** 不下载pdf、文件转发方案(上传快,没有可读判断)
String hostAddress = "";
try{
...
...
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