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
7be53995
Commit
7be53995
authored
Mar 14, 2025
by
fanjiaxin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
联调问题处理
parent
209b97f8
Pipeline
#71594
passed with stages
in 1 minute 6 seconds
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
88 additions
and
9 deletions
+88
-9
ProductServiceImpl.java
.../wx/store/sharer/biz/service/impl/ProductServiceImpl.java
+16
-9
AsyncUtils.java
...tease/yanxuan/wx/store/sharer/common/util/AsyncUtils.java
+72
-0
No files found.
yanxuan-wx-store-sharer-biz/src/main/java/com/netease/yanxuan/wx/store/sharer/biz/service/impl/ProductServiceImpl.java
View file @
7be53995
...
...
@@ -3,12 +3,13 @@ package com.netease.yanxuan.wx.store.sharer.biz.service.impl;
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
;
import
com.netease.yanxuan.wx.store.sharer.common.exception.NoBindSharerException
;
import
com.netease.yanxuan.wx.store.sharer.biz.meta.model.vo.ProductListVO
;
import
com.netease.yanxuan.wx.store.sharer.biz.meta.model.vo.ProductPromotionLinkVO
;
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.exception.NoBindSharerException
;
import
com.netease.yanxuan.wx.store.sharer.common.util.AsyncUtils
;
import
com.netease.yanxuan.wx.store.sharer.integration.handler.impl.WeChatShopPromoteProductDetailRequest
;
import
com.netease.yanxuan.wx.store.sharer.integration.handler.impl.WeChatShopPromoteProductLinkRequest
;
import
com.netease.yanxuan.wx.store.sharer.integration.handler.impl.WeChatShopPromoteProductListRequest
;
...
...
@@ -43,18 +44,17 @@ public class ProductServiceImpl implements IProductService {
private
final
WeChatShopSharerListRequest
weChatShopSharerListRequest
;
private
final
DrmSharerConfig
drmSharerConfig
;
@Override
public
PageVO
<
ProductListVO
>
getProductPageList
(
PageQuery
pageQuery
,
String
keyword
)
{
PageVO
<
ProductListVO
>
pageVO
=
new
PageVO
<>();
WeChatPromoteProductListVO
productListVO
=
weChatShopPromoteProductListRequest
.
handle
(
keyword
,
pageQuery
.
getNextKey
(),
pageQuery
.
getPageSize
());
pageVO
.
setHasMore
(!
CollectionUtils
.
isEmpty
(
productListVO
.
getProduct_list
())
&&
productListVO
.
getProduct_list
().
size
()
>=
pageQuery
.
getPageSize
());
pageVO
.
setNextKey
(
productListVO
.
getNext_key
());
pageVO
.
setHasMore
(
false
);
// 商品列表
List
<
ProductListVO
>
resultList
=
Optional
.
ofNullable
(
productListVO
.
getProduct_list
()).
orElseGet
(
ArrayList:
:
new
)
.
stream
()
.
map
(
item
->
{
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
)
{
...
...
@@ -104,10 +104,17 @@ public class ProductServiceImpl implements IProductService {
listVO
.
setShopAppid
(
item
.
getShop_appid
());
listVO
.
setProductId
(
item
.
getProduct_id
());
return
listVO
;
})
});
// 过滤空
productList
=
Optional
.
of
(
productList
).
orElseGet
(
ArrayList:
:
new
)
.
stream
()
.
filter
(
Objects:
:
nonNull
)
.
collect
(
Collectors
.
toList
());
pageVO
.
setList
(
resultList
);
pageVO
.
setList
(
productList
);
pageVO
.
setHasMore
(!
CollectionUtils
.
isEmpty
(
productList
)
&&
productList
.
size
()
>=
pageQuery
.
getPageSize
());
pageVO
.
setNextKey
(
productListVO
.
getNext_key
());
}
return
pageVO
;
}
...
...
yanxuan-wx-store-sharer-common/src/main/java/com/netease/yanxuan/wx/store/sharer/common/util/AsyncUtils.java
0 → 100644
View file @
7be53995
package
com
.
netease
.
yanxuan
.
wx
.
store
.
sharer
.
common
.
util
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.concurrent.CompletableFuture
;
import
java.util.concurrent.Executor
;
import
java.util.function.Function
;
/**
* @Description 异步处理工具类
* @Author fanjiaxin
* @Date 2024/6/13 09:31
*/
public
class
AsyncUtils
{
/**
* 异步处理列表中的每个元素,并收集所有结果。
*
* @param <T> 列表中的元素类型
* @param <R> 异步处理结果类型
* @param itemList 要处理的列表
* @param asyncTask 定义如何异步处理每个元素的函数
* @return 异步处理后所有结果的列表
*/
public
static
<
T
,
R
>
List
<
R
>
processListAsync
(
List
<
T
>
itemList
,
Function
<
T
,
R
>
asyncTask
)
{
CompletableFuture
<
R
>[]
futures
=
new
CompletableFuture
[
itemList
.
size
()];
for
(
int
i
=
0
;
i
<
itemList
.
size
();
i
++)
{
T
item
=
itemList
.
get
(
i
);
CompletableFuture
<
R
>
future
=
CompletableFuture
.
supplyAsync
(()
->
asyncTask
.
apply
(
item
));
futures
[
i
]
=
future
;
}
CompletableFuture
.
allOf
(
futures
).
join
();
List
<
R
>
resultList
=
new
ArrayList
<>(
itemList
.
size
());
for
(
CompletableFuture
<
R
>
future
:
futures
)
{
resultList
.
add
(
future
.
join
());
}
return
resultList
;
}
/**
* 异步处理列表中的每个元素,并收集所有结果。
*
* @param <T> 列表中的元素类型
* @param <R> 异步处理结果类型
* @param itemList 要处理的列表
* @param asyncTask 定义如何异步处理每个元素的函数
* @param executor 异步执行器
* @return 异步处理后所有结果的列表
*/
public
static
<
T
,
R
>
List
<
R
>
processListAsync
(
List
<
T
>
itemList
,
Function
<
T
,
R
>
asyncTask
,
Executor
executor
)
{
CompletableFuture
<
R
>[]
futures
=
new
CompletableFuture
[
itemList
.
size
()];
for
(
int
i
=
0
;
i
<
itemList
.
size
();
i
++)
{
T
item
=
itemList
.
get
(
i
);
CompletableFuture
<
R
>
future
=
CompletableFuture
.
supplyAsync
(()
->
asyncTask
.
apply
(
item
),
executor
);
futures
[
i
]
=
future
;
}
CompletableFuture
.
allOf
(
futures
).
join
();
List
<
R
>
resultList
=
new
ArrayList
<>(
itemList
.
size
());
for
(
CompletableFuture
<
R
>
future
:
futures
)
{
resultList
.
add
(
future
.
join
());
}
return
resultList
;
}
}
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