Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
sample-form-platform
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
赵啸非
sample-form-platform
Commits
652c438e
Commit
652c438e
authored
Dec 23, 2022
by
赵啸非
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加材料数量统计
parent
9719dba9
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
79 additions
and
6 deletions
+79
-6
sample-form-manager/pom.xml
sample-form-manager/pom.xml
+14
-0
sample-form-manager/src/main/java/com/mortals/xhx/common/utils/WordUtil.java
.../src/main/java/com/mortals/xhx/common/utils/WordUtil.java
+30
-1
sample-form-manager/src/main/java/com/mortals/xhx/module/matter/service/impl/MatterDatumServiceImpl.java
...hx/module/matter/service/impl/MatterDatumServiceImpl.java
+35
-5
No files found.
sample-form-manager/pom.xml
View file @
652c438e
...
@@ -169,6 +169,20 @@
...
@@ -169,6 +169,20 @@
<version>
1.12.0
</version>
<version>
1.12.0
</version>
</dependency>
</dependency>
<dependency>
<groupId>
com.itextpdf
</groupId>
<artifactId>
itext7-core
</artifactId>
<version>
RELEASE
</version>
<type>
pom
</type>
</dependency>
<dependency>
<groupId>
org.apache.pdfbox
</groupId>
<artifactId>
pdfbox
</artifactId>
<version>
2.0.27
</version>
</dependency>
<dependency>
<dependency>
<groupId>
cn.hutool
</groupId>
<groupId>
cn.hutool
</groupId>
<artifactId>
hutool-all
</artifactId>
<artifactId>
hutool-all
</artifactId>
...
...
sample-form-manager/src/main/java/com/mortals/xhx/common/utils/WordUtil.java
View file @
652c438e
...
@@ -10,6 +10,9 @@ import com.mortals.framework.exception.AppException;
...
@@ -10,6 +10,9 @@ import com.mortals.framework.exception.AppException;
import
com.mortals.framework.util.DateUtils
;
import
com.mortals.framework.util.DateUtils
;
import
freemarker.template.Configuration
;
import
freemarker.template.Configuration
;
import
freemarker.template.Template
;
import
freemarker.template.Template
;
import
lombok.extern.apachecommons.CommonsLog
;
import
org.apache.pdfbox.pdmodel.PDDocument
;
import
org.apache.pdfbox.rendering.PDFRenderer
;
import
sun.misc.BASE64Encoder
;
import
sun.misc.BASE64Encoder
;
import
javax.imageio.ImageIO
;
import
javax.imageio.ImageIO
;
...
@@ -20,7 +23,7 @@ import java.io.*;
...
@@ -20,7 +23,7 @@ import java.io.*;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
@CommonsLog
public
class
WordUtil
{
public
class
WordUtil
{
private
Configuration
configure
=
null
;
private
Configuration
configure
=
null
;
...
@@ -137,6 +140,32 @@ public class WordUtil {
...
@@ -137,6 +140,32 @@ public class WordUtil {
}
}
public
static
void
pdfToImages
(
String
filePath
,
String
jpegPath
)
{
log
.
info
(
String
.
format
(
"文件转换开始:%s"
,
DateUtils
.
getCurrStrDateTime
()));
// 转换开始前时间
long
old
=
System
.
currentTimeMillis
();
File
file
=
new
File
(
jpegPath
);
List
<
BufferedImage
>
imageInfoList
=
new
ArrayList
<>();
try
(
PDDocument
doc
=
PDDocument
.
load
(
new
File
(
filePath
)))
{
PDFRenderer
renderer
=
new
PDFRenderer
(
doc
);
int
pageCount
=
doc
.
getNumberOfPages
();
for
(
int
i
=
0
;
i
<
pageCount
;
i
++)
{
BufferedImage
image
=
renderer
.
renderImage
(
i
);
imageInfoList
.
add
(
image
);
}
BufferedImage
mergeImage
=
mergeImage
(
false
,
imageInfoList
);
ImageIO
.
write
(
mergeImage
,
"png"
,
file
);
// 转换结束后时间
long
now
=
System
.
currentTimeMillis
();
//os.close();
log
.
info
(
"文件转换结束,共耗时:"
+
((
now
-
old
)
/
1000.0
)
+
"秒"
);
}
catch
(
IOException
e
)
{
log
.
error
(
"生成预览图片异常:"
,
e
);
throw
new
AppException
(
"生成预览图片异常"
);
}
}
/**
/**
* 合并任数量的图片成一张图片
* 合并任数量的图片成一张图片
*
*
...
...
sample-form-manager/src/main/java/com/mortals/xhx/module/matter/service/impl/MatterDatumServiceImpl.java
View file @
652c438e
...
@@ -80,6 +80,11 @@ public class MatterDatumServiceImpl extends AbstractCRUDServiceImpl<MatterDatumD
...
@@ -80,6 +80,11 @@ public class MatterDatumServiceImpl extends AbstractCRUDServiceImpl<MatterDatumD
@Autowired
@Autowired
private
PubdatumService
pubdatumService
;
private
PubdatumService
pubdatumService
;
public
static
String
word
[]
=
{
"doc"
,
"dot"
,
"wps"
,
"wpt"
,
"docx"
,
"dotx"
,
"docm"
,
"dotm"
};
public
static
String
imgs
[]
=
{
"jpg"
,
"png"
,
"jpeg"
,
"gif"
};
public
static
String
pdf
[]
=
{
"pdf"
};
@Override
@Override
protected
MatterDatumEntity
findBefore
(
MatterDatumEntity
params
,
PageInfo
pageInfo
,
Context
context
)
throws
AppException
{
protected
MatterDatumEntity
findBefore
(
MatterDatumEntity
params
,
PageInfo
pageInfo
,
Context
context
)
throws
AppException
{
if
(!
ObjectUtils
.
isEmpty
(
params
.
getMaterialName
()))
{
if
(!
ObjectUtils
.
isEmpty
(
params
.
getMaterialName
()))
{
...
@@ -151,20 +156,45 @@ public class MatterDatumServiceImpl extends AbstractCRUDServiceImpl<MatterDatumD
...
@@ -151,20 +156,45 @@ public class MatterDatumServiceImpl extends AbstractCRUDServiceImpl<MatterDatumD
}
}
//生成样表预览图片
//生成样表预览图片
String
rootPath
=
this
.
filePath
.
endsWith
(
"/"
)
?
this
.
filePath
:
this
.
filePath
+
"/"
;
String
rootPath
=
this
.
filePath
.
endsWith
(
"/"
)
?
this
.
filePath
:
this
.
filePath
+
"/"
;
String
samplePath
=
rootPath
+
entity
.
getSamplePath
();
String
prePath
=
"file/preview/"
;
String
prePath
=
"file/preview/"
;
String
newName
=
genPreviewPath
(
rootPath
,
prePath
,
entity
.
getSamplePath
());
entity
.
setPreViewPath
(
prePath
+
newName
);
super
.
saveBefore
(
entity
,
context
);
}
private
String
genPreviewPath
(
String
rootPath
,
String
prePath
,
String
tempPath
)
{
//生成样表预览图片
String
samplePath
=
rootPath
+
tempPath
;
String
filePath
=
rootPath
+
prePath
;
String
filePath
=
rootPath
+
prePath
;
File
pathDir
=
new
File
(
filePath
);
File
pathDir
=
new
File
(
filePath
);
if
(!
pathDir
.
exists
())
{
if
(!
pathDir
.
exists
())
{
pathDir
.
mkdirs
();
pathDir
.
mkdirs
();
}
}
String
newName
=
RandomUtil
.
randomNumbers
(
12
)
+
".jpg"
;
String
newName
=
RandomUtil
.
randomNumbers
(
12
)
+
".jpg"
;
String
filePathAll
=
filePath
+
newName
;
String
filePathAll
=
filePath
+
newName
;
WordUtil
.
convertWordToJPEG
(
samplePath
,
filePathAll
);
//判断文件类型是否为doc pdf jpg png 等
entity
.
setPreViewPath
(
prePath
+
newName
);
String
extName
=
FileUtil
.
getSuffix
(
samplePath
);
if
(
this
.
isExsitArry
(
extName
,
word
))
{
WordUtil
.
convertWordToJPEG
(
samplePath
,
filePathAll
);
}
else
if
(
this
.
isExsitArry
(
extName
,
pdf
)){
WordUtil
.
pdfToImages
(
samplePath
,
filePathAll
);
}
else
if
(
this
.
isExsitArry
(
extName
,
imgs
)){
try
{
com
.
mortals
.
framework
.
util
.
FileUtil
.
copyFile
(
samplePath
,
filePathAll
);
}
catch
(
FileNotFoundException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
return
newName
;
}
super
.
saveBefore
(
entity
,
context
);
public
boolean
isExsitArry
(
String
chex
,
String
arry
[])
{
for
(
String
ex
:
arry
)
{
if
(
chex
.
equalsIgnoreCase
(
ex
))
{
return
true
;
}
}
return
false
;
}
}
...
...
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