Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
order-group
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
order-group-application
order-group
Commits
cf3b439d
Commit
cf3b439d
authored
May 31, 2021
by
周晓航
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增 库存校验
parent
df4fe111
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
9 deletions
+57
-9
shopping-cart-application-service/src/main/java/cn/freemud/service/impl/ShoppingCartNewServiceImpl.java
+57
-9
No files found.
shopping-cart-application-service/src/main/java/cn/freemud/service/impl/ShoppingCartNewServiceImpl.java
View file @
cf3b439d
...
...
@@ -3169,7 +3169,6 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService {
private
boolean
updateCartGoodsLegal
(
List
<
CartGoods
>
excludeGoods
,
String
userId
,
ShopGoodsReplaceVo
replaceGoodsRequestVo
,
ShoppingCartGoodsResponseVo
shoppingCartGoodsResponseVo
,
boolean
fullReplace
)
{
//存储新添加的购物车信息
List
<
CartGoods
>
nowCartGoodsList
=
new
ArrayList
<>();
//当商品全部添加完毕,校验购物车商品(是否合法,上下架,点餐方式,是否在当前菜单中...),并移除非法商品
...
...
@@ -3194,21 +3193,70 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService {
fullReplace
=
false
;
}
//判断当前商品在购物车是否已存在,存在则数量+1,不存在商品行 + 1
allCartGoodsList
.
forEach
(
oldCartGoods
->
{
int
index
;
if
((
index
=
nowCartGoodsList
.
indexOf
(
oldCartGoods
))
>=
0
)
{
nowCartGoodsList
.
get
(
index
).
setQty
(
nowCartGoodsList
.
get
(
index
).
getQty
());
}
else
{
nowCartGoodsList
.
add
(
oldCartGoods
);
// allCartGoodsList.forEach(oldCartGoods -> {
// int index;
// if ((index = nowCartGoodsList.indexOf(oldCartGoods)) >= 0) {
// nowCartGoodsList.get(index).setQty(nowCartGoodsList.get(index).getQty());
// } else {
// nowCartGoodsList.add(oldCartGoods);
// }
// });
//校验库存
List
<
CartGoods
>
stockLimitGoods
=
allCartGoodsList
.
stream
().
filter
(
CartGoods:
:
isStockLimit
).
collect
(
toList
());
if
(!
CollectionUtils
.
isEmpty
(
stockLimitGoods
))
{
List
<
Long
>
spuIds
=
stockLimitGoods
.
stream
().
map
(
v
->
Long
.
parseLong
(
v
.
getSpuId
())).
collect
(
toList
());
GetProductStockRequestDto
requestDto
=
new
GetProductStockRequestDto
();
requestDto
.
setChannel
(
BusinessTypeEnum
.
getByType
(
replaceGoodsRequestVo
.
getMenuType
()).
getCode
());
requestDto
.
setPartnerId
(
replaceGoodsRequestVo
.
getPartnerId
());
requestDto
.
setStoreId
(
replaceGoodsRequestVo
.
getShopId
());
requestDto
.
setProductIds
(
spuIds
);
GetProductStockResponseDto
availableStocks
=
stockClient
.
getAvailableStocks
(
requestDto
);
if
(
availableStocks
!=
null
)
{
if
(!
ResponseCodeConstant
.
RESPONSE_SUCCESS_STR
.
equals
(
availableStocks
.
getCode
())){
// 没有请求数据
fullReplace
=
false
;
return
fullReplace
;
}
if
(
CollectionUtils
.
isEmpty
(
availableStocks
.
getResult
())){
LogUtil
.
info
(
"request check stock limit fail result is null"
,
requestDto
,
availableStocks
);
fullReplace
=
false
;
return
fullReplace
;
}
List
<
GetProductStockResponseDto
.
DataBean
>
availableStocksResult
=
availableStocks
.
getResult
();
stockLimitGoods
.
forEach
(
cartGoods
->
{
// 数量修改
availableStocksResult
.
forEach
(
dataBean
->
{
if
(
cartGoods
.
getSpuId
().
equals
(
dataBean
.
getPid
()))
{
Integer
qty
=
dataBean
.
getQty
();
if
(
qty
!=
null
&&
qty
.
compareTo
(
cartGoods
.
getQty
())
<
0
)
{
cartGoods
.
setQty
(
qty
);
}
}
});
});
// 获取到最新的 库存 stockLimitGoods 数据 放入 nowCartGoodsList 中
List
<
CartGoods
>
notCheckStock
=
allCartGoodsList
.
stream
().
filter
(
cartGoods
->
!
cartGoods
.
isStockLimit
()).
collect
(
toList
());
notCheckStock
.
addAll
(
stockLimitGoods
);
allCartGoodsList
=
notCheckStock
;
notCheckStock
=
null
;
stockLimitGoods
=
null
;
}
else
{
LogUtil
.
info
(
"request check stock limit fail"
,
requestDto
,
null
);
fullReplace
=
false
;
return
fullReplace
;
}
}
// fisherman 删除 新门店的缓存数据 重新添加 测试 之后需要放开
shoppingCartNewBaseService
.
clear
(
replaceGoodsRequestVo
.
getPartnerId
(),
replaceGoodsRequestVo
.
getShopId
(),
userId
);
// 重新set购物车信息到缓存中
assortmentSdkService
.
setShoppingCart
(
replaceGoodsRequestVo
.
getPartnerId
(),
replaceGoodsRequestVo
.
getShopId
(),
userId
,
now
CartGoodsList
,
replaceGoodsRequestVo
.
getSessionId
(),
null
,
this
.
shoppingCartBaseService
);
userId
,
all
CartGoodsList
,
replaceGoodsRequestVo
.
getSessionId
(),
null
,
this
.
shoppingCartBaseService
);
excludeGoods
.
clear
();
excludeGoods
.
addAll
(
now
CartGoodsList
);
excludeGoods
.
addAll
(
all
CartGoodsList
);
return
fullReplace
;
}
...
...
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