Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
midjourney-proxy
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
徐少华
midjourney-proxy
Commits
d1217400
Commit
d1217400
authored
Dec 26, 2022
by
李传峰
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:[none] 接口加缓存
parent
82b6dc82
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
85 additions
and
15 deletions
+85
-15
ResourcePageBizImpl.java
...a/com/pcloud/book/group/biz/impl/ResourcePageBizImpl.java
+77
-15
ThreadPoolUtils.java
...ain/java/com/pcloud/book/util/common/ThreadPoolUtils.java
+8
-0
No files found.
pcloud-service-book/src/main/java/com/pcloud/book/group/biz/impl/ResourcePageBizImpl.java
View file @
d1217400
...
@@ -2864,11 +2864,7 @@ public class ResourcePageBizImpl implements ResourcePageBiz {
...
@@ -2864,11 +2864,7 @@ public class ResourcePageBizImpl implements ResourcePageBiz {
amqpTemplate
.
convertAndSend
(
MQTopicProducer
.
EXCHAGE
,
MQTopicProducer
.
MEMBER_ACTIVITY_BOOK_SET
,
memberActivityBookSetDTO
);
amqpTemplate
.
convertAndSend
(
MQTopicProducer
.
EXCHAGE
,
MQTopicProducer
.
MEMBER_ACTIVITY_BOOK_SET
,
memberActivityBookSetDTO
);
}
}
@Override
private
ResourcePageVO
queryResourcePageByBookGroupIdOrSceneId4Wechat
(
Long
bookGroupId
,
Long
wechatUserId
,
Long
sceneId
)
{
public
ResourcePageVO
getResourcePageByBookGroupIdOrSceneId4Wechat
(
Long
bookGroupId
,
Long
wechatUserId
,
Long
sceneId
)
{
if
(
null
==
bookGroupId
&&
null
==
sceneId
)
{
throw
new
BookBizException
(
BookBizException
.
PARAM_IS_NULL
,
"参数缺失"
);
}
Long
bookId
=
null
;
Long
bookId
=
null
;
if
(
null
!=
bookGroupId
)
{
if
(
null
!=
bookGroupId
)
{
bookId
=
resourcePageDao
.
getBookIdByBookGroupId
(
bookGroupId
);
bookId
=
resourcePageDao
.
getBookIdByBookGroupId
(
bookGroupId
);
...
@@ -2928,7 +2924,7 @@ public class ResourcePageBizImpl implements ResourcePageBiz {
...
@@ -2928,7 +2924,7 @@ public class ResourcePageBizImpl implements ResourcePageBiz {
couponVOS
=
couponFuture
.
get
(
ThreadPoolUtils
.
REMOTE_TIME_OUT
,
TimeUnit
.
SECONDS
);
couponVOS
=
couponFuture
.
get
(
ThreadPoolUtils
.
REMOTE_TIME_OUT
,
TimeUnit
.
SECONDS
);
pushTextPermission
=
pushTextFuture
.
get
(
ThreadPoolUtils
.
REMOTE_TIME_OUT
,
TimeUnit
.
SECONDS
);
pushTextPermission
=
pushTextFuture
.
get
(
ThreadPoolUtils
.
REMOTE_TIME_OUT
,
TimeUnit
.
SECONDS
);
}
catch
(
InterruptedException
|
ExecutionException
|
TimeoutException
e
)
{
}
catch
(
InterruptedException
|
ExecutionException
|
TimeoutException
e
)
{
log
.
error
(
"查询实体店铺/优惠券失败"
+
e
.
getMessage
(),
e
);
log
.
error
(
"查询实体店铺/优惠券失败"
+
e
.
getMessage
(),
e
);
}
}
resourcePageVO
.
setResourcePageBookstoreList
(
bookstoreVOS
);
resourcePageVO
.
setResourcePageBookstoreList
(
bookstoreVOS
);
resourcePageVO
.
setResourcePageCouponList
(
couponVOS
);
resourcePageVO
.
setResourcePageCouponList
(
couponVOS
);
...
@@ -2937,6 +2933,37 @@ public class ResourcePageBizImpl implements ResourcePageBiz {
...
@@ -2937,6 +2933,37 @@ public class ResourcePageBizImpl implements ResourcePageBiz {
return
resourcePageVO
;
return
resourcePageVO
;
}
}
@Override
public
ResourcePageVO
getResourcePageByBookGroupIdOrSceneId4Wechat
(
Long
bookGroupId
,
Long
wechatUserId
,
Long
sceneId
)
{
if
(
null
==
bookGroupId
&&
null
==
sceneId
)
{
throw
new
BookBizException
(
BookBizException
.
PARAM_IS_NULL
,
"参数缺失"
);
}
String
cacheKey
=
buildCacheKey
(
"book:getResourcePageByBookGroupIdOrSceneId4Wechat"
,
bookGroupId
,
wechatUserId
,
sceneId
);
ResourcePageVO
result
=
JedisClusterUtils
.
getJson
(
cacheKey
,
ResourcePageVO
.
class
);
if
(
result
==
null
)
{
if
(
JedisClusterUtils
.
lock
(
cacheKey
+
":lock"
,
1
))
{
result
=
queryResourcePageByBookGroupIdOrSceneId4Wechat
(
bookGroupId
,
wechatUserId
,
sceneId
);
JedisClusterUtils
.
setJson
(
cacheKey
,
result
,
600
);
JedisClusterUtils
.
del
(
cacheKey
+
":lock"
);
return
result
;
}
for
(
int
i
=
1
;
i
<
6
;
i
++)
{
ThreadPoolUtils
.
sleep
(
i
*
20
);
result
=
JedisClusterUtils
.
getJson
(
cacheKey
,
ResourcePageVO
.
class
);
if
(
result
!=
null
)
{
return
result
;
}
if
(
i
==
5
)
{
result
=
queryResourcePageByBookGroupIdOrSceneId4Wechat
(
bookGroupId
,
wechatUserId
,
sceneId
);
JedisClusterUtils
.
setJson
(
cacheKey
,
result
,
600
);
break
;
}
}
}
return
result
;
}
@ParamLog
(
"加载企业微信落地页信息"
)
@ParamLog
(
"加载企业微信落地页信息"
)
private
void
fillWxworkPage
(
ResourcePageVO
resourcePageVO
)
{
private
void
fillWxworkPage
(
ResourcePageVO
resourcePageVO
)
{
if
(
resourcePageVO
==
null
||
resourcePageVO
.
getId
()
==
null
){
if
(
resourcePageVO
==
null
||
resourcePageVO
.
getId
()
==
null
){
...
@@ -4243,23 +4270,58 @@ public class ResourcePageBizImpl implements ResourcePageBiz {
...
@@ -4243,23 +4270,58 @@ public class ResourcePageBizImpl implements ResourcePageBiz {
return
false
;
return
false
;
}
}
/**
private
String
buildCacheKey
(
String
prefix
,
Long
...
ids
)
{
* 查询书刊推荐资源
StringBuilder
sb
=
new
StringBuilder
(
prefix
);
*/
for
(
Long
id
:
ids
)
{
@Override
sb
.
append
(
":"
).
append
(
Optional
.
ofNullable
(
id
).
orElse
(
0L
));
public
List
<
RecommendServeVO
>
getBookRecommendServe
(
Long
wechatUserId
,
Long
bookId
,
Long
adviserId
,
Long
channelId
,
Long
sceneId
)
{
}
return
sb
.
toString
();
}
private
List
<
RecommendServeVO
>
queryBookRecommendServe
(
Long
wechatUserId
,
Long
bookId
,
Long
adviserId
,
Long
channelId
,
Long
sceneId
)
{
//1.首先查书刊是否开启了资源推荐
//1.首先查书刊是否开启了资源推荐
OpenRecommendVO
openRecommend
=
getRecommend
(
bookId
,
adviserId
,
channelId
,
sceneId
);
OpenRecommendVO
openRecommend
=
getRecommend
(
bookId
,
adviserId
,
channelId
,
sceneId
);
if
(
null
==
openRecommend
||
null
==
openRecommend
.
getIsOpenRecommend
()
||
0
==
openRecommend
.
getIsOpenRecommend
())
{
if
(
null
==
openRecommend
||
null
==
openRecommend
.
getIsOpenRecommend
()
||
0
==
openRecommend
.
getIsOpenRecommend
())
{
return
null
;
return
null
;
}
}
//2.从系统数据表里面查到推荐资源,填充资源信息
//2.从系统数据表里面查到推荐资源,填充资源信息
List
<
RecommendServeDto
>
serveList
=
bookRecommendBiz
.
getById
(
bookId
,
channelId
,
adviserId
,
openRecommend
.
getRecommendFromType
());
List
<
RecommendServeDto
>
serveList
=
bookRecommendBiz
.
getById
(
bookId
,
channelId
,
adviserId
,
openRecommend
.
getRecommendFromType
());
if
(
CollUtil
.
isEmpty
(
serveList
))
{
if
(
CollUtil
.
isEmpty
(
serveList
))
{
return
null
;
return
null
;
}
}
//3.填充服务信息。以及channel对应的公众号信息
//3.填充服务信息。以及channel对应的公众号信息
List
<
RecommendServeVO
>
result
=
getRecommendServeVOS
(
channelId
,
serveList
);
return
getRecommendServeVOS
(
channelId
,
serveList
);
}
/**
* 查询书刊推荐资源
*/
@Override
public
List
<
RecommendServeVO
>
getBookRecommendServe
(
Long
wechatUserId
,
Long
bookId
,
Long
adviserId
,
Long
channelId
,
Long
sceneId
)
{
String
cacheKey
=
buildCacheKey
(
"book:getBookRecommendServe"
,
wechatUserId
,
bookId
,
adviserId
,
channelId
,
sceneId
);
List
<
RecommendServeVO
>
result
=
JedisClusterUtils
.
getJsonList
(
cacheKey
,
RecommendServeVO
.
class
);
if
(
result
==
null
)
{
if
(
JedisClusterUtils
.
lock
(
cacheKey
+
":lock"
,
1
))
{
result
=
queryBookRecommendServe
(
wechatUserId
,
bookId
,
adviserId
,
channelId
,
sceneId
);
JedisClusterUtils
.
setJsonList
(
cacheKey
,
Optional
.
ofNullable
(
result
).
orElseGet
(
ArrayList:
:
new
),
600
);
JedisClusterUtils
.
del
(
cacheKey
+
":lock"
);
return
result
;
}
for
(
int
i
=
1
;
i
<
6
;
i
++)
{
ThreadPoolUtils
.
sleep
(
i
*
20
);
result
=
JedisClusterUtils
.
getJsonList
(
cacheKey
,
RecommendServeVO
.
class
);
if
(
result
!=
null
)
{
return
result
;
}
if
(
i
==
5
)
{
result
=
queryBookRecommendServe
(
wechatUserId
,
bookId
,
adviserId
,
channelId
,
sceneId
);
JedisClusterUtils
.
setJsonList
(
cacheKey
,
Optional
.
ofNullable
(
result
).
orElseGet
(
ArrayList:
:
new
),
600
);
break
;
}
}
}
return
result
;
return
result
;
}
}
...
...
pcloud-service-book/src/main/java/com/pcloud/book/util/common/ThreadPoolUtils.java
View file @
d1217400
...
@@ -122,6 +122,14 @@ public class ThreadPoolUtils {
...
@@ -122,6 +122,14 @@ public class ThreadPoolUtils {
public
static
final
ExecutorService
BOOK_BASE_INFO_POOL
=
new
ThreadPoolExecutor
(
16
,
128
,
0L
,
TimeUnit
.
SECONDS
,
public
static
final
ExecutorService
BOOK_BASE_INFO_POOL
=
new
ThreadPoolExecutor
(
16
,
128
,
0L
,
TimeUnit
.
SECONDS
,
new
LinkedBlockingQueue
<>(),
new
ThreadFactoryBuilder
().
setNameFormat
(
"book-base-info-pool-%d"
).
build
(),
new
ThreadPoolExecutor
.
CallerRunsPolicy
());
new
LinkedBlockingQueue
<>(),
new
ThreadFactoryBuilder
().
setNameFormat
(
"book-base-info-pool-%d"
).
build
(),
new
ThreadPoolExecutor
.
CallerRunsPolicy
());
public
static
void
sleep
(
int
mills
)
{
try
{
TimeUnit
.
MILLISECONDS
.
sleep
(
mills
);
}
catch
(
InterruptedException
e
)
{
// ignore
}
}
}
}
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