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
梁杰芳
slm-fileview
Commits
1f197023
Commit
1f197023
authored
Dec 27, 2020
by
chenkailing
Committed by
kl
Dec 27, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
精简util模块,ReturenResponse重构
parent
594bd895
Show whitespace changes
Inline
Side-by-side
Showing
24 changed files
with
248 additions
and
259 deletions
+248
-259
ConfigRefreshComponent.java
...rc/main/java/cn/keking/config/ConfigRefreshComponent.java
+3
-4
SchedulerCleanConfig.java
.../src/main/java/cn/keking/config/SchedulerCleanConfig.java
+5
-5
FileType.java
server/src/main/java/cn/keking/model/FileType.java
+17
-1
ReturnResponse.java
server/src/main/java/cn/keking/model/ReturnResponse.java
+32
-1
CompressFileReader.java
...r/src/main/java/cn/keking/service/CompressFileReader.java
+3
-3
FileConvertQueueTask.java
...src/main/java/cn/keking/service/FileConvertQueueTask.java
+2
-1
FileHandlerService.java
...r/src/main/java/cn/keking/service/FileHandlerService.java
+103
-44
OfficePluginExtendFormatRegistry.java
...a/cn/keking/service/OfficePluginExtendFormatRegistry.java
+3
-3
OfficePluginManager.java
.../src/main/java/cn/keking/service/OfficePluginManager.java
+1
-2
OfficeToPdfService.java
...r/src/main/java/cn/keking/service/OfficeToPdfService.java
+7
-4
CacheServiceRedisImpl.java
...a/cn/keking/service/cache/impl/CacheServiceRedisImpl.java
+3
-11
CacheServiceRocksDBImpl.java
...cn/keking/service/cache/impl/CacheServiceRocksDBImpl.java
+0
-3
CadFilePreviewImpl.java
.../main/java/cn/keking/service/impl/CadFilePreviewImpl.java
+10
-18
CompressFilePreviewImpl.java
.../java/cn/keking/service/impl/CompressFilePreviewImpl.java
+1
-1
MediaFilePreviewImpl.java
...ain/java/cn/keking/service/impl/MediaFilePreviewImpl.java
+3
-2
OfficeFilePreviewImpl.java
...in/java/cn/keking/service/impl/OfficeFilePreviewImpl.java
+9
-12
PdfFilePreviewImpl.java
.../main/java/cn/keking/service/impl/PdfFilePreviewImpl.java
+4
-7
PictureFilePreviewImpl.java
...n/java/cn/keking/service/impl/PictureFilePreviewImpl.java
+1
-1
SimTextFilePreviewImpl.java
...n/java/cn/keking/service/impl/SimTextFilePreviewImpl.java
+1
-1
CadUtils.java
server/src/main/java/cn/keking/utils/CadUtils.java
+0
-50
FileUtils.java
server/src/main/java/cn/keking/utils/FileUtils.java
+10
-0
PdfUtils.java
server/src/main/java/cn/keking/utils/PdfUtils.java
+0
-79
WebUtils.java
server/src/main/java/cn/keking/utils/WebUtils.java
+26
-0
FileController.java
...rc/main/java/cn/keking/web/controller/FileController.java
+4
-6
No files found.
server/src/main/java/cn/keking/
service
/ConfigRefreshComponent.java
→
server/src/main/java/cn/keking/
config
/ConfigRefreshComponent.java
View file @
1f197023
package
cn
.
keking
.
service
;
package
cn
.
keking
.
config
;
import
cn.keking.config.ConfigConstants
;
import
cn.keking.config.WatermarkConfigConstants
;
import
org.artofsolving.jodconverter.office.OfficeUtils
;
import
org.artofsolving.jodconverter.office.OfficeUtils
;
import
org.artofsolving.jodconverter.util.ConfigUtils
;
import
org.artofsolving.jodconverter.util.ConfigUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
...
@@ -13,6 +11,7 @@ import java.io.BufferedReader;
...
@@ -13,6 +11,7 @@ import java.io.BufferedReader;
import
java.io.FileReader
;
import
java.io.FileReader
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.util.Properties
;
import
java.util.Properties
;
import
java.util.concurrent.TimeUnit
;
/**
/**
* @auther: chenjh
* @auther: chenjh
...
@@ -81,7 +80,7 @@ public class ConfigRefreshComponent {
...
@@ -81,7 +80,7 @@ public class ConfigRefreshComponent {
setWatermarkConfig
(
properties
);
setWatermarkConfig
(
properties
);
bufferedReader
.
close
();
bufferedReader
.
close
();
fileReader
.
close
();
fileReader
.
close
();
T
hread
.
sleep
(
1000L
);
T
imeUnit
.
SECONDS
.
sleep
(
1
);
}
}
}
catch
(
IOException
|
InterruptedException
e
)
{
}
catch
(
IOException
|
InterruptedException
e
)
{
LOGGER
.
error
(
"读取配置文件异常"
,
e
);
LOGGER
.
error
(
"读取配置文件异常"
,
e
);
...
...
server/src/main/java/cn/keking/
utils/ShedulerClean
.java
→
server/src/main/java/cn/keking/
config/SchedulerCleanConfig
.java
View file @
1f197023
package
cn
.
keking
.
utils
;
package
cn
.
keking
.
config
;
import
cn.keking.config.ConfigConstants
;
import
cn.keking.service.cache.CacheService
;
import
cn.keking.service.cache.CacheService
;
import
cn.keking.utils.FileUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnExpression
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnExpression
;
...
@@ -14,13 +14,13 @@ import org.springframework.stereotype.Component;
...
@@ -14,13 +14,13 @@ import org.springframework.stereotype.Component;
*/
*/
@Component
@Component
@ConditionalOnExpression
(
"'${cache.clean.enabled:false}'.equals('true')"
)
@ConditionalOnExpression
(
"'${cache.clean.enabled:false}'.equals('true')"
)
public
class
S
hedulerClean
{
public
class
S
chedulerCleanConfig
{
private
final
Logger
logger
=
LoggerFactory
.
getLogger
(
S
hedulerClean
.
class
);
private
final
Logger
logger
=
LoggerFactory
.
getLogger
(
S
chedulerCleanConfig
.
class
);
private
final
CacheService
cacheService
;
private
final
CacheService
cacheService
;
public
S
hedulerClean
(
CacheService
cacheService
)
{
public
S
chedulerCleanConfig
(
CacheService
cacheService
)
{
this
.
cacheService
=
cacheService
;
this
.
cacheService
=
cacheService
;
}
}
...
...
server/src/main/java/cn/keking/model/FileType.java
View file @
1f197023
...
@@ -50,9 +50,25 @@ public enum FileType {
...
@@ -50,9 +50,25 @@ public enum FileType {
FILE_TYPE_MAPPER
.
put
(
"dwg"
,
FileType
.
cad
);
FILE_TYPE_MAPPER
.
put
(
"dwg"
,
FileType
.
cad
);
}
}
p
ublic
static
FileType
to
(
String
fileType
){
p
rivate
static
FileType
to
(
String
fileType
){
return
FILE_TYPE_MAPPER
.
getOrDefault
(
fileType
,
other
);
return
FILE_TYPE_MAPPER
.
getOrDefault
(
fileType
,
other
);
}
}
/**
* 查看文件类型(防止参数中存在.点号或者其他特殊字符,所以先抽取文件名,然后再获取文件类型)
*
* @param url url
* @return 文件类型
*/
public
static
FileType
typeFromUrl
(
String
url
)
{
String
nonPramStr
=
url
.
substring
(
0
,
url
.
contains
(
"?"
)
?
url
.
indexOf
(
"?"
)
:
url
.
length
());
String
fileName
=
nonPramStr
.
substring
(
nonPramStr
.
lastIndexOf
(
"/"
)
+
1
);
return
typeFromFileName
(
fileName
);
}
public
static
FileType
typeFromFileName
(
String
fileName
)
{
String
fileType
=
fileName
.
substring
(
fileName
.
lastIndexOf
(
"."
)
+
1
);
return
FileType
.
to
(
fileType
);
}
private
final
String
instanceName
;
private
final
String
instanceName
;
...
...
server/src/main/java/cn/keking/model/ReturnResponse.java
View file @
1f197023
...
@@ -4,11 +4,18 @@ import java.io.Serializable;
...
@@ -4,11 +4,18 @@ import java.io.Serializable;
/**
/**
* 接口返回值结构
* 接口返回值结构
*
* @author yudian-it
* @author yudian-it
* @date 2017/11/17
* @date 2017/11/17
*/
*/
public
class
ReturnResponse
<
T
>
implements
Serializable
{
public
class
ReturnResponse
<
T
>
implements
Serializable
{
private
static
final
long
serialVersionUID
=
313975329998789878L
;
private
static
final
long
serialVersionUID
=
313975329998789878L
;
public
static
final
int
SUCCESS_CODE
=
0
;
public
static
final
int
FAILURE_CODE
=
1
;
public
static
final
String
SUCCESS_MSG
=
"SUCCESS"
;
public
static
final
String
FAILURE_MSG
=
"FAILURE"
;
/**
/**
* 返回状态
* 返回状态
* 0. 成功
* 0. 成功
...
@@ -31,6 +38,30 @@ public class ReturnResponse<T> implements Serializable{
...
@@ -31,6 +38,30 @@ public class ReturnResponse<T> implements Serializable{
this
.
content
=
content
;
this
.
content
=
content
;
}
}
public
static
ReturnResponse
<
Object
>
failure
(
String
errMsg
)
{
return
new
ReturnResponse
<>(
FAILURE_CODE
,
errMsg
,
null
);
}
public
static
ReturnResponse
<
Object
>
failure
()
{
return
failure
(
FAILURE_MSG
);
}
public
static
ReturnResponse
<
Object
>
success
(){
return
success
(
null
);
}
public
static
ReturnResponse
<
Object
>
success
(
Object
content
)
{
return
new
ReturnResponse
<>(
SUCCESS_CODE
,
SUCCESS_MSG
,
content
);
}
public
boolean
isSuccess
(){
return
SUCCESS_CODE
==
code
;
}
public
boolean
isFailure
(){
return
!
isSuccess
();
}
public
int
getCode
()
{
public
int
getCode
()
{
return
code
;
return
code
;
}
}
...
...
server/src/main/java/cn/keking/service/CompressFileReader.java
View file @
1f197023
...
@@ -67,7 +67,7 @@ public class CompressFileReader {
...
@@ -67,7 +67,7 @@ public class CompressFileReader {
}
}
String
parentName
=
getLast2FileName
(
fullName
,
archiveSeparator
,
archiveFileName
);
String
parentName
=
getLast2FileName
(
fullName
,
archiveSeparator
,
archiveFileName
);
parentName
=
(
level
-
1
)
+
"_"
+
parentName
;
parentName
=
(
level
-
1
)
+
"_"
+
parentName
;
FileType
type
=
fileHandlerServic
e
.
typeFromUrl
(
childName
);
FileType
type
=
FileTyp
e
.
typeFromUrl
(
childName
);
if
(
type
.
equals
(
FileType
.
picture
))
{
//添加图片文件到图片列表
if
(
type
.
equals
(
FileType
.
picture
))
{
//添加图片文件到图片列表
imgUrls
.
add
(
baseUrl
+
childName
);
imgUrls
.
add
(
baseUrl
+
childName
);
}
}
...
@@ -120,7 +120,7 @@ public class CompressFileReader {
...
@@ -120,7 +120,7 @@ public class CompressFileReader {
headersToBeExtracted
.
add
(
Collections
.
singletonMap
(
childName
,
header
));
headersToBeExtracted
.
add
(
Collections
.
singletonMap
(
childName
,
header
));
}
}
String
parentName
=
getLast2FileName
(
fullName
,
"\\"
,
archiveFileName
);
String
parentName
=
getLast2FileName
(
fullName
,
"\\"
,
archiveFileName
);
FileType
type
=
fileHandlerServic
e
.
typeFromUrl
(
childName
);
FileType
type
=
FileTyp
e
.
typeFromUrl
(
childName
);
if
(
type
.
equals
(
FileType
.
picture
))
{
//添加图片文件到图片列表
if
(
type
.
equals
(
FileType
.
picture
))
{
//添加图片文件到图片列表
imgUrls
.
add
(
baseUrl
+
childName
);
imgUrls
.
add
(
baseUrl
+
childName
);
}
}
...
@@ -163,7 +163,7 @@ public class CompressFileReader {
...
@@ -163,7 +163,7 @@ public class CompressFileReader {
}
}
String
parentName
=
getLast2FileName
(
fullName
,
archiveSeparator
,
archiveFileName
);
String
parentName
=
getLast2FileName
(
fullName
,
archiveSeparator
,
archiveFileName
);
parentName
=
(
level
-
1
)
+
"_"
+
parentName
;
parentName
=
(
level
-
1
)
+
"_"
+
parentName
;
FileType
type
=
fileHandlerServic
e
.
typeFromUrl
(
childName
);
FileType
type
=
FileTyp
e
.
typeFromUrl
(
childName
);
if
(
type
.
equals
(
FileType
.
picture
))
{
//添加图片文件到图片列表
if
(
type
.
equals
(
FileType
.
picture
))
{
//添加图片文件到图片列表
imgUrls
.
add
(
baseUrl
+
childName
);
imgUrls
.
add
(
baseUrl
+
childName
);
}
}
...
...
server/src/main/java/cn/keking/service/FileConvertQueueTask.java
View file @
1f197023
...
@@ -10,6 +10,7 @@ import org.springframework.ui.ExtendedModelMap;
...
@@ -10,6 +10,7 @@ import org.springframework.ui.ExtendedModelMap;
import
javax.annotation.PostConstruct
;
import
javax.annotation.PostConstruct
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.TimeUnit
;
/**
/**
* Created by kl on 2018/1/19.
* Created by kl on 2018/1/19.
...
@@ -70,7 +71,7 @@ public class FileConvertQueueTask {
...
@@ -70,7 +71,7 @@ public class FileConvertQueueTask {
}
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
try
{
try
{
T
hread
.
sleep
(
1000
*
10
);
T
imeUnit
.
SECONDS
.
sleep
(
10
);
}
catch
(
Exception
ex
){
}
catch
(
Exception
ex
){
ex
.
printStackTrace
();
ex
.
printStackTrace
();
}
}
...
...
server/src/main/java/cn/keking/service/FileHandlerService.java
View file @
1f197023
...
@@ -4,13 +4,28 @@ import cn.keking.config.ConfigConstants;
...
@@ -4,13 +4,28 @@ import cn.keking.config.ConfigConstants;
import
cn.keking.model.FileAttribute
;
import
cn.keking.model.FileAttribute
;
import
cn.keking.model.FileType
;
import
cn.keking.model.FileType
;
import
cn.keking.service.cache.CacheService
;
import
cn.keking.service.cache.CacheService
;
import
cn.keking.utils.FileUtils
;
import
cn.keking.utils.WebUtils
;
import
cn.keking.utils.WebUtils
;
import
com.aspose.cad.Color
;
import
com.aspose.cad.fileformats.cad.CadDrawTypeMode
;
import
com.aspose.cad.imageoptions.CadRasterizationOptions
;
import
com.aspose.cad.imageoptions.PdfOptions
;
import
org.apache.pdfbox.pdmodel.PDDocument
;
import
org.apache.pdfbox.rendering.ImageType
;
import
org.apache.pdfbox.rendering.PDFRenderer
;
import
org.apache.pdfbox.tools.imageio.ImageIOUtil
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
org.springframework.util.StringUtils
;
import
org.springframework.util.StringUtils
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
java.awt.image.BufferedImage
;
import
java.io.*
;
import
java.io.*
;
import
java.net.URLEncoder
;
import
java.nio.charset.StandardCharsets
;
import
java.nio.charset.StandardCharsets
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
...
@@ -21,10 +36,15 @@ import java.util.Map;
...
@@ -21,10 +36,15 @@ import java.util.Map;
@Component
@Component
public
class
FileHandlerService
{
public
class
FileHandlerService
{
private
final
Logger
logger
=
LoggerFactory
.
getLogger
(
FileHandlerService
.
class
);
private
static
final
String
DEFAULT_CONVERTER_CHARSET
=
System
.
getProperty
(
"sun.jnu.encoding"
);
private
static
final
String
DEFAULT_CONVERTER_CHARSET
=
System
.
getProperty
(
"sun.jnu.encoding"
);
private
final
String
fileDir
=
ConfigConstants
.
getFileDir
();
private
final
String
fileDir
=
ConfigConstants
.
getFileDir
();
private
final
CacheService
cacheService
;
private
final
CacheService
cacheService
;
@Value
(
"${server.tomcat.uri-encoding:UTF-8}"
)
private
String
uriEncoding
;
public
FileHandlerService
(
CacheService
cacheService
)
{
public
FileHandlerService
(
CacheService
cacheService
)
{
this
.
cacheService
=
cacheService
;
this
.
cacheService
=
cacheService
;
}
}
...
@@ -51,35 +71,6 @@ public class FileHandlerService {
...
@@ -51,35 +71,6 @@ public class FileHandlerService {
return
cacheService
.
getPdfImageCache
(
key
);
return
cacheService
.
getPdfImageCache
(
key
);
}
}
/**
* 查看文件类型(防止参数中存在.点号或者其他特殊字符,所以先抽取文件名,然后再获取文件类型)
*
* @param url url
* @return 文件类型
*/
public
FileType
typeFromUrl
(
String
url
)
{
String
nonPramStr
=
url
.
substring
(
0
,
url
.
contains
(
"?"
)
?
url
.
indexOf
(
"?"
)
:
url
.
length
());
String
fileName
=
nonPramStr
.
substring
(
nonPramStr
.
lastIndexOf
(
"/"
)
+
1
);
return
this
.
typeFromFileName
(
fileName
);
}
private
FileType
typeFromFileName
(
String
fileName
)
{
String
fileType
=
fileName
.
substring
(
fileName
.
lastIndexOf
(
"."
)
+
1
);
return
FileType
.
to
(
fileType
);
}
/**
* 从url中剥离出文件名
*
* @param url 格式如:http://www.com.cn/20171113164107_月度绩效表模板(新).xls?UCloudPublicKey=ucloudtangshd@weifenf.com14355492830001993909323&Expires=&Signature=I D1NOFtAJSPT16E6imv6JWuq0k=
* @return 文件名
*/
public
String
getFileNameFromURL
(
String
url
)
{
// 因为url的参数中可能会存在/的情况,所以直接url.lastIndexOf("/")会有问题
// 所以先从?处将url截断,然后运用url.lastIndexOf("/")获取文件名
String
noQueryUrl
=
url
.
substring
(
0
,
url
.
contains
(
"?"
)
?
url
.
indexOf
(
"?"
)
:
url
.
length
());
return
noQueryUrl
.
substring
(
noQueryUrl
.
lastIndexOf
(
"/"
)
+
1
);
}
/**
/**
* 从路径中获取文件负
* 从路径中获取文件负
...
@@ -174,19 +165,87 @@ public class FileHandlerService {
...
@@ -174,19 +165,87 @@ public class FileHandlerService {
}
}
/**
/**
* 获取文件后缀
* pdf文件转换成jpg图片集
*
* @param pdfFilePath pdf文件路径
* @param url url
* @param pdfName pdf文件名称
* @return 文件后缀
* @param baseUrl 基础访问地址
* @return 图片访问集合
*/
*/
private
String
suffixFromUrl
(
String
url
)
{
public
List
<
String
>
pdf2jpg
(
String
pdfFilePath
,
String
pdfName
,
String
baseUrl
)
{
String
nonPramStr
=
url
.
substring
(
0
,
url
.
contains
(
"?"
)
?
url
.
indexOf
(
"?"
)
:
url
.
length
());
List
<
String
>
imageUrls
=
new
ArrayList
<>();
String
fileName
=
nonPramStr
.
substring
(
nonPramStr
.
lastIndexOf
(
"/"
)
+
1
);
Integer
imageCount
=
this
.
getConvertedPdfImage
(
pdfFilePath
);
return
suffixFromFileName
(
fileName
);
String
imageFileSuffix
=
".jpg"
;
String
pdfFolder
=
pdfName
.
substring
(
0
,
pdfName
.
length
()
-
4
);
String
urlPrefix
;
try
{
urlPrefix
=
baseUrl
+
URLEncoder
.
encode
(
URLEncoder
.
encode
(
pdfFolder
,
uriEncoding
).
replaceAll
(
"\\+"
,
"%20"
),
uriEncoding
);
}
catch
(
UnsupportedEncodingException
e
)
{
logger
.
error
(
"UnsupportedEncodingException"
,
e
);
urlPrefix
=
baseUrl
+
pdfFolder
;
}
if
(
imageCount
!=
null
&&
imageCount
>
0
)
{
for
(
int
i
=
0
;
i
<
imageCount
;
i
++)
imageUrls
.
add
(
urlPrefix
+
"/"
+
i
+
imageFileSuffix
);
return
imageUrls
;
}
try
{
File
pdfFile
=
new
File
(
pdfFilePath
);
PDDocument
doc
=
PDDocument
.
load
(
pdfFile
);
int
pageCount
=
doc
.
getNumberOfPages
();
PDFRenderer
pdfRenderer
=
new
PDFRenderer
(
doc
);
int
index
=
pdfFilePath
.
lastIndexOf
(
"."
);
String
folder
=
pdfFilePath
.
substring
(
0
,
index
);
File
path
=
new
File
(
folder
);
if
(!
path
.
exists
()
&&
!
path
.
mkdirs
())
{
logger
.
error
(
"创建转换文件【{}】目录失败,请检查目录权限!"
,
folder
);
}
String
imageFilePath
;
for
(
int
pageIndex
=
0
;
pageIndex
<
pageCount
;
pageIndex
++)
{
imageFilePath
=
folder
+
File
.
separator
+
pageIndex
+
imageFileSuffix
;
BufferedImage
image
=
pdfRenderer
.
renderImageWithDPI
(
pageIndex
,
105
,
ImageType
.
RGB
);
ImageIOUtil
.
writeImage
(
image
,
imageFilePath
,
105
);
imageUrls
.
add
(
urlPrefix
+
"/"
+
pageIndex
+
imageFileSuffix
);
}
doc
.
close
();
this
.
addConvertedPdfImage
(
pdfFilePath
,
pageCount
);
}
catch
(
IOException
e
)
{
logger
.
error
(
"Convert pdf to jpg exception, pdfFilePath:{}"
,
pdfFilePath
,
e
);
}
return
imageUrls
;
}
}
private
String
suffixFromFileName
(
String
fileName
)
{
/**
return
fileName
.
substring
(
fileName
.
lastIndexOf
(
"."
)
+
1
);
* cad文件转pdf
* @param inputFilePath cad文件路径
* @param outputFilePath pdf输出文件路径
* @return 转换是否成功
*/
public
boolean
cadToPdf
(
String
inputFilePath
,
String
outputFilePath
)
{
com
.
aspose
.
cad
.
Image
cadImage
=
com
.
aspose
.
cad
.
Image
.
load
(
inputFilePath
);
CadRasterizationOptions
cadRasterizationOptions
=
new
CadRasterizationOptions
();
cadRasterizationOptions
.
setLayouts
(
new
String
[]{
"Model"
});
cadRasterizationOptions
.
setNoScaling
(
true
);
cadRasterizationOptions
.
setBackgroundColor
(
Color
.
getWhite
());
cadRasterizationOptions
.
setPageWidth
(
cadImage
.
getWidth
());
cadRasterizationOptions
.
setPageHeight
(
cadImage
.
getHeight
());
cadRasterizationOptions
.
setPdfProductLocation
(
"center"
);
cadRasterizationOptions
.
setAutomaticLayoutsScaling
(
true
);
cadRasterizationOptions
.
setDrawType
(
CadDrawTypeMode
.
UseObjectColor
);
PdfOptions
pdfOptions
=
new
PdfOptions
();
pdfOptions
.
setVectorRasterizationOptions
(
cadRasterizationOptions
);
File
outputFile
=
new
File
(
outputFilePath
);
OutputStream
stream
;
try
{
stream
=
new
FileOutputStream
(
outputFile
);
cadImage
.
save
(
stream
,
pdfOptions
);
cadImage
.
close
();
return
true
;
}
catch
(
FileNotFoundException
e
)
{
logger
.
error
(
"PDFFileNotFoundException,inputFilePath:{}"
,
inputFilePath
,
e
);
return
false
;
}
}
}
/**
/**
...
@@ -203,12 +262,12 @@ public class FileHandlerService {
...
@@ -203,12 +262,12 @@ public class FileHandlerService {
String
fullFileName
=
WebUtils
.
getUrlParameterReg
(
url
,
"fullfilename"
);
String
fullFileName
=
WebUtils
.
getUrlParameterReg
(
url
,
"fullfilename"
);
if
(
StringUtils
.
hasText
(
fullFileName
))
{
if
(
StringUtils
.
hasText
(
fullFileName
))
{
fileName
=
fullFileName
;
fileName
=
fullFileName
;
type
=
this
.
typeFromFileName
(
fullFileName
);
type
=
FileType
.
typeFromFileName
(
fullFileName
);
suffix
=
suffixFromFileName
(
fullFileName
);
suffix
=
FileUtils
.
suffixFromFileName
(
fullFileName
);
}
else
{
}
else
{
fileName
=
getFileNameFromURL
(
url
);
fileName
=
WebUtils
.
getFileNameFromURL
(
url
);
type
=
typeFromUrl
(
url
);
type
=
FileType
.
typeFromUrl
(
url
);
suffix
=
suffixFromUrl
(
url
);
suffix
=
WebUtils
.
suffixFromUrl
(
url
);
}
}
attribute
.
setType
(
type
);
attribute
.
setType
(
type
);
attribute
.
setName
(
fileName
);
attribute
.
setName
(
fileName
);
...
...
server/src/main/java/cn/keking/
extend/ControlDocument
FormatRegistry.java
→
server/src/main/java/cn/keking/
service/OfficePluginExtend
FormatRegistry.java
View file @
1f197023
package
cn
.
keking
.
extend
;
package
cn
.
keking
.
service
;
import
org.artofsolving.jodconverter.document.DocumentFamily
;
import
org.artofsolving.jodconverter.document.DocumentFamily
;
import
org.artofsolving.jodconverter.document.DocumentFormat
;
import
org.artofsolving.jodconverter.document.DocumentFormat
;
...
@@ -13,9 +13,9 @@ import java.util.Map;
...
@@ -13,9 +13,9 @@ import java.util.Map;
* @author yudian-it
* @author yudian-it
* @date 2017/12/5
* @date 2017/12/5
*/
*/
public
class
ControlDocument
FormatRegistry
extends
SimpleDocumentFormatRegistry
{
public
class
OfficePluginExtend
FormatRegistry
extends
SimpleDocumentFormatRegistry
{
public
ControlDocument
FormatRegistry
()
{
public
OfficePluginExtend
FormatRegistry
()
{
DocumentFormat
pdf
=
new
DocumentFormat
(
"Portable Document Format"
,
"pdf"
,
"application/pdf"
);
DocumentFormat
pdf
=
new
DocumentFormat
(
"Portable Document Format"
,
"pdf"
,
"application/pdf"
);
pdf
.
setStoreProperties
(
DocumentFamily
.
TEXT
,
Collections
.
singletonMap
(
"FilterName"
,
"writer_pdf_Export"
));
pdf
.
setStoreProperties
(
DocumentFamily
.
TEXT
,
Collections
.
singletonMap
(
"FilterName"
,
"writer_pdf_Export"
));
pdf
.
setStoreProperties
(
DocumentFamily
.
SPREADSHEET
,
Collections
.
singletonMap
(
"FilterName"
,
"calc_pdf_Export"
));
pdf
.
setStoreProperties
(
DocumentFamily
.
SPREADSHEET
,
Collections
.
singletonMap
(
"FilterName"
,
"calc_pdf_Export"
));
...
...
server/src/main/java/cn/keking/service/OfficePluginManager.java
View file @
1f197023
package
cn
.
keking
.
service
;
package
cn
.
keking
.
service
;
import
com.sun.star.document.UpdateDocMode
;
import
com.sun.star.document.UpdateDocMode
;
import
cn.keking.extend.ControlDocumentFormatRegistry
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.artofsolving.jodconverter.OfficeDocumentConverter
;
import
org.artofsolving.jodconverter.OfficeDocumentConverter
;
import
org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration
;
import
org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration
;
...
@@ -72,7 +71,7 @@ public class OfficePluginManager {
...
@@ -72,7 +71,7 @@ public class OfficePluginManager {
}
}
public
OfficeDocumentConverter
getDocumentConverter
()
{
public
OfficeDocumentConverter
getDocumentConverter
()
{
OfficeDocumentConverter
converter
=
new
OfficeDocumentConverter
(
officeManager
,
new
ControlDocument
FormatRegistry
());
OfficeDocumentConverter
converter
=
new
OfficeDocumentConverter
(
officeManager
,
new
OfficePluginExtend
FormatRegistry
());
converter
.
setDefaultLoadProperties
(
getLoadProperties
());
converter
.
setDefaultLoadProperties
(
getLoadProperties
());
return
converter
;
return
converter
;
}
}
...
...
server/src/main/java/cn/keking/service/OfficeToPdfService.java
View file @
1f197023
package
cn
.
keking
.
service
;
package
cn
.
keking
.
service
;
import
org.artofsolving.jodconverter.OfficeDocumentConverter
;
import
org.artofsolving.jodconverter.OfficeDocumentConverter
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
java.io.File
;
import
java.io.File
;
...
@@ -10,6 +12,8 @@ import java.io.File;
...
@@ -10,6 +12,8 @@ import java.io.File;
*/
*/
@Component
@Component
public
class
OfficeToPdfService
{
public
class
OfficeToPdfService
{
private
final
static
Logger
logger
=
LoggerFactory
.
getLogger
(
OfficeToPdfService
.
class
);
private
final
OfficePluginManager
officePluginManager
;
private
final
OfficePluginManager
officePluginManager
;
public
OfficeToPdfService
(
OfficePluginManager
officePluginManager
)
{
public
OfficeToPdfService
(
OfficePluginManager
officePluginManager
)
{
...
@@ -21,12 +25,11 @@ public class OfficeToPdfService {
...
@@ -21,12 +25,11 @@ public class OfficeToPdfService {
}
}
public
static
void
converterFile
(
File
inputFile
,
String
outputFilePath_end
,
public
static
void
converterFile
(
File
inputFile
,
String
outputFilePath_end
,
OfficeDocumentConverter
converter
)
{
OfficeDocumentConverter
converter
)
{
File
outputFile
=
new
File
(
outputFilePath_end
);
File
outputFile
=
new
File
(
outputFilePath_end
);
// 假如目标路径不存在,则新建该路径
// 假如目标路径不存在,则新建该路径
if
(!
outputFile
.
getParentFile
().
exists
())
{
if
(!
outputFile
.
getParentFile
().
exists
()
&&
!
outputFile
.
getParentFile
().
mkdirs
()
)
{
outputFile
.
getParentFile
().
mkdirs
(
);
logger
.
error
(
"创建目录【{}】失败,请检查目录权限!"
,
outputFilePath_end
);
}
}
converter
.
convert
(
inputFile
,
outputFile
);
converter
.
convert
(
inputFile
,
outputFile
);
}
}
...
...
server/src/main/java/cn/keking/service/cache/impl/CacheServiceRedisImpl.java
View file @
1f197023
...
@@ -28,19 +28,11 @@ public class CacheServiceRedisImpl implements CacheService {
...
@@ -28,19 +28,11 @@ public class CacheServiceRedisImpl implements CacheService {
}
}
@Override
@Override
public
void
initPDFCachePool
(
Integer
capacity
)
{
public
void
initPDFCachePool
(
Integer
capacity
)
{
}
}
@Override
@Override
public
void
initIMGCachePool
(
Integer
capacity
)
{
public
void
initIMGCachePool
(
Integer
capacity
)
{
}
}
@Override
@Override
public
void
initPdfImagesCachePool
(
Integer
capacity
)
{
public
void
initPdfImagesCachePool
(
Integer
capacity
)
{
}
}
@Override
@Override
public
void
putPDFCache
(
String
key
,
String
value
)
{
public
void
putPDFCache
(
String
key
,
String
value
)
{
...
...
server/src/main/java/cn/keking/service/cache/impl/CacheServiceRocksDBImpl.java
View file @
1f197023
...
@@ -31,11 +31,8 @@ public class CacheServiceRocksDBImpl implements CacheService {
...
@@ -31,11 +31,8 @@ public class CacheServiceRocksDBImpl implements CacheService {
}
}
private
static
final
String
DB_PATH
=
ConfigUtils
.
getHomePath
()
+
File
.
separator
+
"cache"
;
private
static
final
String
DB_PATH
=
ConfigUtils
.
getHomePath
()
+
File
.
separator
+
"cache"
;
private
static
final
int
QUEUE_SIZE
=
500000
;
private
static
final
int
QUEUE_SIZE
=
500000
;
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
CacheServiceRocksDBImpl
.
class
);
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
CacheServiceRocksDBImpl
.
class
);
private
final
BlockingQueue
<
String
>
blockingQueue
=
new
ArrayBlockingQueue
<>(
QUEUE_SIZE
);
private
final
BlockingQueue
<
String
>
blockingQueue
=
new
ArrayBlockingQueue
<>(
QUEUE_SIZE
);
private
RocksDB
db
;
private
RocksDB
db
;
...
...
server/src/main/java/cn/keking/service/impl/CadFilePreviewImpl.java
View file @
1f197023
...
@@ -4,10 +4,8 @@ import cn.keking.config.ConfigConstants;
...
@@ -4,10 +4,8 @@ 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.CadUtils
;
import
cn.keking.utils.DownloadUtils
;
import
cn.keking.utils.DownloadUtils
;
import
cn.keking.service.FileHandlerService
;
import
cn.keking.service.FileHandlerService
;
import
cn.keking.utils.PdfUtils
;
import
cn.keking.web.filter.BaseUrlFilter
;
import
cn.keking.web.filter.BaseUrlFilter
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.ui.Model
;
import
org.springframework.ui.Model
;
...
@@ -22,43 +20,37 @@ import static cn.keking.service.impl.OfficeFilePreviewImpl.getPreviewType;
...
@@ -22,43 +20,37 @@ import static cn.keking.service.impl.OfficeFilePreviewImpl.getPreviewType;
@Service
@Service
public
class
CadFilePreviewImpl
implements
FilePreview
{
public
class
CadFilePreviewImpl
implements
FilePreview
{
private
final
FileHandlerService
fileHandlerService
;
private
final
CadUtils
cadUtils
;
private
final
PdfUtils
pdfUtils
;
public
CadFilePreviewImpl
(
FileHandlerService
fileHandlerService
,
CadUtils
cadUtils
,
PdfUtils
pdfUtils
)
{
this
.
fileHandlerService
=
fileHandlerService
;
this
.
cadUtils
=
cadUtils
;
this
.
pdfUtils
=
pdfUtils
;
}
private
static
final
String
OFFICE_PREVIEW_TYPE_IMAGE
=
"image"
;
private
static
final
String
OFFICE_PREVIEW_TYPE_IMAGE
=
"image"
;
private
static
final
String
OFFICE_PREVIEW_TYPE_ALL_IMAGES
=
"allImages"
;
private
static
final
String
OFFICE_PREVIEW_TYPE_ALL_IMAGES
=
"allImages"
;
private
static
final
String
FILE_DIR
=
ConfigConstants
.
getFileDir
();
private
static
final
String
FILE_DIR
=
ConfigConstants
.
getFileDir
();
private
final
FileHandlerService
fileHandlerService
;
public
CadFilePreviewImpl
(
FileHandlerService
fileHandlerService
)
{
this
.
fileHandlerService
=
fileHandlerService
;
}
@Override
@Override
public
String
filePreviewHandle
(
String
url
,
Model
model
,
FileAttribute
fileAttribute
)
{
public
String
filePreviewHandle
(
String
url
,
Model
model
,
FileAttribute
fileAttribute
)
{
// 预览Type,参数传了就取参数的,没传取系统默认
// 预览Type,参数传了就取参数的,没传取系统默认
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
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
=
FILE_DIR
+
pdfName
;
String
outFilePath
=
FILE_DIR
+
pdfName
;
// 判断之前是否已转换过,如果转换过,直接返回,否则执行转换
// 判断之前是否已转换过,如果转换过,直接返回,否则执行转换
if
(!
fileHandlerService
.
listConvertedFiles
().
containsKey
(
pdfName
)
||
!
ConfigConstants
.
isCacheEnabled
())
{
if
(!
fileHandlerService
.
listConvertedFiles
().
containsKey
(
pdfName
)
||
!
ConfigConstants
.
isCacheEnabled
())
{
String
filePath
;
String
filePath
;
ReturnResponse
<
String
>
response
=
DownloadUtils
.
downLoad
(
fileAttribute
,
null
);
ReturnResponse
<
String
>
response
=
DownloadUtils
.
downLoad
(
fileAttribute
,
null
);
if
(
0
!=
response
.
getCod
e
())
{
if
(
response
.
isFailur
e
())
{
model
.
addAttribute
(
"fileType"
,
suffix
);
model
.
addAttribute
(
"fileType"
,
suffix
);
model
.
addAttribute
(
"msg"
,
response
.
getMsg
());
model
.
addAttribute
(
"msg"
,
response
.
getMsg
());
return
"fileNotSupported"
;
return
"fileNotSupported"
;
}
}
filePath
=
response
.
getContent
();
filePath
=
response
.
getContent
();
if
(
StringUtils
.
hasText
(
outFilePath
))
{
if
(
StringUtils
.
hasText
(
outFilePath
))
{
boolean
convertResult
=
cadUtils
.
cadToPdf
(
filePath
,
outFilePath
);
boolean
convertResult
=
fileHandlerService
.
cadToPdf
(
filePath
,
outFilePath
);
if
(!
convertResult
)
{
if
(!
convertResult
)
{
model
.
addAttribute
(
"fileType"
,
suffix
);
model
.
addAttribute
(
"fileType"
,
suffix
);
model
.
addAttribute
(
"msg"
,
"cad文件转换异常,请联系管理员"
);
model
.
addAttribute
(
"msg"
,
"cad文件转换异常,请联系管理员"
);
...
@@ -71,7 +63,7 @@ public class CadFilePreviewImpl implements FilePreview {
...
@@ -71,7 +63,7 @@ public class CadFilePreviewImpl implements FilePreview {
}
}
}
}
if
(
baseUrl
!=
null
&&
(
OFFICE_PREVIEW_TYPE_IMAGE
.
equals
(
officePreviewType
)
||
OFFICE_PREVIEW_TYPE_ALL_IMAGES
.
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
,
fileHandlerService
,
OFFICE_PREVIEW_TYPE_IMAGE
);
}
}
model
.
addAttribute
(
"pdfUrl"
,
pdfName
);
model
.
addAttribute
(
"pdfUrl"
,
pdfName
);
return
"pdf"
;
return
"pdf"
;
...
...
server/src/main/java/cn/keking/service/impl/CompressFilePreviewImpl.java
View file @
1f197023
...
@@ -34,7 +34,7 @@ public class CompressFilePreviewImpl implements FilePreview {
...
@@ -34,7 +34,7 @@ public class CompressFilePreviewImpl implements FilePreview {
// 判断文件名是否存在(redis缓存读取)
// 判断文件名是否存在(redis缓存读取)
if
(!
StringUtils
.
hasText
(
fileHandlerService
.
getConvertedFile
(
fileName
))
||
!
ConfigConstants
.
isCacheEnabled
())
{
if
(!
StringUtils
.
hasText
(
fileHandlerService
.
getConvertedFile
(
fileName
))
||
!
ConfigConstants
.
isCacheEnabled
())
{
ReturnResponse
<
String
>
response
=
DownloadUtils
.
downLoad
(
fileAttribute
,
fileName
);
ReturnResponse
<
String
>
response
=
DownloadUtils
.
downLoad
(
fileAttribute
,
fileName
);
if
(
0
!=
response
.
getCod
e
())
{
if
(
response
.
isFailur
e
())
{
model
.
addAttribute
(
"fileType"
,
suffix
);
model
.
addAttribute
(
"fileType"
,
suffix
);
model
.
addAttribute
(
"msg"
,
response
.
getMsg
());
model
.
addAttribute
(
"msg"
,
response
.
getMsg
());
return
"fileNotSupported"
;
return
"fileNotSupported"
;
...
...
server/src/main/java/cn/keking/service/impl/MediaFilePreviewImpl.java
View file @
1f197023
...
@@ -8,6 +8,7 @@ import cn.keking.service.FileHandlerService;
...
@@ -8,6 +8,7 @@ import cn.keking.service.FileHandlerService;
import
cn.keking.web.filter.BaseUrlFilter
;
import
cn.keking.web.filter.BaseUrlFilter
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.ui.Model
;
import
org.springframework.ui.Model
;
/**
/**
* @author : kl
* @author : kl
* @authorboke : kailing.pub
* @authorboke : kailing.pub
...
@@ -28,7 +29,7 @@ public class MediaFilePreviewImpl implements FilePreview {
...
@@ -28,7 +29,7 @@ public class MediaFilePreviewImpl implements FilePreview {
// 不是http开头,浏览器不能直接访问,需下载到本地
// 不是http开头,浏览器不能直接访问,需下载到本地
if
(
url
!=
null
&&
!
url
.
toLowerCase
().
startsWith
(
"http"
))
{
if
(
url
!=
null
&&
!
url
.
toLowerCase
().
startsWith
(
"http"
))
{
ReturnResponse
<
String
>
response
=
DownloadUtils
.
downLoad
(
fileAttribute
,
fileAttribute
.
getName
());
ReturnResponse
<
String
>
response
=
DownloadUtils
.
downLoad
(
fileAttribute
,
fileAttribute
.
getName
());
if
(
0
!=
response
.
getCode
())
{
if
(
!
response
.
isSuccess
())
{
model
.
addAttribute
(
"fileType"
,
fileAttribute
.
getSuffix
());
model
.
addAttribute
(
"fileType"
,
fileAttribute
.
getSuffix
());
model
.
addAttribute
(
"msg"
,
response
.
getMsg
());
model
.
addAttribute
(
"msg"
,
response
.
getMsg
());
return
"fileNotSupported"
;
return
"fileNotSupported"
;
...
@@ -39,7 +40,7 @@ public class MediaFilePreviewImpl implements FilePreview {
...
@@ -39,7 +40,7 @@ public class MediaFilePreviewImpl implements FilePreview {
model
.
addAttribute
(
"mediaUrl"
,
url
);
model
.
addAttribute
(
"mediaUrl"
,
url
);
}
}
model
.
addAttribute
(
"mediaUrl"
,
url
);
model
.
addAttribute
(
"mediaUrl"
,
url
);
String
suffix
=
fileAttribute
.
getSuffix
();
String
suffix
=
fileAttribute
.
getSuffix
();
if
(
"flv"
.
equalsIgnoreCase
(
suffix
))
{
if
(
"flv"
.
equalsIgnoreCase
(
suffix
))
{
return
"flv"
;
return
"flv"
;
}
}
...
...
server/src/main/java/cn/keking/service/impl/OfficeFilePreviewImpl.java
View file @
1f197023
...
@@ -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.service.FileHandlerService
;
import
cn.keking.service.FileHandlerService
;
import
cn.keking.service.OfficeToPdfService
;
import
cn.keking.service.OfficeToPdfService
;
import
cn.keking.utils.PdfUtils
;
import
cn.keking.web.filter.BaseUrlFilter
;
import
cn.keking.web.filter.BaseUrlFilter
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.ui.Model
;
import
org.springframework.ui.Model
;
...
@@ -22,20 +21,18 @@ import java.util.List;
...
@@ -22,20 +21,18 @@ import java.util.List;
@Service
@Service
public
class
OfficeFilePreviewImpl
implements
FilePreview
{
public
class
OfficeFilePreviewImpl
implements
FilePreview
{
public
static
final
String
OFFICE_PREVIEW_TYPE_IMAGE
=
"image"
;
public
static
final
String
OFFICE_PREVIEW_TYPE_ALL_IMAGES
=
"allImages"
;
private
static
final
String
FILE_DIR
=
ConfigConstants
.
getFileDir
();
private
final
FileHandlerService
fileHandlerService
;
private
final
FileHandlerService
fileHandlerService
;
private
final
PdfUtils
pdfUtils
;
private
final
OfficeToPdfService
officeToPdfService
;
private
final
OfficeToPdfService
officeToPdfService
;
public
OfficeFilePreviewImpl
(
FileHandlerService
fileHandlerService
,
PdfUtils
pdfUtils
,
OfficeToPdfService
officeToPdfService
)
{
public
OfficeFilePreviewImpl
(
FileHandlerService
fileHandlerService
,
OfficeToPdfService
officeToPdfService
)
{
this
.
fileHandlerService
=
fileHandlerService
;
this
.
fileHandlerService
=
fileHandlerService
;
this
.
pdfUtils
=
pdfUtils
;
this
.
officeToPdfService
=
officeToPdfService
;
this
.
officeToPdfService
=
officeToPdfService
;
}
}
public
static
final
String
OFFICE_PREVIEW_TYPE_IMAGE
=
"image"
;
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
)
{
// 预览Type,参数传了就取参数的,没传取系统默认
// 预览Type,参数传了就取参数的,没传取系统默认
...
@@ -50,7 +47,7 @@ public class OfficeFilePreviewImpl implements FilePreview {
...
@@ -50,7 +47,7 @@ public class OfficeFilePreviewImpl implements FilePreview {
if
(!
fileHandlerService
.
listConvertedFiles
().
containsKey
(
pdfName
)
||
!
ConfigConstants
.
isCacheEnabled
())
{
if
(!
fileHandlerService
.
listConvertedFiles
().
containsKey
(
pdfName
)
||
!
ConfigConstants
.
isCacheEnabled
())
{
String
filePath
;
String
filePath
;
ReturnResponse
<
String
>
response
=
DownloadUtils
.
downLoad
(
fileAttribute
,
null
);
ReturnResponse
<
String
>
response
=
DownloadUtils
.
downLoad
(
fileAttribute
,
null
);
if
(
0
!=
response
.
getCod
e
())
{
if
(
response
.
isFailur
e
())
{
model
.
addAttribute
(
"fileType"
,
suffix
);
model
.
addAttribute
(
"fileType"
,
suffix
);
model
.
addAttribute
(
"msg"
,
response
.
getMsg
());
model
.
addAttribute
(
"msg"
,
response
.
getMsg
());
return
"fileNotSupported"
;
return
"fileNotSupported"
;
...
@@ -69,14 +66,14 @@ public class OfficeFilePreviewImpl implements FilePreview {
...
@@ -69,14 +66,14 @@ public class OfficeFilePreviewImpl implements FilePreview {
}
}
}
}
if
(!
isHtml
&&
baseUrl
!=
null
&&
(
OFFICE_PREVIEW_TYPE_IMAGE
.
equals
(
officePreviewType
)
||
OFFICE_PREVIEW_TYPE_ALL_IMAGES
.
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
,
fileHandlerService
,
OFFICE_PREVIEW_TYPE_IMAGE
);
}
}
model
.
addAttribute
(
"pdfUrl"
,
pdfName
);
model
.
addAttribute
(
"pdfUrl"
,
pdfName
);
return
isHtml
?
"html"
:
"pdf"
;
return
isHtml
?
"html"
:
"pdf"
;
}
}
static
String
getPreviewType
(
Model
model
,
FileAttribute
fileAttribute
,
String
officePreviewType
,
String
baseUrl
,
String
pdfName
,
String
outFilePath
,
PdfUtils
pdfUtils
,
String
officePreviewTypeImage
)
{
static
String
getPreviewType
(
Model
model
,
FileAttribute
fileAttribute
,
String
officePreviewType
,
String
baseUrl
,
String
pdfName
,
String
outFilePath
,
FileHandlerService
fileHandlerService
,
String
officePreviewTypeImage
)
{
List
<
String
>
imageUrls
=
pdfUtils
.
pdf2jpg
(
outFilePath
,
pdfName
,
baseUrl
);
List
<
String
>
imageUrls
=
fileHandlerService
.
pdf2jpg
(
outFilePath
,
pdfName
,
baseUrl
);
if
(
imageUrls
==
null
||
imageUrls
.
size
()
<
1
)
{
if
(
imageUrls
==
null
||
imageUrls
.
size
()
<
1
)
{
model
.
addAttribute
(
"msg"
,
"office转图片异常,请联系管理员"
);
model
.
addAttribute
(
"msg"
,
"office转图片异常,请联系管理员"
);
model
.
addAttribute
(
"fileType"
,
fileAttribute
.
getSuffix
());
model
.
addAttribute
(
"fileType"
,
fileAttribute
.
getSuffix
());
...
...
server/src/main/java/cn/keking/service/impl/PdfFilePreviewImpl.java
View file @
1f197023
...
@@ -6,7 +6,6 @@ import cn.keking.model.ReturnResponse;
...
@@ -6,7 +6,6 @@ import cn.keking.model.ReturnResponse;
import
cn.keking.service.FilePreview
;
import
cn.keking.service.FilePreview
;
import
cn.keking.utils.DownloadUtils
;
import
cn.keking.utils.DownloadUtils
;
import
cn.keking.service.FileHandlerService
;
import
cn.keking.service.FileHandlerService
;
import
cn.keking.utils.PdfUtils
;
import
cn.keking.web.filter.BaseUrlFilter
;
import
cn.keking.web.filter.BaseUrlFilter
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.ui.Model
;
import
org.springframework.ui.Model
;
...
@@ -21,12 +20,10 @@ import java.util.List;
...
@@ -21,12 +20,10 @@ import java.util.List;
public
class
PdfFilePreviewImpl
implements
FilePreview
{
public
class
PdfFilePreviewImpl
implements
FilePreview
{
private
final
FileHandlerService
fileHandlerService
;
private
final
FileHandlerService
fileHandlerService
;
private
final
PdfUtils
pdfUtils
;
private
static
final
String
FILE_DIR
=
ConfigConstants
.
getFileDir
();
private
static
final
String
FILE_DIR
=
ConfigConstants
.
getFileDir
();
public
PdfFilePreviewImpl
(
FileHandlerService
fileHandlerService
,
PdfUtils
pdfUtils
)
{
public
PdfFilePreviewImpl
(
FileHandlerService
fileHandlerService
)
{
this
.
fileHandlerService
=
fileHandlerService
;
this
.
fileHandlerService
=
fileHandlerService
;
this
.
pdfUtils
=
pdfUtils
;
}
}
@Override
@Override
...
@@ -41,7 +38,7 @@ public class PdfFilePreviewImpl implements FilePreview {
...
@@ -41,7 +38,7 @@ public class PdfFilePreviewImpl implements FilePreview {
//当文件不存在时,就去下载
//当文件不存在时,就去下载
if
(!
fileHandlerService
.
listConvertedFiles
().
containsKey
(
pdfName
)
||
!
ConfigConstants
.
isCacheEnabled
())
{
if
(!
fileHandlerService
.
listConvertedFiles
().
containsKey
(
pdfName
)
||
!
ConfigConstants
.
isCacheEnabled
())
{
ReturnResponse
<
String
>
response
=
DownloadUtils
.
downLoad
(
fileAttribute
,
fileName
);
ReturnResponse
<
String
>
response
=
DownloadUtils
.
downLoad
(
fileAttribute
,
fileName
);
if
(
0
!=
response
.
getCod
e
())
{
if
(
response
.
isFailur
e
())
{
model
.
addAttribute
(
"fileType"
,
suffix
);
model
.
addAttribute
(
"fileType"
,
suffix
);
model
.
addAttribute
(
"msg"
,
response
.
getMsg
());
model
.
addAttribute
(
"msg"
,
response
.
getMsg
());
return
"fileNotSupported"
;
return
"fileNotSupported"
;
...
@@ -52,7 +49,7 @@ public class PdfFilePreviewImpl implements FilePreview {
...
@@ -52,7 +49,7 @@ public class PdfFilePreviewImpl implements FilePreview {
fileHandlerService
.
addConvertedFile
(
pdfName
,
fileHandlerService
.
getRelativePath
(
outFilePath
));
fileHandlerService
.
addConvertedFile
(
pdfName
,
fileHandlerService
.
getRelativePath
(
outFilePath
));
}
}
}
}
List
<
String
>
imageUrls
=
pdfUtils
.
pdf2jpg
(
outFilePath
,
pdfName
,
baseUrl
);
List
<
String
>
imageUrls
=
fileHandlerService
.
pdf2jpg
(
outFilePath
,
pdfName
,
baseUrl
);
if
(
imageUrls
==
null
||
imageUrls
.
size
()
<
1
)
{
if
(
imageUrls
==
null
||
imageUrls
.
size
()
<
1
)
{
model
.
addAttribute
(
"msg"
,
"pdf转图片异常,请联系管理员"
);
model
.
addAttribute
(
"msg"
,
"pdf转图片异常,请联系管理员"
);
model
.
addAttribute
(
"fileType"
,
fileAttribute
.
getSuffix
());
model
.
addAttribute
(
"fileType"
,
fileAttribute
.
getSuffix
());
...
@@ -70,7 +67,7 @@ public class PdfFilePreviewImpl implements FilePreview {
...
@@ -70,7 +67,7 @@ public class PdfFilePreviewImpl implements FilePreview {
if
(
url
!=
null
&&
!
url
.
toLowerCase
().
startsWith
(
"http"
))
{
if
(
url
!=
null
&&
!
url
.
toLowerCase
().
startsWith
(
"http"
))
{
if
(!
fileHandlerService
.
listConvertedFiles
().
containsKey
(
pdfName
)
||
!
ConfigConstants
.
isCacheEnabled
())
{
if
(!
fileHandlerService
.
listConvertedFiles
().
containsKey
(
pdfName
)
||
!
ConfigConstants
.
isCacheEnabled
())
{
ReturnResponse
<
String
>
response
=
DownloadUtils
.
downLoad
(
fileAttribute
,
pdfName
);
ReturnResponse
<
String
>
response
=
DownloadUtils
.
downLoad
(
fileAttribute
,
pdfName
);
if
(
0
!=
response
.
getCod
e
())
{
if
(
response
.
isFailur
e
())
{
model
.
addAttribute
(
"fileType"
,
suffix
);
model
.
addAttribute
(
"fileType"
,
suffix
);
model
.
addAttribute
(
"msg"
,
response
.
getMsg
());
model
.
addAttribute
(
"msg"
,
response
.
getMsg
());
return
"fileNotSupported"
;
return
"fileNotSupported"
;
...
...
server/src/main/java/cn/keking/service/impl/PictureFilePreviewImpl.java
View file @
1f197023
...
@@ -36,7 +36,7 @@ public class PictureFilePreviewImpl implements FilePreview {
...
@@ -36,7 +36,7 @@ public class PictureFilePreviewImpl implements FilePreview {
// 不是http开头,浏览器不能直接访问,需下载到本地
// 不是http开头,浏览器不能直接访问,需下载到本地
if
(
url
!=
null
&&
!
url
.
toLowerCase
().
startsWith
(
"http"
))
{
if
(
url
!=
null
&&
!
url
.
toLowerCase
().
startsWith
(
"http"
))
{
ReturnResponse
<
String
>
response
=
DownloadUtils
.
downLoad
(
fileAttribute
,
null
);
ReturnResponse
<
String
>
response
=
DownloadUtils
.
downLoad
(
fileAttribute
,
null
);
if
(
0
!=
response
.
getCod
e
())
{
if
(
response
.
isFailur
e
())
{
model
.
addAttribute
(
"fileType"
,
fileAttribute
.
getSuffix
());
model
.
addAttribute
(
"fileType"
,
fileAttribute
.
getSuffix
());
model
.
addAttribute
(
"msg"
,
response
.
getMsg
());
model
.
addAttribute
(
"msg"
,
response
.
getMsg
());
return
"fileNotSupported"
;
return
"fileNotSupported"
;
...
...
server/src/main/java/cn/keking/service/impl/SimTextFilePreviewImpl.java
View file @
1f197023
...
@@ -27,7 +27,7 @@ public class SimTextFilePreviewImpl implements FilePreview {
...
@@ -27,7 +27,7 @@ public class SimTextFilePreviewImpl implements FilePreview {
public
String
filePreviewHandle
(
String
url
,
Model
model
,
FileAttribute
fileAttribute
)
{
public
String
filePreviewHandle
(
String
url
,
Model
model
,
FileAttribute
fileAttribute
)
{
String
fileName
=
fileAttribute
.
getName
();
String
fileName
=
fileAttribute
.
getName
();
ReturnResponse
<
String
>
response
=
DownloadUtils
.
downLoad
(
fileAttribute
,
fileName
);
ReturnResponse
<
String
>
response
=
DownloadUtils
.
downLoad
(
fileAttribute
,
fileName
);
if
(
0
!=
response
.
getCod
e
())
{
if
(
response
.
isFailur
e
())
{
model
.
addAttribute
(
"msg"
,
response
.
getMsg
());
model
.
addAttribute
(
"msg"
,
response
.
getMsg
());
model
.
addAttribute
(
"fileType"
,
fileAttribute
.
getSuffix
());
model
.
addAttribute
(
"fileType"
,
fileAttribute
.
getSuffix
());
return
"fileNotSupported"
;
return
"fileNotSupported"
;
...
...
server/src/main/java/cn/keking/utils/CadUtils.java
deleted
100644 → 0
View file @
594bd895
package
cn
.
keking
.
utils
;
import
com.aspose.cad.Color
;
import
com.aspose.cad.fileformats.cad.CadDrawTypeMode
;
import
com.aspose.cad.imageoptions.CadRasterizationOptions
;
import
com.aspose.cad.imageoptions.PdfOptions
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Component
;
import
java.io.File
;
import
java.io.FileNotFoundException
;
import
java.io.FileOutputStream
;
import
java.io.OutputStream
;
/**
* @author chenjhc
* @since 2019/11/21 14:34
*/
@Component
public
class
CadUtils
{
private
final
Logger
logger
=
LoggerFactory
.
getLogger
(
CadUtils
.
class
);
public
boolean
cadToPdf
(
String
inputFilePath
,
String
outputFilePath
)
{
com
.
aspose
.
cad
.
Image
cadImage
=
com
.
aspose
.
cad
.
Image
.
load
(
inputFilePath
);
CadRasterizationOptions
cadRasterizationOptions
=
new
CadRasterizationOptions
();
cadRasterizationOptions
.
setLayouts
(
new
String
[]{
"Model"
});
cadRasterizationOptions
.
setNoScaling
(
true
);
cadRasterizationOptions
.
setBackgroundColor
(
Color
.
getWhite
());
cadRasterizationOptions
.
setPageWidth
(
cadImage
.
getWidth
());
cadRasterizationOptions
.
setPageHeight
(
cadImage
.
getHeight
());
cadRasterizationOptions
.
setPdfProductLocation
(
"center"
);
cadRasterizationOptions
.
setAutomaticLayoutsScaling
(
true
);
cadRasterizationOptions
.
setDrawType
(
CadDrawTypeMode
.
UseObjectColor
);
PdfOptions
pdfOptions
=
new
PdfOptions
();
pdfOptions
.
setVectorRasterizationOptions
(
cadRasterizationOptions
);
File
outputFile
=
new
File
(
outputFilePath
);
OutputStream
stream
;
try
{
stream
=
new
FileOutputStream
(
outputFile
);
cadImage
.
save
(
stream
,
pdfOptions
);
cadImage
.
close
();
return
true
;
}
catch
(
FileNotFoundException
e
)
{
logger
.
error
(
"PDFFileNotFoundException,inputFilePath:{}"
,
inputFilePath
,
e
);
return
false
;
}
}
}
server/src/main/java/cn/keking/utils/FileUtils.java
View file @
1f197023
...
@@ -57,6 +57,16 @@ public class FileUtils {
...
@@ -57,6 +57,16 @@ public class FileUtils {
}
}
}
}
/**
* 通过文件名获取文件后缀
* @param fileName 文件名称
* @return 文件后缀
*/
public
static
String
suffixFromFileName
(
String
fileName
)
{
return
fileName
.
substring
(
fileName
.
lastIndexOf
(
"."
)
+
1
);
}
/**
/**
* 根据文件路径删除文件
* 根据文件路径删除文件
*
*
...
...
server/src/main/java/cn/keking/utils/PdfUtils.java
deleted
100644 → 0
View file @
594bd895
package
cn
.
keking
.
utils
;
import
cn.keking.service.FileHandlerService
;
import
org.apache.pdfbox.pdmodel.PDDocument
;
import
org.apache.pdfbox.rendering.ImageType
;
import
org.apache.pdfbox.rendering.PDFRenderer
;
import
org.apache.pdfbox.tools.imageio.ImageIOUtil
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
import
java.awt.image.BufferedImage
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.UnsupportedEncodingException
;
import
java.net.URLEncoder
;
import
java.util.ArrayList
;
import
java.util.List
;
@Component
public
class
PdfUtils
{
private
final
Logger
logger
=
LoggerFactory
.
getLogger
(
PdfUtils
.
class
);
private
final
FileHandlerService
fileHandlerService
;
@Value
(
"${server.tomcat.uri-encoding:UTF-8}"
)
private
String
uriEncoding
;
public
PdfUtils
(
FileHandlerService
fileHandlerService
)
{
this
.
fileHandlerService
=
fileHandlerService
;
}
public
List
<
String
>
pdf2jpg
(
String
pdfFilePath
,
String
pdfName
,
String
baseUrl
)
{
List
<
String
>
imageUrls
=
new
ArrayList
<>();
Integer
imageCount
=
fileHandlerService
.
getConvertedPdfImage
(
pdfFilePath
);
String
imageFileSuffix
=
".jpg"
;
String
pdfFolder
=
pdfName
.
substring
(
0
,
pdfName
.
length
()
-
4
);
String
urlPrefix
=
null
;
try
{
urlPrefix
=
baseUrl
+
URLEncoder
.
encode
(
URLEncoder
.
encode
(
pdfFolder
,
uriEncoding
).
replaceAll
(
"\\+"
,
"%20"
),
uriEncoding
);
}
catch
(
UnsupportedEncodingException
e
)
{
logger
.
error
(
"UnsupportedEncodingException"
,
e
);
urlPrefix
=
baseUrl
+
pdfFolder
;
}
if
(
imageCount
!=
null
&&
imageCount
>
0
)
{
for
(
int
i
=
0
;
i
<
imageCount
;
i
++)
imageUrls
.
add
(
urlPrefix
+
"/"
+
i
+
imageFileSuffix
);
return
imageUrls
;
}
try
{
File
pdfFile
=
new
File
(
pdfFilePath
);
PDDocument
doc
=
PDDocument
.
load
(
pdfFile
);
int
pageCount
=
doc
.
getNumberOfPages
();
PDFRenderer
pdfRenderer
=
new
PDFRenderer
(
doc
);
int
index
=
pdfFilePath
.
lastIndexOf
(
"."
);
String
folder
=
pdfFilePath
.
substring
(
0
,
index
);
File
path
=
new
File
(
folder
);
if
(!
path
.
exists
())
{
path
.
mkdirs
();
}
String
imageFilePath
;
for
(
int
pageIndex
=
0
;
pageIndex
<
pageCount
;
pageIndex
++)
{
imageFilePath
=
folder
+
File
.
separator
+
pageIndex
+
imageFileSuffix
;
BufferedImage
image
=
pdfRenderer
.
renderImageWithDPI
(
pageIndex
,
105
,
ImageType
.
RGB
);
ImageIOUtil
.
writeImage
(
image
,
imageFilePath
,
105
);
imageUrls
.
add
(
urlPrefix
+
"/"
+
pageIndex
+
imageFileSuffix
);
}
doc
.
close
();
fileHandlerService
.
addConvertedPdfImage
(
pdfFilePath
,
pageCount
);
}
catch
(
IOException
e
)
{
logger
.
error
(
"Convert pdf to jpg exception, pdfFilePath:{}"
,
pdfFilePath
,
e
);
}
return
imageUrls
;
}
}
server/src/main/java/cn/keking/utils/WebUtils.java
View file @
1f197023
...
@@ -57,4 +57,30 @@ public class WebUtils {
...
@@ -57,4 +57,30 @@ public class WebUtils {
}
}
return
strAllParam
;
return
strAllParam
;
}
}
/**
* 从url中剥离出文件名
*
* @param url 格式如:http://www.com.cn/20171113164107_月度绩效表模板(新).xls?UCloudPublicKey=ucloudtangshd@weifenf.com14355492830001993909323&Expires=&Signature=I D1NOFtAJSPT16E6imv6JWuq0k=
* @return 文件名
*/
public
static
String
getFileNameFromURL
(
String
url
)
{
// 因为url的参数中可能会存在/的情况,所以直接url.lastIndexOf("/")会有问题
// 所以先从?处将url截断,然后运用url.lastIndexOf("/")获取文件名
String
noQueryUrl
=
url
.
substring
(
0
,
url
.
contains
(
"?"
)
?
url
.
indexOf
(
"?"
)
:
url
.
length
());
return
noQueryUrl
.
substring
(
noQueryUrl
.
lastIndexOf
(
"/"
)
+
1
);
}
/**
* 从url中获取文件后缀
*
* @param url url
* @return 文件后缀
*/
public
static
String
suffixFromUrl
(
String
url
)
{
String
nonPramStr
=
url
.
substring
(
0
,
url
.
contains
(
"?"
)
?
url
.
indexOf
(
"?"
)
:
url
.
length
());
String
fileName
=
nonPramStr
.
substring
(
nonPramStr
.
lastIndexOf
(
"/"
)
+
1
);
return
FileUtils
.
suffixFromFileName
(
fileName
);
}
}
}
server/src/main/java/cn/keking/web/controller/FileController.java
View file @
1f197023
...
@@ -28,9 +28,7 @@ public class FileController {
...
@@ -28,9 +28,7 @@ public class FileController {
private
final
Logger
logger
=
LoggerFactory
.
getLogger
(
FileController
.
class
);
private
final
Logger
logger
=
LoggerFactory
.
getLogger
(
FileController
.
class
);
private
final
String
fileDir
=
ConfigConstants
.
getFileDir
();
private
final
String
fileDir
=
ConfigConstants
.
getFileDir
();
private
final
String
demoDir
=
"demo"
;
private
final
String
demoDir
=
"demo"
;
private
final
String
demoPath
=
demoDir
+
File
.
separator
;
private
final
String
demoPath
=
demoDir
+
File
.
separator
;
@RequestMapping
(
value
=
"fileUpload"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
value
=
"fileUpload"
,
method
=
RequestMethod
.
POST
)
...
@@ -49,7 +47,7 @@ public class FileController {
...
@@ -49,7 +47,7 @@ public class FileController {
}
}
// 判断是否存在同名文件
// 判断是否存在同名文件
if
(
existsFile
(
fileName
))
{
if
(
existsFile
(
fileName
))
{
return
new
ObjectMapper
().
writeValueAsString
(
new
ReturnResponse
<
String
>(
1
,
"存在同名文件,请先删除原有文件再次上传"
,
null
));
return
new
ObjectMapper
().
writeValueAsString
(
ReturnResponse
.
failure
(
"存在同名文件,请先删除原有文件再次上传"
));
}
}
File
outFile
=
new
File
(
fileDir
+
demoPath
);
File
outFile
=
new
File
(
fileDir
+
demoPath
);
if
(!
outFile
.
exists
()
&&
!
outFile
.
mkdirs
())
{
if
(!
outFile
.
exists
()
&&
!
outFile
.
mkdirs
())
{
...
@@ -58,10 +56,10 @@ public class FileController {
...
@@ -58,10 +56,10 @@ public class FileController {
logger
.
info
(
"上传文件:{}"
,
fileDir
+
demoPath
+
fileName
);
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
(
ReturnResponse
.
success
(
null
));
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
logger
.
error
(
"文件上传失败"
,
e
);
logger
.
error
(
"文件上传失败"
,
e
);
return
new
ObjectMapper
().
writeValueAsString
(
new
ReturnResponse
<
String
>(
1
,
"FAILURE"
,
null
));
return
new
ObjectMapper
().
writeValueAsString
(
ReturnResponse
.
failure
(
));
}
}
}
}
...
@@ -75,7 +73,7 @@ public class FileController {
...
@@ -75,7 +73,7 @@ public class FileController {
if
(
file
.
exists
()
&&
!
file
.
delete
())
{
if
(
file
.
exists
()
&&
!
file
.
delete
())
{
logger
.
error
(
"删除文件【{}】失败,请检查目录权限!"
,
file
.
getPath
());
logger
.
error
(
"删除文件【{}】失败,请检查目录权限!"
,
file
.
getPath
());
}
}
return
new
ObjectMapper
().
writeValueAsString
(
new
ReturnResponse
<
String
>(
0
,
"SUCCESS"
,
null
));
return
new
ObjectMapper
().
writeValueAsString
(
ReturnResponse
.
success
(
));
}
}
@RequestMapping
(
value
=
"listFiles"
,
method
=
RequestMethod
.
GET
)
@RequestMapping
(
value
=
"listFiles"
,
method
=
RequestMethod
.
GET
)
...
...
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