Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yanxuan-wx-store-sharer
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
wx
yanxuan-wx-store-sharer
Commits
2def4d75
Commit
2def4d75
authored
Mar 14, 2025
by
fanjiaxin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
联调问题处理
parent
3cc33c49
Pipeline
#71642
passed with stages
in 1 minute 12 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
64 deletions
+31
-64
ExecutorConfig.java
...se/yanxuan/wx/store/sharer/biz/config/ExecutorConfig.java
+0
-53
ProductServiceImpl.java
.../wx/store/sharer/biz/service/impl/ProductServiceImpl.java
+24
-8
CoreConstant.java
...yanxuan/wx/store/sharer/common/constant/CoreConstant.java
+7
-2
SharerInfo.java
...yanxuan/wx/store/sharer/dal/meta/model/po/SharerInfo.java
+0
-1
No files found.
yanxuan-wx-store-sharer-biz/src/main/java/com/netease/yanxuan/wx/store/sharer/biz/config/ExecutorConfig.java
deleted
100644 → 0
View file @
3cc33c49
package
com
.
netease
.
yanxuan
.
wx
.
store
.
sharer
.
biz
.
config
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.scheduling.annotation.EnableAsync
;
import
org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor
;
import
java.util.concurrent.Executor
;
import
java.util.concurrent.ThreadPoolExecutor
;
/**
* 线程池配置类
*
* @author fanjiaxin
* @date 2024/6/12 15:55
*/
@Slf4j
@Configuration
@EnableAsync
public
class
ExecutorConfig
{
/**
* 异步线程池
*/
@Bean
(
name
=
"asyncProductListServiceExecutor"
)
public
Executor
asyncProductListServiceExecutor
()
{
log
.
info
(
"start asyncProductListServiceExecutor..."
);
ThreadPoolTaskExecutor
executor
=
new
ThreadPoolTaskExecutor
();
//配置核心线程数
executor
.
setCorePoolSize
(
10
);
//配置最大线程数
executor
.
setMaxPoolSize
(
20
);
//配置队列大小
executor
.
setQueueCapacity
(
500
);
//线程空闲时间
executor
.
setKeepAliveSeconds
(
30
);
//配置线程池中的线程的名称前缀
executor
.
setThreadNamePrefix
(
"async-product-list-service-executor-"
);
/**
* rejection-policy:当pool已经达到max size的时候,如何处理新任务
* CALLER_RUNS:不在新线程中执行任务,而是有调用者所在的线程来执行
*/
executor
.
setRejectedExecutionHandler
(
new
ThreadPoolExecutor
.
CallerRunsPolicy
());
//等待所有任务完成再关闭
executor
.
setWaitForTasksToCompleteOnShutdown
(
true
);
//最长等待时间,秒
executor
.
setAwaitTerminationSeconds
(
60
);
//初始化执行器
executor
.
initialize
();
return
executor
;
}
}
yanxuan-wx-store-sharer-biz/src/main/java/com/netease/yanxuan/wx/store/sharer/biz/service/impl/ProductServiceImpl.java
View file @
2def4d75
package
com
.
netease
.
yanxuan
.
wx
.
store
.
sharer
.
biz
.
service
.
impl
;
import
com.alibaba.fastjson.JSON
;
import
com.netease.yanxuan.wx.store.sharer.biz.config.DrmSharerConfig
;
import
com.netease.yanxuan.wx.store.sharer.biz.core.LoginUserContextHolder
;
import
com.netease.yanxuan.wx.store.sharer.biz.core.LoginUserInfo
;
...
...
@@ -8,7 +9,9 @@ import com.netease.yanxuan.wx.store.sharer.biz.meta.model.vo.ProductPromotionLin
import
com.netease.yanxuan.wx.store.sharer.biz.meta.page.PageQuery
;
import
com.netease.yanxuan.wx.store.sharer.biz.meta.page.PageVO
;
import
com.netease.yanxuan.wx.store.sharer.biz.service.IProductService
;
import
com.netease.yanxuan.wx.store.sharer.common.constant.CoreConstant
;
import
com.netease.yanxuan.wx.store.sharer.common.exception.NoBindSharerException
;
import
com.netease.yanxuan.wx.store.sharer.common.handler.RedisClient
;
import
com.netease.yanxuan.wx.store.sharer.common.util.AsyncUtils
;
import
com.netease.yanxuan.wx.store.sharer.integration.constant.WeChatApi
;
import
com.netease.yanxuan.wx.store.sharer.integration.handler.impl.WeChatShopPromoteProductDetailRequest
;
...
...
@@ -29,7 +32,6 @@ import java.util.List;
import
java.util.Objects
;
import
java.util.Optional
;
import
java.util.stream.Collectors
;
import
java.util.concurrent.Executor
;
/**
* @Description 商品-业务实现类
...
...
@@ -45,7 +47,7 @@ public class ProductServiceImpl implements IProductService {
private
final
WeChatShopPromoteProductLinkRequest
weChatShopPromoteProductLinkRequest
;
private
final
WeChatShopSharerListRequest
weChatShopSharerListRequest
;
private
final
DrmSharerConfig
drmSharerConfig
;
private
final
Executor
asyncProductListServiceExecutor
;
private
final
RedisClient
redisClient
;
@Override
...
...
@@ -58,11 +60,7 @@ public class ProductServiceImpl implements IProductService {
if
(!
CollectionUtils
.
isEmpty
(
productListVO
.
getProduct_list
()))
{
// 使用异步多线程处理
List
<
ProductListVO
>
productList
=
AsyncUtils
.
processListAsync
(
productListVO
.
getProduct_list
(),
item
->
{
WeChatPromoteProductDetailVO
detailVO
=
weChatShopPromoteProductDetailRequest
.
handle
(
item
.
getShop_appid
(),
Long
.
valueOf
(
item
.
getProduct_id
()));
if
(
null
==
detailVO
)
{
return
null
;
}
WeChatPromoteProductDetailVO
detailVO
=
getProductDetailCache
(
item
.
getShop_appid
(),
item
.
getProduct_id
());
WeChatPromoteProductDetailVO
.
WeChatPromoteProductVO
product
=
detailVO
.
getProduct
();
if
(
null
==
product
)
{
return
null
;
...
...
@@ -122,7 +120,7 @@ public class ProductServiceImpl implements IProductService {
listVO
.
setProductId
(
item
.
getProduct_id
());
listVO
.
setProductPromotionLink
(
productInfo
.
getProduct_promotion_link
());
return
listVO
;
}
,
asyncProductListServiceExecutor
);
});
// 过滤空
productList
=
Optional
.
of
(
productList
).
orElseGet
(
ArrayList:
:
new
)
.
stream
()
...
...
@@ -154,4 +152,22 @@ public class ProductServiceImpl implements IProductService {
}
return
null
;
}
/**
* 获取商品详情,并缓存到redis中
*/
private
WeChatPromoteProductDetailVO
getProductDetailCache
(
String
shopAppid
,
String
productId
)
{
WeChatPromoteProductDetailVO
detailVO
;
String
productDetailKey
=
CoreConstant
.
REDIS_PRODUCT_DETAIL_KEY
+
shopAppid
+
"&"
+
productId
;
String
productDetailJson
=
redisClient
.
getStr
(
productDetailKey
);
if
(
StringUtils
.
isBlank
(
productDetailJson
))
{
detailVO
=
weChatShopPromoteProductDetailRequest
.
handle
(
shopAppid
,
Long
.
valueOf
(
productId
));
if
(
null
!=
detailVO
)
{
redisClient
.
setStr
(
productDetailKey
,
JSON
.
toJSONString
(
detailVO
),
CoreConstant
.
REDIS_PRODUCT_DETAIL_EXPIRE_SECONDS
);
}
}
else
{
detailVO
=
JSON
.
parseObject
(
productDetailJson
,
WeChatPromoteProductDetailVO
.
class
);
}
return
detailVO
;
}
}
yanxuan-wx-store-sharer-common/src/main/java/com/netease/yanxuan/wx/store/sharer/common/constant/CoreConstant.java
View file @
2def4d75
...
...
@@ -56,7 +56,12 @@ public interface CoreConstant {
int
REDIS_TOKEN_WECHAT_SHOP_LOCK_TIME
=
5
;
/**
* Redis商品详情
ID
缓存KEY
* Redis商品详情缓存KEY
*/
String
REDIS_PRODUCT_DETAIL_ID_KEY
=
"PRODUCT:DETAIL:ID:KEY"
;
String
REDIS_PRODUCT_DETAIL_KEY
=
"PRODUCT:DETAIL:"
;
/**
* Redis商品详情过期时间,秒
*/
int
REDIS_PRODUCT_DETAIL_EXPIRE_SECONDS
=
6
*
60
*
60
;
}
yanxuan-wx-store-sharer-dal/src/main/java/com/netease/yanxuan/wx/store/sharer/dal/meta/model/po/SharerInfo.java
View file @
2def4d75
...
...
@@ -6,7 +6,6 @@ import com.baomidou.mybatisplus.annotation.TableName;
import
lombok.Data
;
import
java.io.Serializable
;
import
java.math.BigDecimal
;
import
java.math.BigInteger
;
import
java.util.Date
;
...
...
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