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
f7080489
Commit
f7080489
authored
May 29, 2025
by
hongguangwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MVP1.7.11-是否自动生成解除劳动合同书 0否1是
parent
ea5bbb2b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
3 additions
and
51 deletions
+3
-51
ExcelToImage.java
...com/yifu/cloud/plus/v1/yifu/social/util/ExcelToImage.java
+3
-51
No files found.
yifu-social/yifu-social-biz/src/main/java/com/yifu/cloud/plus/v1/yifu/social/util/ExcelToImage.java
View file @
f7080489
...
...
@@ -69,7 +69,7 @@ public class ExcelToImage {
if
(
file
.
exists
()){
// file 压缩到1M以内
backLog
.
setLogInfo
(
"压缩大小前"
);
file
=
compressImage
(
projectRoot
,
toImag
,
1024
*
1024
);
file
=
compressImage
(
file
,
projectRoot
);
backLog
.
setLogInfo
(
"压缩大小后"
);
String
key
=
System
.
currentTimeMillis
()
+
file
.
getName
();
byte
[]
fileContent
=
Files
.
readAllBytes
(
file
.
toPath
());
...
...
@@ -99,11 +99,11 @@ public class ExcelToImage {
return
R
.
failed
(
CommonConstants
.
RESULT_DATA_FAIL
);
}
//压缩文件到指定大小
/*private File compressImage(String projectRoot, String toImag, int maxSize) throws IOException {
File originalFile = Paths.get(projectRoot, toImag).toFile();
private
File
compressImage
(
File
originalFile
,
String
projectRoot
)
throws
IOException
{
BufferedImage
image
=
ImageIO
.
read
(
originalFile
);
int
quality
=
100
;
// 从100%开始
File
compressedFile
=
new
File
(
projectRoot
,
TO_IMAGE_TEMP
);
int
maxSize
=
1024
*
1024
;
while
(
originalFile
.
length
()
>
maxSize
&&
quality
>
10
)
{
quality
-=
5
;
ImageIO
.
write
(
image
,
"png"
,
compressedFile
);
...
...
@@ -115,54 +115,6 @@ public class ExcelToImage {
compressedFile
.
delete
();
}
return
originalFile
;
}*/
private
File
compressImage
(
String
projectRoot
,
String
toImag
,
int
maxSize
)
throws
IOException
{
File
originalFile
=
Paths
.
get
(
projectRoot
,
toImag
).
toFile
();
BufferedImage
image
=
ImageIO
.
read
(
originalFile
);
// 使用 jpg 格式以便控制压缩质量
String
format
=
"jpg"
;
File
compressedFile
=
new
File
(
projectRoot
,
TO_IMAGE_TEMP
);
float
quality
=
0.9f
;
// 初始压缩质量 (0.0-1.0)
try
(
ByteArrayOutputStream
byteArrayOutputStream
=
new
ByteArrayOutputStream
())
{
ImageWriter
writer
=
findImageWriter
(
format
);
ImageWriteParam
writeParam
=
writer
.
getDefaultWriteParam
();
writeParam
.
setCompressionMode
(
ImageWriteParam
.
MODE_EXPLICIT
);
writeParam
.
setCompressionQuality
(
quality
);
ImageOutputStream
imageOutputStream
=
ImageIO
.
createImageOutputStream
(
compressedFile
);
writer
.
setOutput
(
imageOutputStream
);
writer
.
write
(
null
,
new
IIOImage
(
image
,
null
,
null
),
writeParam
);
writer
.
dispose
();
imageOutputStream
.
close
();
// 如果压缩后仍超过限制,递归降低质量重新压缩
if
(
compressedFile
.
length
()
>
maxSize
&&
quality
>
0.1
)
{
quality
-=
0.1f
;
return
compressImage
(
projectRoot
,
toImag
,
maxSize
);
// 递归压缩
}
}
// 替换原始文件
if
(
compressedFile
.
exists
())
{
originalFile
.
delete
();
compressedFile
.
renameTo
(
originalFile
);
}
return
originalFile
;
}
// 查找可用的 ImageWriter
private
ImageWriter
findImageWriter
(
String
format
)
{
Iterator
<
ImageWriter
>
writers
=
ImageIO
.
getImageWritersByFormatName
(
format
);
if
(!
writers
.
hasNext
())
{
throw
new
IllegalStateException
(
"No ImageWriter found for format: "
+
format
);
}
return
writers
.
next
();
}
public
R
<
URL
>
excelToImg
(
InputStream
inputStream
,
OSSUtil
ossUtil
){
...
...
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