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
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
136 additions
and
57 deletions
+136
-57
ProductServiceImpl.java
.../wx/store/sharer/biz/service/impl/ProductServiceImpl.java
+64
-57
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;
...
@@ -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.config.DrmSharerConfig
;
import
com.netease.yanxuan.wx.store.sharer.biz.core.LoginUserContextHolder
;
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.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.ProductListVO
;
import
com.netease.yanxuan.wx.store.sharer.biz.meta.model.vo.ProductPromotionLinkVO
;
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.PageQuery
;
import
com.netease.yanxuan.wx.store.sharer.biz.meta.page.PageVO
;
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.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.WeChatShopPromoteProductDetailRequest
;
import
com.netease.yanxuan.wx.store.sharer.integration.handler.impl.WeChatShopPromoteProductLinkRequest
;
import
com.netease.yanxuan.wx.store.sharer.integration.handler.impl.WeChatShopPromoteProductLinkRequest
;
import
com.netease.yanxuan.wx.store.sharer.integration.handler.impl.WeChatShopPromoteProductListRequest
;
import
com.netease.yanxuan.wx.store.sharer.integration.handler.impl.WeChatShopPromoteProductListRequest
;
...
@@ -43,71 +44,77 @@ public class ProductServiceImpl implements IProductService {
...
@@ -43,71 +44,77 @@ public class ProductServiceImpl implements IProductService {
private
final
WeChatShopSharerListRequest
weChatShopSharerListRequest
;
private
final
WeChatShopSharerListRequest
weChatShopSharerListRequest
;
private
final
DrmSharerConfig
drmSharerConfig
;
private
final
DrmSharerConfig
drmSharerConfig
;
@Override
@Override
public
PageVO
<
ProductListVO
>
getProductPageList
(
PageQuery
pageQuery
,
String
keyword
)
{
public
PageVO
<
ProductListVO
>
getProductPageList
(
PageQuery
pageQuery
,
String
keyword
)
{
PageVO
<
ProductListVO
>
pageVO
=
new
PageVO
<>();
PageVO
<
ProductListVO
>
pageVO
=
new
PageVO
<>();
WeChatPromoteProductListVO
productListVO
=
weChatShopPromoteProductListRequest
.
handle
(
keyword
,
WeChatPromoteProductListVO
productListVO
=
weChatShopPromoteProductListRequest
.
handle
(
keyword
,
pageQuery
.
getNextKey
(),
pageQuery
.
getPageSize
());
pageQuery
.
getNextKey
(),
pageQuery
.
getPageSize
());
pageVO
.
setHasMore
(!
CollectionUtils
.
isEmpty
(
productListVO
.
getProduct_list
())
pageVO
.
setHasMore
(
false
);
&&
productListVO
.
getProduct_list
().
size
()
>=
pageQuery
.
getPageSize
());
pageVO
.
setNextKey
(
productListVO
.
getNext_key
());
// 商品列表
// 商品列表
List
<
ProductListVO
>
resultList
=
Optional
.
ofNullable
(
productListVO
.
getProduct_list
()).
orElseGet
(
ArrayList:
:
new
)
if
(!
CollectionUtils
.
isEmpty
(
productListVO
.
getProduct_list
()))
{
.
stream
()
// 使用异步多线程处理
.
map
(
item
->
{
List
<
ProductListVO
>
productList
=
AsyncUtils
.
processListAsync
(
productListVO
.
getProduct_list
(),
item
->
{
WeChatPromoteProductDetailVO
detailVO
=
weChatShopPromoteProductDetailRequest
.
handle
(
item
.
getShop_appid
(),
WeChatPromoteProductDetailVO
detailVO
=
weChatShopPromoteProductDetailRequest
.
handle
(
item
.
getShop_appid
(),
Long
.
valueOf
(
item
.
getProduct_id
()));
Long
.
valueOf
(
item
.
getProduct_id
()));
if
(
null
==
detailVO
)
{
if
(
null
==
detailVO
)
{
return
null
;
return
null
;
}
}
WeChatPromoteProductDetailVO
.
WeChatPromoteProductVO
product
=
detailVO
.
getProduct
();
WeChatPromoteProductDetailVO
.
WeChatPromoteProductVO
product
=
detailVO
.
getProduct
();
if
(
null
==
product
)
{
if
(
null
==
product
)
{
return
null
;
return
null
;
}
}
WeChatPromoteProductDetailVO
.
WeChatPromoteProductVO
.
WeChatPromoteProductInfoVO
productInfo
=
product
.
getProduct_info
();
WeChatPromoteProductDetailVO
.
WeChatPromoteProductVO
.
WeChatPromoteProductInfoVO
productInfo
=
product
.
getProduct_info
();
if
(
null
==
productInfo
)
{
if
(
null
==
productInfo
)
{
return
null
;
return
null
;
}
}
ProductListVO
listVO
=
new
ProductListVO
();
ProductListVO
listVO
=
new
ProductListVO
();
listVO
.
setTitle
(
productInfo
.
getTitle
());
listVO
.
setTitle
(
productInfo
.
getTitle
());
listVO
.
setHeadImg
(
CollectionUtils
.
isEmpty
(
productInfo
.
getHead_imgs
())
?
null
:
productInfo
.
getHead_imgs
().
get
(
0
));
listVO
.
setHeadImg
(
CollectionUtils
.
isEmpty
(
productInfo
.
getHead_imgs
())
?
null
:
productInfo
.
getHead_imgs
().
get
(
0
));
// 取参数SkuInfo中sale_price的最小
// 取参数SkuInfo中sale_price的最小
BigDecimal
price
=
Optional
.
ofNullable
(
productInfo
.
getSkus
()).
orElseGet
(
ArrayList:
:
new
)
BigDecimal
price
=
Optional
.
ofNullable
(
productInfo
.
getSkus
()).
orElseGet
(
ArrayList:
:
new
)
.
stream
()
.
stream
()
.
map
(
WeChatPromoteProductDetailVO
.
WeChatPromoteProductVO
.
WeChatPromoteProductInfoVO
.
WeChatPromoteProductSkuInfoVO
::
getSale_price
)
.
map
(
WeChatPromoteProductDetailVO
.
WeChatPromoteProductVO
.
WeChatPromoteProductInfoVO
.
WeChatPromoteProductSkuInfoVO
::
getSale_price
)
.
min
(
BigDecimal:
:
compareTo
).
orElse
(
null
);
.
min
(
BigDecimal:
:
compareTo
).
orElse
(
null
);
listVO
.
setPrice
(
price
);
listVO
.
setPrice
(
price
);
// 推客分佣比例
// 推客分佣比例
BigDecimal
commissionRatio
=
drmSharerConfig
.
getDefaultCommissionRatio
();
BigDecimal
commissionRatio
=
drmSharerConfig
.
getDefaultCommissionRatio
();
// 获取用户信息
// 获取用户信息
LoginUserInfo
loginUserInfo
=
LoginUserContextHolder
.
get
();
LoginUserInfo
loginUserInfo
=
LoginUserContextHolder
.
get
();
if
(
null
!=
loginUserInfo
&&
StringUtils
.
isNotBlank
(
loginUserInfo
.
getOpenId
()))
{
if
(
null
!=
loginUserInfo
&&
StringUtils
.
isNotBlank
(
loginUserInfo
.
getOpenId
()))
{
WeChatSharerListVO
sharerListVO
=
weChatShopSharerListRequest
.
handle
(
loginUserInfo
.
getOpenId
(),
""
,
1
);
WeChatSharerListVO
sharerListVO
=
weChatShopSharerListRequest
.
handle
(
loginUserInfo
.
getOpenId
(),
""
,
1
);
if
(
null
!=
sharerListVO
&&
!
CollectionUtils
.
isEmpty
(
sharerListVO
.
getSharer_info_list
()))
{
if
(
null
!=
sharerListVO
&&
!
CollectionUtils
.
isEmpty
(
sharerListVO
.
getSharer_info_list
()))
{
WeChatSharerInfoVO
sharerInfoVO
=
sharerListVO
.
getSharer_info_list
().
get
(
0
);
WeChatSharerInfoVO
sharerInfoVO
=
sharerListVO
.
getSharer_info_list
().
get
(
0
);
if
(
null
!=
sharerInfoVO
&&
null
!=
sharerInfoVO
.
getCommission_ratio
())
{
if
(
null
!=
sharerInfoVO
&&
null
!=
sharerInfoVO
.
getCommission_ratio
())
{
commissionRatio
=
sharerInfoVO
.
getCommission_ratio
();
commissionRatio
=
sharerInfoVO
.
getCommission_ratio
();
}
}
}
}
}
WeChatPromoteProductDetailVO
.
WeChatPromoteProductVO
.
WeChatPromoteProductCommissionInfoVO
commissionInfo
=
product
.
getCommission_info
();
}
// 服务费率
WeChatPromoteProductDetailVO
.
WeChatPromoteProductVO
.
WeChatPromoteProductCommissionInfoVO
commissionInfo
=
product
.
getCommission_info
();
Integer
serviceRatio
=
null
!=
commissionInfo
?
commissionInfo
.
getService_ratio
()
:
null
;
// 服务费率
// 佣金=商品价格*服务费率*推客分佣比例,四舍五入保留小数点后两位
Integer
serviceRatio
=
null
!=
commissionInfo
?
commissionInfo
.
getService_ratio
()
:
null
;
BigDecimal
commission
=
null
;
// 佣金=商品价格*服务费率*推客分佣比例,四舍五入保留小数点后两位
if
(
null
!=
price
&&
null
!=
commissionRatio
&&
null
!=
serviceRatio
)
{
BigDecimal
commission
=
null
;
commission
=
price
.
multiply
(
new
BigDecimal
(
serviceRatio
.
toString
()))
if
(
null
!=
price
&&
null
!=
commissionRatio
&&
null
!=
serviceRatio
)
{
.
multiply
(
commissionRatio
).
setScale
(
2
,
RoundingMode
.
HALF_UP
);
commission
=
price
.
multiply
(
new
BigDecimal
(
serviceRatio
.
toString
()))
}
.
multiply
(
commissionRatio
).
setScale
(
2
,
RoundingMode
.
HALF_UP
);
listVO
.
setCommission
(
commission
);
}
listVO
.
setShopAppid
(
item
.
getShop_appid
());
listVO
.
setCommission
(
commission
);
listVO
.
setProductId
(
item
.
getProduct_id
());
listVO
.
setShopAppid
(
item
.
getShop_appid
());
return
listVO
;
listVO
.
setProductId
(
item
.
getProduct_id
());
})
return
listVO
;
.
filter
(
Objects:
:
nonNull
)
});
.
collect
(
Collectors
.
toList
());
// 过滤空
pageVO
.
setList
(
resultList
);
productList
=
Optional
.
of
(
productList
).
orElseGet
(
ArrayList:
:
new
)
.
stream
()
.
filter
(
Objects:
:
nonNull
)
.
collect
(
Collectors
.
toList
());
pageVO
.
setList
(
productList
);
pageVO
.
setHasMore
(!
CollectionUtils
.
isEmpty
(
productList
)
&&
productList
.
size
()
>=
pageQuery
.
getPageSize
());
pageVO
.
setNextKey
(
productListVO
.
getNext_key
());
}
return
pageVO
;
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