Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
Y
yifu-mvp
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
fangxinjiang
yifu-mvp
Commits
7bd483fd
Commit
7bd483fd
authored
Mar 25, 2026
by
hongguangwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1.7.21-优化临时文件
parent
a77104c7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
33 deletions
+31
-33
TSocialFriendPushServiceImpl.java
...ifu/social/service/impl/TSocialFriendPushServiceImpl.java
+3
-3
ExcelToImage.java
...com/yifu/cloud/plus/v1/yifu/social/util/ExcelToImage.java
+28
-30
No files found.
yifu-social/yifu-social-biz/src/main/java/com/yifu/cloud/plus/v1/yifu/social/service/impl/TSocialFriendPushServiceImpl.java
View file @
7bd483fd
...
@@ -1293,7 +1293,7 @@ public class TSocialFriendPushServiceImpl extends ServiceImpl<TSocialFriendMappe
...
@@ -1293,7 +1293,7 @@ public class TSocialFriendPushServiceImpl extends ServiceImpl<TSocialFriendMappe
String
filePath
=
projectRoot
+
CommonConstants
.
DOUBLE_LINE
+
fileName
;
String
filePath
=
projectRoot
+
CommonConstants
.
DOUBLE_LINE
+
fileName
;
//获取要导出的列表
//获取要导出的列表
List
<
TDispatchSocialPersionExportVo
>
list
=
new
ArrayList
<>();
List
<
TDispatchSocialPersionExportVo
>
list
=
new
ArrayList
<>();
ExcelWriter
excelWriter
=
null
;
//
ExcelWriter excelWriter = null;
File
createFile
=
null
;
File
createFile
=
null
;
try
{
try
{
...
@@ -1379,9 +1379,9 @@ public class TSocialFriendPushServiceImpl extends ServiceImpl<TSocialFriendMappe
...
@@ -1379,9 +1379,9 @@ public class TSocialFriendPushServiceImpl extends ServiceImpl<TSocialFriendMappe
finallyClose
(
null
,
null
,
null
,
inputStream
,
null
,
inStream
,
null
);
finallyClose
(
null
,
null
,
null
,
inputStream
,
null
,
inStream
,
null
);
}
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
if
(
excelWriter
!=
null
)
{
/*
if (excelWriter != null) {
excelWriter.finish();
excelWriter.finish();
}
}
*/
log
.
error
(
"税友附件生成异常"
,
e
);
log
.
error
(
"税友附件生成异常"
,
e
);
return
R
.
failed
(
"税友附件生成异常:"
+
e
.
getMessage
());
return
R
.
failed
(
"税友附件生成异常:"
+
e
.
getMessage
());
}
finally
{
}
finally
{
...
...
yifu-social/yifu-social-biz/src/main/java/com/yifu/cloud/plus/v1/yifu/social/util/ExcelToImage.java
View file @
7bd483fd
...
@@ -53,26 +53,28 @@ public class ExcelToImage {
...
@@ -53,26 +53,28 @@ public class ExcelToImage {
return
R
.
failed
(
CommonConstants
.
RESULT_DATA_FAIL
+
toImagParamError
);
return
R
.
failed
(
CommonConstants
.
RESULT_DATA_FAIL
+
toImagParamError
);
}
}
String
projectRoot
=
System
.
getProperty
(
CommonConstants
.
USER_DIR
);
String
projectRoot
=
System
.
getProperty
(
CommonConstants
.
USER_DIR
);
//加载Excel工作表
File
tempFile
=
null
;
Workbook
wb
=
new
Workbook
();
File
compressedTempFile
=
null
;
wb
.
loadFromHtml
(
inputStream
);
//获取工作表
Worksheet
sheet
=
wb
.
getWorksheets
().
get
(
0
);
//调用方法将Excel工作表保存为图片
sheet
.
saveToImage
(
projectRoot
+
toImag
);
File
file
=
null
;
try
{
try
{
//加载Excel工作表
Workbook
wb
=
new
Workbook
();
wb
.
loadFromHtml
(
inputStream
);
//获取工作表
Worksheet
sheet
=
wb
.
getWorksheets
().
get
(
0
);
String
toImagePath
=
projectRoot
+
toImag
;
sheet
.
saveToImage
(
projectRoot
+
toImag
);
tempFile
=
new
File
(
toImagePath
);
// 上传税友文件服务器,返回文件路径
// 上传税友文件服务器,返回文件路径
file
=
new
File
(
projectRoot
+
toImag
);
if
(
tempFile
.
exists
()){
if
(
file
.
exists
()){
// file 压缩到1M以内
// file 压缩到1M以内
backLog
.
setLogInfo
(
"压缩大小前"
);
backLog
.
setLogInfo
(
"压缩大小前"
);
// 压缩并加章
// 压缩并加章
file
=
compressImage
(
file
,
projectRoot
,
zhangStream
);
tempFile
=
compressImage
(
tempFile
,
projectRoot
,
zhangStream
,
compressedTempFile
);
backLog
.
setLogInfo
(
"压缩大小后"
);
backLog
.
setLogInfo
(
"压缩大小后"
);
String
key
=
System
.
currentTimeMillis
()
+
f
ile
.
getName
();
String
key
=
System
.
currentTimeMillis
()
+
tempF
ile
.
getName
();
byte
[]
fileContent
=
Files
.
readAllBytes
(
f
ile
.
toPath
());
byte
[]
fileContent
=
Files
.
readAllBytes
(
tempF
ile
.
toPath
());
String
base64String
=
Base64
.
getEncoder
().
encodeToString
(
fileContent
);
String
base64String
=
Base64
.
getEncoder
().
encodeToString
(
fileContent
);
backLog
.
setLogInfo
(
"转化为base64String"
);
backLog
.
setLogInfo
(
"转化为base64String"
);
String
url
=
socialFriendConfig
.
uploadPng
(
restTemplate
,
key
,
base64String
,
backLog
);
String
url
=
socialFriendConfig
.
uploadPng
(
restTemplate
,
key
,
base64String
,
backLog
);
...
@@ -80,15 +82,18 @@ public class ExcelToImage {
...
@@ -80,15 +82,18 @@ public class ExcelToImage {
return
R
.
failed
(
CommonConstants
.
RESULT_DATA_FAIL
+
toImagOSSError
);
return
R
.
failed
(
CommonConstants
.
RESULT_DATA_FAIL
+
toImagOSSError
);
}
}
// 上传花名册到阿里云
// 上传花名册到阿里云
this
.
uploadHuaMingCeToOss
(
ossUtil
,
tSocialFriendBackLogService
,
socialId
,
file
.
getName
(),
f
ile
);
this
.
uploadHuaMingCeToOss
(
ossUtil
,
tSocialFriendBackLogService
,
socialId
,
tempFile
.
getName
(),
tempF
ile
);
return
R
.
ok
(
url
);
return
R
.
ok
(
url
);
}
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
return
R
.
failed
(
CommonConstants
.
RESULT_DATA_FAIL
+
toImagConvertError
+
e
.
getMessage
());
return
R
.
failed
(
CommonConstants
.
RESULT_DATA_FAIL
+
toImagConvertError
+
e
.
getMessage
());
}
finally
{
}
finally
{
if
(
file
.
exists
()){
if
(
tempFile
!=
null
&&
tempFile
.
exists
()){
file
.
delete
();
tempFile
.
delete
();
}
if
(
compressedTempFile
!=
null
&&
compressedTempFile
.
exists
()){
compressedTempFile
.
delete
();
}
}
if
(
null
!=
inputStream
){
if
(
null
!=
inputStream
){
try
{
try
{
...
@@ -133,33 +138,26 @@ public class ExcelToImage {
...
@@ -133,33 +138,26 @@ public class ExcelToImage {
}
}
//压缩文件到指定大小
//压缩文件到指定大小
private
File
compressImage
(
File
originalFile
,
String
projectRoot
,
InputStream
zhangStream
)
throws
IOException
{
private
File
compressImage
(
File
originalFile
,
String
projectRoot
,
InputStream
zhangStream
,
File
compressedTempFile
)
throws
IOException
{
BufferedImage
image
=
ImageIO
.
read
(
originalFile
);
BufferedImage
image
=
ImageIO
.
read
(
originalFile
);
// 新: 加盖公章
// 新: 加盖公章
BufferedImage
sealedImage
=
addSealToImage
(
image
,
zhangStream
);
BufferedImage
sealedImage
=
addSealToImage
(
image
,
zhangStream
);
ImageIO
.
write
(
sealedImage
,
"png"
,
originalFile
);
ImageIO
.
write
(
sealedImage
,
"png"
,
originalFile
);
int
quality
=
100
;
// 从100%开始
int
quality
=
100
;
// 从100%开始
File
compressedFile
=
new
File
(
projectRoot
,
TO_IMAGE_TEMP
);
int
maxSize
=
1024
*
1024
;
int
maxSize
=
1024
*
1024
;
try
{
try
{
while
(
originalFile
.
length
()
>
maxSize
&&
quality
>
10
)
{
while
(
originalFile
.
length
()
>
maxSize
&&
quality
>
10
)
{
quality
-=
5
;
quality
-=
5
;
ImageIO
.
write
(
sealedImage
,
"png"
,
compressedFile
);
ImageIO
.
write
(
sealedImage
,
"png"
,
compressed
Temp
File
);
if
(
compressedFile
.
length
()
<
maxSize
)
{
if
(
compressed
Temp
File
.
length
()
<
maxSize
)
{
originalFile
.
delete
();
originalFile
.
delete
();
compressedFile
.
renameTo
(
originalFile
);
compressed
Temp
File
.
renameTo
(
originalFile
);
break
;
break
;
}
}
compressedFile
.
delete
();
compressed
Temp
File
.
delete
();
}
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
if
(
compressedFile
!=
null
&&
compressedFile
.
exists
())
{
throw
e
;
compressedFile
.
delete
();
}
}
finally
{
if
(
compressedFile
!=
null
&&
compressedFile
.
exists
())
{
compressedFile
.
delete
();
}
}
}
return
originalFile
;
return
originalFile
;
}
}
...
...
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