Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
H
haoban-manage3.0
Overview
Overview
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
haoban3.0
haoban-manage3.0
Commits
b50c4961
Commit
b50c4961
authored
Apr 26, 2023
by
root
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'bugfix_0426_share_time' into test_branch
parents
efff1473
847910eb
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
90 additions
and
42 deletions
+90
-42
pom.xml
haoban-manage3-service/pom.xml
+5
-0
MaterialShareLogApiServiceImpl.java
...vice/out/impl/content/MaterialShareLogApiServiceImpl.java
+2
-17
DrawImageUtils.java
...va/com/gic/haoban/manage/service/util/DrawImageUtils.java
+83
-25
No files found.
haoban-manage3-service/pom.xml
View file @
b50c4961
...
...
@@ -196,6 +196,11 @@
<artifactId>
gic-order-api
</artifactId>
<version>
${gic-order-api}
</version>
</dependency>
<dependency>
<groupId>
com.freewayso
</groupId>
<artifactId>
image-combiner
</artifactId>
<version>
2.6.3
</version>
</dependency>
</dependencies>
<build>
...
...
haoban-manage3-service/src/main/java/com/gic/haoban/manage/service/service/out/impl/content/MaterialShareLogApiServiceImpl.java
View file @
b50c4961
...
...
@@ -124,7 +124,7 @@ public class MaterialShareLogApiServiceImpl implements MaterialShareLogApiServic
try
{
URL
url
=
new
URL
(
materialConvertDTO
.
getQrCodeUrl
());
InputStream
inputStream
=
url
.
openStream
();
byteArrayOutputStream
=
cloneInputStream
(
inputStream
);
byteArrayOutputStream
=
DrawImageUtils
.
cloneInputStream
(
inputStream
);
}
catch
(
Exception
ex
)
{
log
.
info
(
"获取二维码流对象异常 qrCodeUrl:{}"
,
materialConvertDTO
.
getQrCodeUrl
());
return
ServiceResponse
.
failure
(
"-701"
,
"系统异常"
);
...
...
@@ -136,7 +136,7 @@ public class MaterialShareLogApiServiceImpl implements MaterialShareLogApiServic
List
<
String
>
imageUrls
=
materialConvertDTO
.
getImageUrls
()
.
parallelStream
()
.
map
(
item
->
DrawImageUtils
.
addWater
(
enterpriseDTO
.
getFactoryCode
(),
item
,
new
ByteArrayInputStream
(
finalByteArrayOutputStream
.
toByteArray
())))
.
map
(
item
->
DrawImageUtils
.
addWater
New
(
enterpriseDTO
.
getFactoryCode
(),
item
,
new
ByteArrayInputStream
(
finalByteArrayOutputStream
.
toByteArray
())))
.
collect
(
Collectors
.
toList
());
List
<
String
>
materialIds
=
imageUrls
.
parallelStream
()
.
map
(
item
->
{
...
...
@@ -154,19 +154,4 @@ public class MaterialShareLogApiServiceImpl implements MaterialShareLogApiServic
.
collect
(
Collectors
.
toList
());
return
ServiceResponse
.
success
(
materialIds
);
}
private
static
ByteArrayOutputStream
cloneInputStream
(
InputStream
input
)
{
try
{
ByteArrayOutputStream
baos
=
new
ByteArrayOutputStream
();
byte
[]
buffer
=
new
byte
[
1024
];
int
len
;
while
((
len
=
input
.
read
(
buffer
))
>
-
1
)
{
baos
.
write
(
buffer
,
0
,
len
);
}
baos
.
flush
();
return
baos
;
}
catch
(
Exception
e
)
{
return
null
;
}
}
}
haoban-manage3-service/src/main/java/com/gic/haoban/manage/service/util/DrawImageUtils.java
View file @
b50c4961
package
com
.
gic
.
haoban
.
manage
.
service
.
util
;
import
com.alibaba.fastjson.JSON
;
import
com.freewayso.image.combiner.ImageCombiner
;
import
com.freewayso.image.combiner.enums.OutputFormat
;
import
com.freewayso.image.combiner.enums.ZoomMode
;
import
com.gic.api.base.commons.ServiceResponse
;
import
com.gic.thirdparty.cloudfile.CloudFileUtil
;
import
com.gic.thirdparty.cloudfile.enums.CloudFileBusinessOptEnum
;
import
com.gic.thirdparty.cloudfile.enums.CloudFileTypeEnum
;
...
...
@@ -14,6 +18,7 @@ import javax.imageio.ImageIO;
import
java.awt.*
;
import
java.awt.geom.Ellipse2D
;
import
java.awt.image.BufferedImage
;
import
java.io.ByteArrayInputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
...
...
@@ -104,17 +109,6 @@ public class DrawImageUtils {
return
null
;
}
static
InputStream
inputStream
=
null
;
static
{
try
{
URL
url
=
new
URL
(
"https://gicinner-1251519181.cos.ap-shanghai.myqcloud.com/image/material_content-80819999f96f448d9fcccb5ac86e6c37.png"
);
inputStream
=
url
.
openStream
();
}
catch
(
Exception
ex
)
{
}
}
/***
* 二维码合成
...
...
@@ -185,6 +179,45 @@ public class DrawImageUtils {
return
url
;
}
public
static
String
addWaterNew
(
String
factoryCode
,
String
url
,
InputStream
qrCodeInputStream
)
{
// 读取原图片信息
//文件转化为图片
try
{
BufferedImage
qrCodeBufferedImage
=
ImageIO
.
read
(
qrCodeInputStream
);
long
startTime
=
System
.
currentTimeMillis
();
ImageCombiner
imageCombiner
=
new
ImageCombiner
(
url
,
OutputFormat
.
JPG
);
int
srcImgWidth
=
imageCombiner
.
getCanvasWidth
();
int
srcImgHeight
=
imageCombiner
.
getCanvasHeight
();
log
.
info
(
"图片宽度:{}, 图片高度:{}"
,
srcImgWidth
,
srcImgHeight
);
if
(
srcImgHeight
>
2000
)
{
log
.
info
(
"原图片高度超过2000 高度:{}, 等比压缩"
,
srcImgHeight
);
// 按高度等比压缩
srcImgHeight
=
2000
;
imageCombiner
=
new
ImageCombiner
(
url
,
0
,
srcImgHeight
,
ZoomMode
.
Height
,
OutputFormat
.
JPG
);
srcImgWidth
=
imageCombiner
.
getCanvasWidth
();
log
.
warn
(
"转换后实际的宽: {}, 高:{}"
,
imageCombiner
.
getCanvasWidth
(),
imageCombiner
.
getCanvasHeight
());
}
log
.
info
(
"转换后图片宽度:{}, 图片高度:{}"
,
srcImgWidth
,
srcImgHeight
);
// 计算二维码宽度
int
qrCodeWidthTemp
=
srcImgWidth
*
136
/
750
;
log
.
info
(
"二维码计算后的宽度 {}"
,
qrCodeWidthTemp
);
imageCombiner
.
addImageElement
(
qrCodeBufferedImage
,
srcImgWidth
-
(
qrCodeWidthTemp
+
20
),
srcImgHeight
-
(
qrCodeWidthTemp
+
20
),
qrCodeWidthTemp
,
qrCodeWidthTemp
,
ZoomMode
.
Height
);
imageCombiner
.
combine
();
InputStream
combinedImageStream
=
imageCombiner
.
getCombinedImageStream
();
log
.
info
(
"合成之后的大小 {}"
,
combinedImageStream
.
available
());
CloudFileInfo
cloudFileInfo
=
CloudFileUtil
.
uploadFile
(
combinedImageStream
,
"jpg"
,
CloudFileTypeEnum
.
IMAGE
,
factoryCode
,
CloudFileBusinessOptEnum
.
HAOBAN_COMMON
);
log
.
info
(
"上传图片结果:{}"
,
JSON
.
toJSONString
(
cloudFileInfo
));
long
endTime
=
System
.
currentTimeMillis
();
log
.
info
(
"合成图片耗时 {} 秒"
,
(
endTime
-
startTime
)
/
1000
);
if
(
cloudFileInfo
!=
null
)
{
return
cloudFileInfo
.
getOrgFileUrl
();
}
}
catch
(
Exception
ex
)
{
log
.
info
(
"处理图片发生异常"
,
ex
);
}
return
url
;
}
public
static
BufferedImage
resize
(
Image
img
,
int
h
,
int
w
,
boolean
clip
)
throws
IOException
{
//参数是TYPE_3BYTE_BGR时,图片最清晰!
BufferedImage
image
=
new
BufferedImage
(
w
,
h
,
BufferedImage
.
TYPE_4BYTE_ABGR
);
...
...
@@ -204,23 +237,48 @@ public class DrawImageUtils {
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
try
{
URL
url
=
new
URL
(
"https://gicinner-1251519181.cos.ap-shanghai.myqcloud.com/image/material_content-80819999f96f448d9fcccb5ac86e6c37.png"
);
inputStream
=
url
.
openStream
();
}
catch
(
Exception
ex
)
{
}
String
qrcodeUrl
=
"https://gicinner-1251519181.cos.ap-shanghai.myqcloud.com/image/material_content-80819999f96f448d9fcccb5ac86e6c37.png"
;
String
url
=
"https://jhdm-1251519181.cos.ap-shanghai.myqcloud.com/image/material_content-7c3bc8061ffb4e2694c0e288a1ce176b.jpeg?imageView2/format/jpg/q/50"
;
//String url = "https://newdmwltest-1251519181.cos.ap-shanghai.myqcloud.com/image/material_content-bd89447576b5438d8045def2da2c4c0f.jpg?imageView2/format/jpg/q/50";
System
.
setProperty
(
"gic.module.name"
,
"haoban-manage3-service"
);
DrawImageUtils
.
addWater
(
"jhdm"
,
url
,
inputStream
);
// Random random = new Random();
// String url = DrawImageUtils.drawImage("jhdm", Math.abs(random.nextInt(1000)) + "",
// Math.abs(random.nextInt(1000)) + "万", DrawBkgImg.AREA_MONTH_BKG);
// System.out.println(url);
//
// String temp = DrawImageUtils.drawImage("jhdm", Math.abs(random.nextInt(1000)) + "",
// Math.abs(random.nextInt(1000)) + "万", DrawBkgImg.CLERK_MONTH_BKG);
// System.out.println(temp);
ByteArrayOutputStream
byteArrayOutputStream
=
null
;
try
{
URL
openUrl
=
new
URL
(
qrcodeUrl
);
InputStream
inputStream
=
openUrl
.
openStream
();
byteArrayOutputStream
=
cloneInputStream
(
inputStream
);
}
catch
(
Exception
ex
)
{
log
.
info
(
"获取二维码流对象异常 qrCodeUrl:{}"
,
ex
);
}
if
(
byteArrayOutputStream
==
null
)
{
return
;
}
for
(
int
i
=
0
;
i
<
30
;
i
++)
{
System
.
out
.
println
(
DrawImageUtils
.
addWaterNew
(
"jhdm"
,
url
,
new
ByteArrayInputStream
(
byteArrayOutputStream
.
toByteArray
())));
}
}
/**
* inputStrean 拷贝
* @param input
* @return
*/
public
static
ByteArrayOutputStream
cloneInputStream
(
InputStream
input
)
{
try
{
ByteArrayOutputStream
baos
=
new
ByteArrayOutputStream
();
byte
[]
buffer
=
new
byte
[
1024
];
int
len
;
while
((
len
=
input
.
read
(
buffer
))
>
-
1
)
{
baos
.
write
(
buffer
,
0
,
len
);
}
baos
.
flush
();
return
baos
;
}
catch
(
Exception
ex
)
{
log
.
info
(
"stream 拷贝异常"
,
ex
);
return
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