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
dde171dc
Commit
dde171dc
authored
Oct 29, 2024
by
王祖波
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
使用线程池处理
parent
3cbb61d3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
12 deletions
+47
-12
ImageCombined.java
...haoban/manage/service/context/combined/ImageCombined.java
+30
-5
MaterialApiServiceImpl.java
...nage/service/service/out/impl/MaterialApiServiceImpl.java
+17
-7
No files found.
haoban-manage3-service/src/main/java/com/gic/haoban/manage/service/context/combined/ImageCombined.java
View file @
dde171dc
package
com
.
gic
.
haoban
.
manage
.
service
.
context
.
combined
;
import
com.gic.haoban.manage.api.qdto.combined.CombinedQDTO
;
import
com.gic.haoban.manage.service.context.chat.BusinessManager
;
import
com.github.benmanes.caffeine.cache.Cache
;
import
com.github.benmanes.caffeine.cache.Caffeine
;
import
net.coobird.thumbnailator.Thumbnails
;
...
...
@@ -18,6 +17,8 @@ import java.io.File;
import
java.io.IOException
;
import
java.net.URL
;
import
java.util.Iterator
;
import
java.util.concurrent.ArrayBlockingQueue
;
import
java.util.concurrent.ThreadPoolExecutor
;
import
java.util.concurrent.TimeUnit
;
/**
...
...
@@ -33,6 +34,15 @@ public class ImageCombined {
.
expireAfterAccess
(
30
,
TimeUnit
.
MINUTES
)
// 可设置失效时间
.
build
();
public
static
final
ThreadPoolExecutor
EXECUTOR
=
new
ThreadPoolExecutor
(
20
,
50
,
60L
,
TimeUnit
.
SECONDS
,
new
ArrayBlockingQueue
<>(
100
),
new
ThreadPoolExecutor
.
AbortPolicy
()
);
public
static
final
String
IMAGE_REDIS_KEY
=
"haoban-manage3-service:combined_image:"
;
private
static
final
int
MAX_HEIGHT_NO_WHITE_SPACE
=
1500
;
...
...
@@ -44,8 +54,8 @@ public class ImageCombined {
private
static
final
String
LARGE_IMAGE_URL
=
"https://jhdmyx-1251519181.cos.ap-shanghai.myqcloud.com/image/material_content-191564494842458980f5c5ae685d3440.jpg?imageView2/2/w/1080/h/10800/format/jpg"
;
private
static
final
String
QR_CODE_URL
=
"https://gicinner-1251519181.cos.ap-shanghai.myqcloud.com/image/material_content-4ffc77073ca1476fb264bf1be9f11383.png"
;
private
static
final
String
STORE_NAME
=
"门店CCA"
;
private
static
final
String
GUIDE_NAME
=
"宇智222为您推荐"
;
private
static
final
String
STORE_NAME
=
"门店CCA
门店CCA门店CCA门店CCA门店CCA门店CCA
"
;
private
static
final
String
GUIDE_NAME
=
"宇智222为您推荐
门店CCA门店CCA门店CCA门店CCA门店CCA
"
;
private
static
final
String
OUTPUT_PATH
=
"/Users/wang/Downloads/output_image5.jpg"
;
static
{
...
...
@@ -174,16 +184,31 @@ public class ImageCombined {
// 添加门店名称,距底部88px
g
.
setColor
(
new
Color
(
36
,
40
,
53
));
g
.
setFont
(
new
Font
(
"Arial"
,
Font
.
PLAIN
,
30
));
g
.
drawString
(
lineOne
,
30
,
finalHeight
-
WHITE_SPACE_HEIGHT
+
72
);
drawSingleLineText
(
g
,
lineOne
,
30
,
finalHeight
-
WHITE_SPACE_HEIGHT
+
72
,
width
-
196
);
// 留出左右边距
// 添加推荐人信息,距底部40px
g
.
setColor
(
new
Color
(
151
,
155
,
165
));
g
.
setFont
(
new
Font
(
"Arial"
,
Font
.
PLAIN
,
26
));
g
.
drawString
(
lineTwo
,
30
,
finalHeight
-
WHITE_SPACE_HEIGHT
+
120
);
drawSingleLineText
(
g
,
lineTwo
,
30
,
finalHeight
-
WHITE_SPACE_HEIGHT
+
120
,
width
-
196
);
// 留出左右边距
// 添加二维码,距底部12px
int
qrBottomPadding
=
12
;
g
.
drawImage
(
qrCode
,
width
-
qrWidth
-
qrBottomPadding
,
finalHeight
-
qrWidth
-
qrBottomPadding
,
null
);
}
private
static
void
drawSingleLineText
(
Graphics2D
g
,
String
text
,
int
x
,
int
y
,
int
maxWidth
)
{
FontMetrics
metrics
=
g
.
getFontMetrics
(
g
.
getFont
());
String
truncatedText
=
text
;
// 计算文本宽度并进行截断
if
(
metrics
.
stringWidth
(
text
)
>
maxWidth
)
{
while
(
metrics
.
stringWidth
(
truncatedText
+
"..."
)
>
maxWidth
&&
!
truncatedText
.
isEmpty
())
{
truncatedText
=
truncatedText
.
substring
(
0
,
truncatedText
.
length
()
-
2
);
}
truncatedText
+=
"..."
;
// 添加省略号
}
g
.
drawString
(
truncatedText
,
x
,
y
);
}
}
haoban-manage3-service/src/main/java/com/gic/haoban/manage/service/service/out/impl/MaterialApiServiceImpl.java
View file @
dde171dc
...
...
@@ -6,6 +6,7 @@ import java.util.Collections;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.concurrent.Future
;
import
java.util.concurrent.TimeUnit
;
import
java.util.function.Function
;
import
java.util.stream.Collectors
;
...
...
@@ -530,13 +531,22 @@ public class MaterialApiServiceImpl implements MaterialApiService {
if
(
StringUtils
.
isNotBlank
(
cache
))
{
return
com
.
gic
.
api
.
base
.
commons
.
ServiceResponse
.
success
(
cache
);
}
JSONResponse
json
=
materialService
.
getMaterialIdByCombined
(
wxEnterpriseId
,
combinedQDTO
);
if
(
json
.
getErrorCode
()
==
0
)
{
String
mediaId
=
json
.
getResult
().
toString
()
;
RedisUtil
.
setCache
(
key
,
mediaId
,
1L
,
TimeUnit
.
DAYS
);
return
com
.
gic
.
api
.
base
.
commons
.
ServiceResponse
.
success
(
mediaId
)
;
}
else
{
return
com
.
gic
.
api
.
base
.
commons
.
ServiceResponse
.
failure
(
"9999"
,
json
.
getErrorMessage
())
;
Future
<
JSONResponse
>
future
=
null
;
JSONResponse
json
=
null
;
try
{
future
=
ImageCombined
.
EXECUTOR
.
submit
(()
->
materialService
.
getMaterialIdByCombined
(
wxEnterpriseId
,
combinedQDTO
));
json
=
future
.
get
();
if
(
json
.
getErrorCode
()
==
0
)
{
String
mediaId
=
json
.
getResult
().
toString
()
;
RedisUtil
.
setCache
(
key
,
mediaId
,
1L
,
TimeUnit
.
DAYS
);
return
com
.
gic
.
api
.
base
.
commons
.
ServiceResponse
.
success
(
mediaId
)
;
}
else
{
return
com
.
gic
.
api
.
base
.
commons
.
ServiceResponse
.
failure
(
"9999"
,
json
.
getErrorMessage
())
;
}
}
catch
(
Exception
e
)
{
logger
.
info
(
"获取素材id失败"
,
e
);
return
com
.
gic
.
api
.
base
.
commons
.
ServiceResponse
.
failure
(
"9999"
,
"获取图片,请稍后再试"
);
}
}
}
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