Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
slm-fileview
Project
Project
Details
Activity
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
jenkins
slm-fileview
Commits
1edf4d83
Commit
1edf4d83
authored
May 18, 2020
by
陈精华
Committed by
kl
May 18, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化:重构代码
parent
f620c007
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
95 additions
and
82 deletions
+95
-82
ConfigConstants.java
...r-web/src/main/java/cn/keking/config/ConfigConstants.java
+1
-1
FileConvertQueueTask.java
...src/main/java/cn/keking/service/FileConvertQueueTask.java
+1
-1
CacheServiceRocksDBImpl.java
...cn/keking/service/cache/impl/CacheServiceRocksDBImpl.java
+17
-10
CadFilePreviewImpl.java
.../main/java/cn/keking/service/impl/CadFilePreviewImpl.java
+22
-17
CompressFilePreviewImpl.java
.../java/cn/keking/service/impl/CompressFilePreviewImpl.java
+12
-8
MediaFilePreviewImpl.java
...ain/java/cn/keking/service/impl/MediaFilePreviewImpl.java
+0
-5
OfficeFilePreviewImpl.java
...in/java/cn/keking/service/impl/OfficeFilePreviewImpl.java
+18
-15
OtherFilePreviewImpl.java
...ain/java/cn/keking/service/impl/OtherFilePreviewImpl.java
+0
-5
PdfFilePreviewImpl.java
.../main/java/cn/keking/service/impl/PdfFilePreviewImpl.java
+13
-12
PictureFilePreviewImpl.java
...n/java/cn/keking/service/impl/PictureFilePreviewImpl.java
+8
-5
CadUtils.java
jodconverter-web/src/main/java/cn/keking/utils/CadUtils.java
+2
-2
FileController.java
...rc/main/java/cn/keking/web/controller/FileController.java
+1
-1
No files found.
jodconverter-web/src/main/java/cn/keking/config/ConfigConstants.java
View file @
1edf4d83
...
@@ -45,7 +45,7 @@ public class ConfigConstants {
...
@@ -45,7 +45,7 @@ public class ConfigConstants {
}
}
@Value
(
"${cache.enabled:true}"
)
@Value
(
"${cache.enabled:true}"
)
public
static
void
setCacheEnabled
(
String
cacheEnabled
)
{
public
void
setCacheEnabled
(
String
cacheEnabled
)
{
setCacheEnabledValueValue
(
Boolean
.
parseBoolean
(
cacheEnabled
));
setCacheEnabledValueValue
(
Boolean
.
parseBoolean
(
cacheEnabled
));
}
}
...
...
jodconverter-web/src/main/java/cn/keking/service/FileConvertQueueTask.java
View file @
1edf4d83
...
@@ -42,7 +42,7 @@ public class FileConvertQueueTask {
...
@@ -42,7 +42,7 @@ public class FileConvertQueueTask {
logger
.
info
(
"队列处理文件转换任务启动完成 "
);
logger
.
info
(
"队列处理文件转换任务启动完成 "
);
}
}
class
ConvertTask
implements
Runnable
{
static
class
ConvertTask
implements
Runnable
{
private
final
Logger
logger
=
LoggerFactory
.
getLogger
(
ConvertTask
.
class
);
private
final
Logger
logger
=
LoggerFactory
.
getLogger
(
ConvertTask
.
class
);
...
...
jodconverter-web/src/main/java/cn/keking/service/cache/impl/CacheServiceRocksDBImpl.java
View file @
1edf4d83
...
@@ -99,6 +99,7 @@ public class CacheServiceRocksDBImpl implements CacheService {
...
@@ -99,6 +99,7 @@ public class CacheServiceRocksDBImpl implements CacheService {
}
}
@Override
@Override
@SuppressWarnings
(
"unchecked"
)
public
Map
<
String
,
String
>
getPDFCache
()
{
public
Map
<
String
,
String
>
getPDFCache
()
{
Map
<
String
,
String
>
result
=
new
HashMap
<>();
Map
<
String
,
String
>
result
=
new
HashMap
<>();
try
{
try
{
...
@@ -110,6 +111,7 @@ public class CacheServiceRocksDBImpl implements CacheService {
...
@@ -110,6 +111,7 @@ public class CacheServiceRocksDBImpl implements CacheService {
}
}
@Override
@Override
@SuppressWarnings
(
"unchecked"
)
public
String
getPDFCache
(
String
key
)
{
public
String
getPDFCache
(
String
key
)
{
String
result
=
""
;
String
result
=
""
;
try
{
try
{
...
@@ -122,6 +124,7 @@ public class CacheServiceRocksDBImpl implements CacheService {
...
@@ -122,6 +124,7 @@ public class CacheServiceRocksDBImpl implements CacheService {
}
}
@Override
@Override
@SuppressWarnings
(
"unchecked"
)
public
Map
<
String
,
List
<
String
>>
getImgCache
()
{
public
Map
<
String
,
List
<
String
>>
getImgCache
()
{
Map
<
String
,
List
<
String
>>
result
=
new
HashMap
<>();
Map
<
String
,
List
<
String
>>
result
=
new
HashMap
<>();
try
{
try
{
...
@@ -133,6 +136,7 @@ public class CacheServiceRocksDBImpl implements CacheService {
...
@@ -133,6 +136,7 @@ public class CacheServiceRocksDBImpl implements CacheService {
}
}
@Override
@Override
@SuppressWarnings
(
"unchecked"
)
public
List
<
String
>
getImgCache
(
String
key
)
{
public
List
<
String
>
getImgCache
(
String
key
)
{
List
<
String
>
result
=
new
ArrayList
<>();
List
<
String
>
result
=
new
ArrayList
<>();
Map
<
String
,
List
<
String
>>
map
;
Map
<
String
,
List
<
String
>>
map
;
...
@@ -145,17 +149,8 @@ public class CacheServiceRocksDBImpl implements CacheService {
...
@@ -145,17 +149,8 @@ public class CacheServiceRocksDBImpl implements CacheService {
return
result
;
return
result
;
}
}
public
Map
<
String
,
Integer
>
getPdfImageCaches
()
{
Map
<
String
,
Integer
>
map
=
new
HashMap
<>();
try
{
map
=
(
Map
<
String
,
Integer
>)
toObject
(
db
.
get
(
FILE_PREVIEW_PDF_IMGS_KEY
.
getBytes
()));
}
catch
(
RocksDBException
|
IOException
|
ClassNotFoundException
e
)
{
LOGGER
.
error
(
"Get from RocksDB Exception"
+
e
);
}
return
map
;
}
@Override
@Override
@SuppressWarnings
(
"unchecked"
)
public
Integer
getPdfImageCache
(
String
key
)
{
public
Integer
getPdfImageCache
(
String
key
)
{
Integer
result
=
0
;
Integer
result
=
0
;
Map
<
String
,
Integer
>
map
;
Map
<
String
,
Integer
>
map
;
...
@@ -200,6 +195,18 @@ public class CacheServiceRocksDBImpl implements CacheService {
...
@@ -200,6 +195,18 @@ public class CacheServiceRocksDBImpl implements CacheService {
return
blockingQueue
.
take
();
return
blockingQueue
.
take
();
}
}
@SuppressWarnings
(
"unchecked"
)
private
Map
<
String
,
Integer
>
getPdfImageCaches
()
{
Map
<
String
,
Integer
>
map
=
new
HashMap
<>();
try
{
map
=
(
Map
<
String
,
Integer
>)
toObject
(
db
.
get
(
FILE_PREVIEW_PDF_IMGS_KEY
.
getBytes
()));
}
catch
(
RocksDBException
|
IOException
|
ClassNotFoundException
e
)
{
LOGGER
.
error
(
"Get from RocksDB Exception"
+
e
);
}
return
map
;
}
private
byte
[]
toByteArray
(
Object
obj
)
throws
IOException
{
private
byte
[]
toByteArray
(
Object
obj
)
throws
IOException
{
byte
[]
bytes
;
byte
[]
bytes
;
ByteArrayOutputStream
bos
=
new
ByteArrayOutputStream
();
ByteArrayOutputStream
bos
=
new
ByteArrayOutputStream
();
...
...
jodconverter-web/src/main/java/cn/keking/service/impl/CadFilePreviewImpl.java
View file @
1edf4d83
...
@@ -4,12 +4,11 @@ import cn.keking.config.ConfigConstants;
...
@@ -4,12 +4,11 @@ import cn.keking.config.ConfigConstants;
import
cn.keking.model.FileAttribute
;
import
cn.keking.model.FileAttribute
;
import
cn.keking.model.ReturnResponse
;
import
cn.keking.model.ReturnResponse
;
import
cn.keking.service.FilePreview
;
import
cn.keking.service.FilePreview
;
import
cn.keking.utils.Cad
ToPdf
;
import
cn.keking.utils.Cad
Utils
;
import
cn.keking.utils.DownloadUtils
;
import
cn.keking.utils.DownloadUtils
;
import
cn.keking.utils.FileUtils
;
import
cn.keking.utils.FileUtils
;
import
cn.keking.utils.PdfUtils
;
import
cn.keking.utils.PdfUtils
;
import
cn.keking.web.filter.BaseUrlFilter
;
import
cn.keking.web.filter.BaseUrlFilter
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.ui.Model
;
import
org.springframework.ui.Model
;
import
org.springframework.util.StringUtils
;
import
org.springframework.util.StringUtils
;
...
@@ -23,23 +22,29 @@ import static cn.keking.service.impl.OfficeFilePreviewImpl.getPreviewType;
...
@@ -23,23 +22,29 @@ import static cn.keking.service.impl.OfficeFilePreviewImpl.getPreviewType;
@Service
@Service
public
class
CadFilePreviewImpl
implements
FilePreview
{
public
class
CadFilePreviewImpl
implements
FilePreview
{
private
String
fileDir
=
ConfigConstants
.
getFileDir
()
;
private
final
FileUtils
fileUtils
;
@Autowired
private
final
DownloadUtils
downloadUtils
;
private
FileUtils
fileUtils
;
@Autowired
private
final
CadUtils
cadUtils
;
private
DownloadUtils
downloadUtils
;
@Autowired
private
final
PdfUtils
pdfUtils
;
private
CadToPdf
cadToPdf
;
@Autowired
public
CadFilePreviewImpl
(
FileUtils
fileUtils
,
private
PdfUtils
pdfUtils
;
DownloadUtils
downloadUtils
,
CadUtils
cadUtils
,
PdfUtils
pdfUtils
)
{
this
.
fileUtils
=
fileUtils
;
this
.
downloadUtils
=
downloadUtils
;
this
.
cadUtils
=
cadUtils
;
this
.
pdfUtils
=
pdfUtils
;
}
private
static
final
String
OFFICE_PREVIEW_TYPE_IMAGE
=
"image"
;
private
static
final
String
OFFICE_PREVIEW_TYPE_ALL_IMAGES
=
"allImages"
;
private
static
final
String
FILE_DIR
=
ConfigConstants
.
getFileDir
();
public
static
final
String
OFFICE_PREVIEW_TYPE_PDF
=
"pdf"
;
public
static
final
String
OFFICE_PREVIEW_TYPE_IMAGE
=
"image"
;
public
static
final
String
OFFICE_PREVIEW_TYPE_ALLIMAGES
=
"allImages"
;
@Override
@Override
public
String
filePreviewHandle
(
String
url
,
Model
model
,
FileAttribute
fileAttribute
)
{
public
String
filePreviewHandle
(
String
url
,
Model
model
,
FileAttribute
fileAttribute
)
{
...
@@ -49,7 +54,7 @@ public class CadFilePreviewImpl implements FilePreview {
...
@@ -49,7 +54,7 @@ public class CadFilePreviewImpl implements FilePreview {
String
suffix
=
fileAttribute
.
getSuffix
();
String
suffix
=
fileAttribute
.
getSuffix
();
String
fileName
=
fileAttribute
.
getName
();
String
fileName
=
fileAttribute
.
getName
();
String
pdfName
=
fileName
.
substring
(
0
,
fileName
.
lastIndexOf
(
"."
)
+
1
)
+
"pdf"
;
String
pdfName
=
fileName
.
substring
(
0
,
fileName
.
lastIndexOf
(
"."
)
+
1
)
+
"pdf"
;
String
outFilePath
=
fileDir
+
pdfName
;
String
outFilePath
=
FILE_DIR
+
pdfName
;
// 判断之前是否已转换过,如果转换过,直接返回,否则执行转换
// 判断之前是否已转换过,如果转换过,直接返回,否则执行转换
if
(!
fileUtils
.
listConvertedFiles
().
containsKey
(
pdfName
)
||
!
ConfigConstants
.
isCacheEnabled
())
{
if
(!
fileUtils
.
listConvertedFiles
().
containsKey
(
pdfName
)
||
!
ConfigConstants
.
isCacheEnabled
())
{
String
filePath
;
String
filePath
;
...
@@ -61,7 +66,7 @@ public class CadFilePreviewImpl implements FilePreview {
...
@@ -61,7 +66,7 @@ public class CadFilePreviewImpl implements FilePreview {
}
}
filePath
=
response
.
getContent
();
filePath
=
response
.
getContent
();
if
(
StringUtils
.
hasText
(
outFilePath
))
{
if
(
StringUtils
.
hasText
(
outFilePath
))
{
boolean
convertResult
=
cad
ToPdf
.
cadToPdf
(
filePath
,
outFilePath
);
boolean
convertResult
=
cad
Utils
.
cadToPdf
(
filePath
,
outFilePath
);
if
(!
convertResult
)
{
if
(!
convertResult
)
{
model
.
addAttribute
(
"fileType"
,
suffix
);
model
.
addAttribute
(
"fileType"
,
suffix
);
model
.
addAttribute
(
"msg"
,
"cad文件转换异常,请联系管理员"
);
model
.
addAttribute
(
"msg"
,
"cad文件转换异常,请联系管理员"
);
...
@@ -73,7 +78,7 @@ public class CadFilePreviewImpl implements FilePreview {
...
@@ -73,7 +78,7 @@ public class CadFilePreviewImpl implements FilePreview {
}
}
}
}
}
}
if
(
baseUrl
!=
null
&&
(
OFFICE_PREVIEW_TYPE_IMAGE
.
equals
(
officePreviewType
)
||
OFFICE_PREVIEW_TYPE_ALLIMAGES
.
equals
(
officePreviewType
)))
{
if
(
baseUrl
!=
null
&&
(
OFFICE_PREVIEW_TYPE_IMAGE
.
equals
(
officePreviewType
)
||
OFFICE_PREVIEW_TYPE_ALL
_
IMAGES
.
equals
(
officePreviewType
)))
{
return
getPreviewType
(
model
,
fileAttribute
,
officePreviewType
,
baseUrl
,
pdfName
,
outFilePath
,
pdfUtils
,
OFFICE_PREVIEW_TYPE_IMAGE
);
return
getPreviewType
(
model
,
fileAttribute
,
officePreviewType
,
baseUrl
,
pdfName
,
outFilePath
,
pdfUtils
,
OFFICE_PREVIEW_TYPE_IMAGE
);
}
}
model
.
addAttribute
(
"pdfUrl"
,
pdfName
);
model
.
addAttribute
(
"pdfUrl"
,
pdfName
);
...
...
jodconverter-web/src/main/java/cn/keking/service/impl/CompressFilePreviewImpl.java
View file @
1edf4d83
...
@@ -7,7 +7,6 @@ import cn.keking.service.FilePreview;
...
@@ -7,7 +7,6 @@ import cn.keking.service.FilePreview;
import
cn.keking.utils.DownloadUtils
;
import
cn.keking.utils.DownloadUtils
;
import
cn.keking.utils.FileUtils
;
import
cn.keking.utils.FileUtils
;
import
cn.keking.utils.ZipReader
;
import
cn.keking.utils.ZipReader
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.ui.Model
;
import
org.springframework.ui.Model
;
import
org.springframework.util.StringUtils
;
import
org.springframework.util.StringUtils
;
...
@@ -17,16 +16,21 @@ import org.springframework.util.StringUtils;
...
@@ -17,16 +16,21 @@ import org.springframework.util.StringUtils;
* Content :处理压缩包文件
* Content :处理压缩包文件
*/
*/
@Service
@Service
public
class
CompressFilePreviewImpl
implements
FilePreview
{
public
class
CompressFilePreviewImpl
implements
FilePreview
{
@Autowired
private
final
FileUtils
fileUtils
;
FileUtils
fileUtils
;
@Autowired
private
final
DownloadUtils
downloadUtils
;
DownloadUtils
downloadUtils
;
@Autowired
private
final
ZipReader
zipReader
;
ZipReader
zipReader
;
public
CompressFilePreviewImpl
(
FileUtils
fileUtils
,
DownloadUtils
downloadUtils
,
ZipReader
zipReader
)
{
this
.
fileUtils
=
fileUtils
;
this
.
downloadUtils
=
downloadUtils
;
this
.
zipReader
=
zipReader
;
}
@Override
@Override
public
String
filePreviewHandle
(
String
url
,
Model
model
,
FileAttribute
fileAttribute
)
{
public
String
filePreviewHandle
(
String
url
,
Model
model
,
FileAttribute
fileAttribute
)
{
...
...
jodconverter-web/src/main/java/cn/keking/service/impl/MediaFilePreviewImpl.java
View file @
1edf4d83
...
@@ -2,8 +2,6 @@ package cn.keking.service.impl;
...
@@ -2,8 +2,6 @@ package cn.keking.service.impl;
import
cn.keking.model.FileAttribute
;
import
cn.keking.model.FileAttribute
;
import
cn.keking.service.FilePreview
;
import
cn.keking.service.FilePreview
;
import
cn.keking.utils.FileUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.ui.Model
;
import
org.springframework.ui.Model
;
/**
/**
...
@@ -15,9 +13,6 @@ import org.springframework.ui.Model;
...
@@ -15,9 +13,6 @@ import org.springframework.ui.Model;
@Service
@Service
public
class
MediaFilePreviewImpl
implements
FilePreview
{
public
class
MediaFilePreviewImpl
implements
FilePreview
{
@Autowired
FileUtils
fileUtils
;
@Override
@Override
public
String
filePreviewHandle
(
String
url
,
Model
model
,
FileAttribute
fileAttribute
)
{
public
String
filePreviewHandle
(
String
url
,
Model
model
,
FileAttribute
fileAttribute
)
{
model
.
addAttribute
(
"mediaUrl"
,
url
);
model
.
addAttribute
(
"mediaUrl"
,
url
);
...
...
jodconverter-web/src/main/java/cn/keking/service/impl/OfficeFilePreviewImpl.java
View file @
1edf4d83
...
@@ -9,7 +9,6 @@ import cn.keking.utils.FileUtils;
...
@@ -9,7 +9,6 @@ import cn.keking.utils.FileUtils;
import
cn.keking.utils.OfficeToPdf
;
import
cn.keking.utils.OfficeToPdf
;
import
cn.keking.utils.PdfUtils
;
import
cn.keking.utils.PdfUtils
;
import
cn.keking.web.filter.BaseUrlFilter
;
import
cn.keking.web.filter.BaseUrlFilter
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.ui.Model
;
import
org.springframework.ui.Model
;
import
org.springframework.util.StringUtils
;
import
org.springframework.util.StringUtils
;
...
@@ -23,23 +22,27 @@ import java.util.List;
...
@@ -23,23 +22,27 @@ import java.util.List;
@Service
@Service
public
class
OfficeFilePreviewImpl
implements
FilePreview
{
public
class
OfficeFilePreviewImpl
implements
FilePreview
{
@Autowired
private
final
FileUtils
fileUtils
;
FileUtils
fileUtils
;
@Autowired
private
final
PdfUtils
pdfUtils
;
PdfUtils
pdfUtils
;
@Autowired
private
final
DownloadUtils
downloadUtils
;
DownloadUtils
downloadUtils
;
@Autowired
private
final
OfficeToPdf
officeToPdf
;
private
OfficeToPdf
officeToPdf
;
String
fileDir
=
ConfigConstants
.
getFileDir
();
public
OfficeFilePreviewImpl
(
FileUtils
fileUtils
,
PdfUtils
pdfUtils
,
DownloadUtils
downloadUtils
,
OfficeToPdf
officeToPdf
)
{
this
.
fileUtils
=
fileUtils
;
this
.
pdfUtils
=
pdfUtils
;
this
.
downloadUtils
=
downloadUtils
;
this
.
officeToPdf
=
officeToPdf
;
}
public
static
final
String
OFFICE_PREVIEW_TYPE_PDF
=
"pdf"
;
public
static
final
String
OFFICE_PREVIEW_TYPE_IMAGE
=
"image"
;
public
static
final
String
OFFICE_PREVIEW_TYPE_IMAGE
=
"image"
;
public
static
final
String
OFFICE_PREVIEW_TYPE_ALLIMAGES
=
"allImages"
;
public
static
final
String
OFFICE_PREVIEW_TYPE_ALL_IMAGES
=
"allImages"
;
private
static
final
String
FILE_DIR
=
ConfigConstants
.
getFileDir
();
@Override
@Override
public
String
filePreviewHandle
(
String
url
,
Model
model
,
FileAttribute
fileAttribute
)
{
public
String
filePreviewHandle
(
String
url
,
Model
model
,
FileAttribute
fileAttribute
)
{
...
@@ -50,10 +53,10 @@ public class OfficeFilePreviewImpl implements FilePreview {
...
@@ -50,10 +53,10 @@ public class OfficeFilePreviewImpl implements FilePreview {
String
fileName
=
fileAttribute
.
getName
();
String
fileName
=
fileAttribute
.
getName
();
boolean
isHtml
=
suffix
.
equalsIgnoreCase
(
"xls"
)
||
suffix
.
equalsIgnoreCase
(
"xlsx"
);
boolean
isHtml
=
suffix
.
equalsIgnoreCase
(
"xls"
)
||
suffix
.
equalsIgnoreCase
(
"xlsx"
);
String
pdfName
=
fileName
.
substring
(
0
,
fileName
.
lastIndexOf
(
"."
)
+
1
)
+
(
isHtml
?
"html"
:
"pdf"
);
String
pdfName
=
fileName
.
substring
(
0
,
fileName
.
lastIndexOf
(
"."
)
+
1
)
+
(
isHtml
?
"html"
:
"pdf"
);
String
outFilePath
=
fileDir
+
pdfName
;
String
outFilePath
=
FILE_DIR
+
pdfName
;
// 判断之前是否已转换过,如果转换过,直接返回,否则执行转换
// 判断之前是否已转换过,如果转换过,直接返回,否则执行转换
if
(!
fileUtils
.
listConvertedFiles
().
containsKey
(
pdfName
)
||
!
ConfigConstants
.
isCacheEnabled
())
{
if
(!
fileUtils
.
listConvertedFiles
().
containsKey
(
pdfName
)
||
!
ConfigConstants
.
isCacheEnabled
())
{
String
filePath
=
fileDir
+
fileName
;
String
filePath
;
ReturnResponse
<
String
>
response
=
downloadUtils
.
downLoad
(
fileAttribute
,
null
);
ReturnResponse
<
String
>
response
=
downloadUtils
.
downLoad
(
fileAttribute
,
null
);
if
(
0
!=
response
.
getCode
())
{
if
(
0
!=
response
.
getCode
())
{
model
.
addAttribute
(
"fileType"
,
suffix
);
model
.
addAttribute
(
"fileType"
,
suffix
);
...
@@ -73,7 +76,7 @@ public class OfficeFilePreviewImpl implements FilePreview {
...
@@ -73,7 +76,7 @@ public class OfficeFilePreviewImpl implements FilePreview {
}
}
}
}
}
}
if
(!
isHtml
&&
baseUrl
!=
null
&&
(
OFFICE_PREVIEW_TYPE_IMAGE
.
equals
(
officePreviewType
)
||
OFFICE_PREVIEW_TYPE_ALLIMAGES
.
equals
(
officePreviewType
)))
{
if
(!
isHtml
&&
baseUrl
!=
null
&&
(
OFFICE_PREVIEW_TYPE_IMAGE
.
equals
(
officePreviewType
)
||
OFFICE_PREVIEW_TYPE_ALL
_
IMAGES
.
equals
(
officePreviewType
)))
{
return
getPreviewType
(
model
,
fileAttribute
,
officePreviewType
,
baseUrl
,
pdfName
,
outFilePath
,
pdfUtils
,
OFFICE_PREVIEW_TYPE_IMAGE
);
return
getPreviewType
(
model
,
fileAttribute
,
officePreviewType
,
baseUrl
,
pdfName
,
outFilePath
,
pdfUtils
,
OFFICE_PREVIEW_TYPE_IMAGE
);
}
}
model
.
addAttribute
(
"pdfUrl"
,
pdfName
);
model
.
addAttribute
(
"pdfUrl"
,
pdfName
);
...
...
jodconverter-web/src/main/java/cn/keking/service/impl/OtherFilePreviewImpl.java
View file @
1edf4d83
...
@@ -2,8 +2,6 @@ package cn.keking.service.impl;
...
@@ -2,8 +2,6 @@ package cn.keking.service.impl;
import
cn.keking.model.FileAttribute
;
import
cn.keking.model.FileAttribute
;
import
cn.keking.service.FilePreview
;
import
cn.keking.service.FilePreview
;
import
cn.keking.utils.FileUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.ui.Model
;
import
org.springframework.ui.Model
;
...
@@ -13,9 +11,6 @@ import org.springframework.ui.Model;
...
@@ -13,9 +11,6 @@ import org.springframework.ui.Model;
*/
*/
@Service
@Service
public
class
OtherFilePreviewImpl
implements
FilePreview
{
public
class
OtherFilePreviewImpl
implements
FilePreview
{
@Autowired
FileUtils
fileUtils
;
@Override
@Override
public
String
filePreviewHandle
(
String
url
,
Model
model
,
FileAttribute
fileAttribute
)
{
public
String
filePreviewHandle
(
String
url
,
Model
model
,
FileAttribute
fileAttribute
)
{
model
.
addAttribute
(
"fileType"
,
fileAttribute
.
getSuffix
());
model
.
addAttribute
(
"fileType"
,
fileAttribute
.
getSuffix
());
...
...
jodconverter-web/src/main/java/cn/keking/service/impl/PdfFilePreviewImpl.java
View file @
1edf4d83
...
@@ -8,7 +8,6 @@ import cn.keking.utils.DownloadUtils;
...
@@ -8,7 +8,6 @@ import cn.keking.utils.DownloadUtils;
import
cn.keking.utils.FileUtils
;
import
cn.keking.utils.FileUtils
;
import
cn.keking.utils.PdfUtils
;
import
cn.keking.utils.PdfUtils
;
import
cn.keking.web.filter.BaseUrlFilter
;
import
cn.keking.web.filter.BaseUrlFilter
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.ui.Model
;
import
org.springframework.ui.Model
;
...
@@ -19,19 +18,21 @@ import java.util.List;
...
@@ -19,19 +18,21 @@ import java.util.List;
* Content :处理pdf文件
* Content :处理pdf文件
*/
*/
@Service
@Service
public
class
PdfFilePreviewImpl
implements
FilePreview
{
public
class
PdfFilePreviewImpl
implements
FilePreview
{
private
final
FileUtils
fileUtils
;
@Autowired
private
final
PdfUtils
pdfUtils
;
FileUtils
fileUtils
;
@Autowired
private
final
DownloadUtils
downloadUtils
;
PdfUtils
pdfUtils
;
@Autowired
public
PdfFilePreviewImpl
(
FileUtils
fileUtils
,
DownloadUtils
downloadUtils
;
PdfUtils
pdfUtils
,
DownloadUtils
downloadUtils
)
{
String
fileDir
=
ConfigConstants
.
getFileDir
();
this
.
fileUtils
=
fileUtils
;
this
.
pdfUtils
=
pdfUtils
;
this
.
downloadUtils
=
downloadUtils
;
}
@Override
@Override
public
String
filePreviewHandle
(
String
url
,
Model
model
,
FileAttribute
fileAttribute
)
{
public
String
filePreviewHandle
(
String
url
,
Model
model
,
FileAttribute
fileAttribute
)
{
...
@@ -40,8 +41,8 @@ public class PdfFilePreviewImpl implements FilePreview{
...
@@ -40,8 +41,8 @@ public class PdfFilePreviewImpl implements FilePreview{
String
officePreviewType
=
model
.
asMap
().
get
(
"officePreviewType"
)
==
null
?
ConfigConstants
.
getOfficePreviewType
()
:
model
.
asMap
().
get
(
"officePreviewType"
).
toString
();
String
officePreviewType
=
model
.
asMap
().
get
(
"officePreviewType"
)
==
null
?
ConfigConstants
.
getOfficePreviewType
()
:
model
.
asMap
().
get
(
"officePreviewType"
).
toString
();
String
baseUrl
=
BaseUrlFilter
.
getBaseUrl
();
String
baseUrl
=
BaseUrlFilter
.
getBaseUrl
();
String
pdfName
=
fileName
.
substring
(
0
,
fileName
.
lastIndexOf
(
"."
)
+
1
)
+
"pdf"
;
String
pdfName
=
fileName
.
substring
(
0
,
fileName
.
lastIndexOf
(
"."
)
+
1
)
+
"pdf"
;
String
outFilePath
=
fileDir
+
pdfName
;
String
outFilePath
;
if
(
OfficeFilePreviewImpl
.
OFFICE_PREVIEW_TYPE_IMAGE
.
equals
(
officePreviewType
)
||
OfficeFilePreviewImpl
.
OFFICE_PREVIEW_TYPE_ALLIMAGES
.
equals
(
officePreviewType
))
{
if
(
OfficeFilePreviewImpl
.
OFFICE_PREVIEW_TYPE_IMAGE
.
equals
(
officePreviewType
)
||
OfficeFilePreviewImpl
.
OFFICE_PREVIEW_TYPE_ALL
_
IMAGES
.
equals
(
officePreviewType
))
{
//当文件不存在时,就去下载
//当文件不存在时,就去下载
ReturnResponse
<
String
>
response
=
downloadUtils
.
downLoad
(
fileAttribute
,
fileName
);
ReturnResponse
<
String
>
response
=
downloadUtils
.
downLoad
(
fileAttribute
,
fileName
);
if
(
0
!=
response
.
getCode
())
{
if
(
0
!=
response
.
getCode
())
{
...
...
jodconverter-web/src/main/java/cn/keking/service/impl/PictureFilePreviewImpl.java
View file @
1edf4d83
...
@@ -6,7 +6,6 @@ import cn.keking.service.FilePreview;
...
@@ -6,7 +6,6 @@ import cn.keking.service.FilePreview;
import
cn.keking.utils.DownloadUtils
;
import
cn.keking.utils.DownloadUtils
;
import
cn.keking.utils.FileUtils
;
import
cn.keking.utils.FileUtils
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Lists
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.ui.Model
;
import
org.springframework.ui.Model
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
org.springframework.web.context.request.RequestContextHolder
;
...
@@ -20,11 +19,15 @@ import java.util.List;
...
@@ -20,11 +19,15 @@ import java.util.List;
@Service
@Service
public
class
PictureFilePreviewImpl
implements
FilePreview
{
public
class
PictureFilePreviewImpl
implements
FilePreview
{
@Autowired
private
final
FileUtils
fileUtils
;
FileUtils
fileUtils
;
@Autowired
private
final
DownloadUtils
downloadUtils
;
DownloadUtils
downloadUtils
;
public
PictureFilePreviewImpl
(
FileUtils
fileUtils
,
DownloadUtils
downloadUtils
)
{
this
.
fileUtils
=
fileUtils
;
this
.
downloadUtils
=
downloadUtils
;
}
@Override
@Override
public
String
filePreviewHandle
(
String
url
,
Model
model
,
FileAttribute
fileAttribute
)
{
public
String
filePreviewHandle
(
String
url
,
Model
model
,
FileAttribute
fileAttribute
)
{
...
...
jodconverter-web/src/main/java/cn/keking/utils/Cad
ToPdf
.java
→
jodconverter-web/src/main/java/cn/keking/utils/Cad
Utils
.java
View file @
1edf4d83
...
@@ -18,9 +18,9 @@ import java.io.OutputStream;
...
@@ -18,9 +18,9 @@ import java.io.OutputStream;
* @since 2019/11/21 14:34
* @since 2019/11/21 14:34
*/
*/
@Component
@Component
public
class
Cad
ToPdf
{
public
class
Cad
Utils
{
private
final
Logger
logger
=
LoggerFactory
.
getLogger
(
Cad
ToPdf
.
class
);
private
final
Logger
logger
=
LoggerFactory
.
getLogger
(
Cad
Utils
.
class
);
public
boolean
cadToPdf
(
String
inputFilePath
,
String
outputFilePath
)
{
public
boolean
cadToPdf
(
String
inputFilePath
,
String
outputFilePath
)
{
com
.
aspose
.
cad
.
Image
cadImage
=
com
.
aspose
.
cad
.
Image
.
load
(
inputFilePath
);
com
.
aspose
.
cad
.
Image
cadImage
=
com
.
aspose
.
cad
.
Image
.
load
(
inputFilePath
);
...
...
jodconverter-web/src/main/java/cn/keking/web/controller/FileController.java
View file @
1edf4d83
...
@@ -59,7 +59,7 @@ public class FileController {
...
@@ -59,7 +59,7 @@ public class FileController {
if
(!
outFile
.
exists
())
{
if
(!
outFile
.
exists
())
{
outFile
.
mkdirs
();
outFile
.
mkdirs
();
}
}
logger
.
info
(
"上传文件:{}"
,
outFile
.
getAbsolutePath
()
);
logger
.
info
(
"上传文件:{}"
,
fileDir
+
demoPath
+
fileName
);
try
(
InputStream
in
=
file
.
getInputStream
();
OutputStream
out
=
new
FileOutputStream
(
fileDir
+
demoPath
+
fileName
))
{
try
(
InputStream
in
=
file
.
getInputStream
();
OutputStream
out
=
new
FileOutputStream
(
fileDir
+
demoPath
+
fileName
))
{
StreamUtils
.
copy
(
in
,
out
);
StreamUtils
.
copy
(
in
,
out
);
return
new
ObjectMapper
().
writeValueAsString
(
new
ReturnResponse
<
String
>(
0
,
"SUCCESS"
,
null
));
return
new
ObjectMapper
().
writeValueAsString
(
new
ReturnResponse
<
String
>(
0
,
"SUCCESS"
,
null
));
...
...
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