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
b94fa912
Commit
b94fa912
authored
Aug 09, 2021
by
ping.wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
购物车限购数量调整
parent
1fa7810e
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
94 additions
and
110 deletions
+94
-110
shopping-cart-application-service/src/main/java/cn/freemud/demo/service/impl/AbstractAddGoodsService.java
+44
-51
shopping-cart-application-service/src/main/java/cn/freemud/service/impl/ShoppingCartNewServiceImpl.java
+49
-58
shopping-cart-application-service/src/main/java/cn/freemud/utils/RedisUtil.java
+1
-1
No files found.
shopping-cart-application-service/src/main/java/cn/freemud/demo/service/impl/AbstractAddGoodsService.java
View file @
b94fa912
...
@@ -362,7 +362,7 @@ public abstract class AbstractAddGoodsService implements AddGoodsService {
...
@@ -362,7 +362,7 @@ public abstract class AbstractAddGoodsService implements AddGoodsService {
//购物车添加数量限制
//购物车添加数量限制
CartGoods
addGoods
=
baseRequestDTO
.
getAddGoods
();
CartGoods
addGoods
=
baseRequestDTO
.
getAddGoods
();
this
.
limitGoodsQty
(
checkBussinessRulesBO
.
getCartGoods
(),
addGoods
,
baseRequestDTO
.
getAppId
());
this
.
limitGoodsQty
(
checkBussinessRulesBO
.
getCartGoods
(),
addGoods
,
baseRequestDTO
.
getAppId
()
,
baseRequestDTO
.
getPartnerId
()
);
// 校验数量, 库存
// 校验数量, 库存
this
.
checkStocks
(
baseRequestDTO
,
checkBussinessRulesBO
);
this
.
checkStocks
(
baseRequestDTO
,
checkBussinessRulesBO
);
...
@@ -684,7 +684,7 @@ public abstract class AbstractAddGoodsService implements AddGoodsService {
...
@@ -684,7 +684,7 @@ public abstract class AbstractAddGoodsService implements AddGoodsService {
/**
/**
* 查询生态配置限制加购开关与限制数量
* 查询生态配置限制加购开关与限制数量
*/
*/
private
Integer
limitGoodsQty
(
List
<
CartGoods
>
oldCartGoodsList
,
CartGoods
addGoods
,
String
appid
)
{
private
Integer
limitGoodsQty
(
List
<
CartGoods
>
oldCartGoodsList
,
CartGoods
addGoods
,
String
appid
,
String
partnerId
)
{
Integer
qty
=
0
;
Integer
qty
=
0
;
if
(
CollectionUtils
.
isNotEmpty
(
oldCartGoodsList
))
{
if
(
CollectionUtils
.
isNotEmpty
(
oldCartGoodsList
))
{
for
(
CartGoods
goods
:
oldCartGoodsList
)
{
for
(
CartGoods
goods
:
oldCartGoodsList
)
{
...
@@ -693,58 +693,51 @@ public abstract class AbstractAddGoodsService implements AddGoodsService {
...
@@ -693,58 +693,51 @@ public abstract class AbstractAddGoodsService implements AddGoodsService {
}
}
qty
+=
addGoods
.
getQty
();
qty
+=
addGoods
.
getQty
();
Long
expire
=
5L
;
//购物车内部缓存
Integer
limitCount
=
redisCache
.
getValue
(
RedisUtil
.
limitCart
+
appid
);
if
(
limitCount
!=
null
)
{
if
(
qty
>
limitCount
)
{
throw
new
ServiceException
(
ResponseResult
.
SHOPPING_CART_LIMIT_ADD
);
}
return
qty
;
}
String
redisKey
=
limitCartKey
+
appid
;
//生态缓存获取慢
Object
value
=
redisCache
.
hashGet
(
redisKey
,
"2"
);
if
(
value
==
null
)
{
redisCache
.
save
(
RedisUtil
.
limitCart
+
appid
,
0
,
expire
,
TimeUnit
.
MINUTES
);
return
qty
;
}
else
{
boolean
bool
=
value
.
getClass
().
getName
().
equals
(
"java.lang.String"
);
if
(
bool
)
{
redisCache
.
save
(
RedisUtil
.
limitCart
+
appid
,
0
,
expire
,
TimeUnit
.
MINUTES
);
return
qty
;
}
JSONArray
jsonArray
=
(
JSONArray
)
value
;
int
cartLimitFlag
=
0
;
int
cartLimitCount
=
0
;
int
cartLimitCount
=
0
;
for
(
Object
object
:
jsonArray
)
{
String
redisKey
=
RedisUtil
.
limitCart
+
partnerId
+
"_"
+
appid
;
JSONObject
jsonObject
=
(
JSONObject
)
object
;
//购物车内部缓存
HashMap
hashMap
=
JSONObject
.
parseObject
(
jsonObject
.
toJSONString
(),
HashMap
.
class
);
String
value
=
redisCache
.
hashGet
(
redisKey
,
"cartLimitType"
);
if
(
"cartLimitFlag"
.
equals
(
hashMap
.
get
(
"appKey"
)))
{
if
(
StringUtils
.
isNotBlank
(
value
))
{
if
(
StringUtils
.
isBlank
((
String
)
hashMap
.
get
(
"appValue"
)))
{
cartLimitCount
=
Integer
.
parseInt
(
value
);
redisCache
.
save
(
RedisUtil
.
limitCart
+
appid
,
0
,
expire
,
TimeUnit
.
MINUTES
);
}
return
qty
;
}
// String redisKey = limitCartKey + appid;
cartLimitFlag
=
Integer
.
parseInt
((
String
)
hashMap
.
get
(
"appValue"
));
// //生态缓存获取慢
if
(
cartLimitFlag
!=
1
)
{
// Object value = redisCache.hashGet(redisKey, "2");
redisCache
.
save
(
RedisUtil
.
limitCart
+
appid
,
0
,
expire
,
TimeUnit
.
MINUTES
);
// if (value == null) {
return
qty
;
// return qty;
}
// } else {
}
// boolean bool = value.getClass().getName().equals("java.lang.String");
if
(
"cartLimitCount"
.
equals
(
hashMap
.
get
(
"appKey"
)))
{
// if (bool) {
if
(
StringUtils
.
isBlank
((
String
)
hashMap
.
get
(
"appValue"
)))
{
// return qty;
redisCache
.
save
(
RedisUtil
.
limitCart
+
appid
,
0
,
expire
,
TimeUnit
.
MINUTES
);
// }
return
qty
;
// JSONArray jsonArray = (JSONArray) value;
}
// int cartLimitFlag = 0;
cartLimitCount
=
Integer
.
parseInt
((
String
)
hashMap
.
get
(
"appValue"
));
// int cartLimitCount = 0;
redisCache
.
save
(
RedisUtil
.
limitCart
+
appid
,
cartLimitCount
,
expire
,
TimeUnit
.
MINUTES
);
// for (Object object : jsonArray) {
}
// JSONObject jsonObject = (JSONObject) object;
}
// HashMap hashMap = JSONObject.parseObject(jsonObject.toJSONString(), HashMap.class);
if
(
cartLimitFlag
==
1
&&
cartLimitCount
!=
0
&&
qty
>
cartLimitCount
)
{
// if ("cartLimitFlag".equals(hashMap.get("appKey"))) {
// if (StringUtils.isBlank((String) hashMap.get("appValue"))) {
// return qty;
// }
// cartLimitFlag = Integer.parseInt((String) hashMap.get("appValue"));
// if (cartLimitFlag != 1) {
// return qty;
// }
// }
// if ("cartLimitCount".equals(hashMap.get("appKey"))) {
// if (StringUtils.isBlank((String) hashMap.get("appValue"))) {
// return qty;
// }
// cartLimitCount = Integer.parseInt((String) hashMap.get("appValue"));
// }
// }
//
// }
if
(
cartLimitCount
!=
0
&&
qty
>
cartLimitCount
)
{
throw
new
ServiceException
(
ResponseResult
.
SHOPPING_CART_LIMIT_ADD
);
throw
new
ServiceException
(
ResponseResult
.
SHOPPING_CART_LIMIT_ADD
);
}
}
}
return
qty
;
return
qty
;
}
}
...
...
shopping-cart-application-service/src/main/java/cn/freemud/service/impl/ShoppingCartNewServiceImpl.java
View file @
b94fa912
...
@@ -354,7 +354,7 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService {
...
@@ -354,7 +354,7 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService {
Integer
checkQty
=
this
.
checkSkuQty
(
allCartGoodsList
,
cartGoods
);
Integer
checkQty
=
this
.
checkSkuQty
(
allCartGoodsList
,
cartGoods
);
//购物车添加数量限制
//购物车添加数量限制
Integer
productsCount
=
limitGoodsQty
(
allCartGoodsList
,
cartGoods
,
appId
);
Integer
productsCount
=
limitGoodsQty
(
allCartGoodsList
,
cartGoods
,
appId
,
partnerId
);
//查询多个商品库存信息 TODO
//查询多个商品库存信息 TODO
queryManyGoodsStocks
(
addShoppingCartGoodsRequestVo
,
productIds
,
productBeanListSpuClass
,
skuId
,
checkQty
);
queryManyGoodsStocks
(
addShoppingCartGoodsRequestVo
,
productIds
,
productBeanListSpuClass
,
skuId
,
checkQty
);
String
productName
=
null
;
String
productName
=
null
;
...
@@ -2610,7 +2610,7 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService {
...
@@ -2610,7 +2610,7 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService {
/**
/**
* 查询生态配置限制加购开关与限制数量
* 查询生态配置限制加购开关与限制数量
*/
*/
public
Integer
limitGoodsQty
(
List
<
CartGoods
>
oldCartGoodsList
,
CartGoods
cartGoods
,
String
appid
)
{
public
Integer
limitGoodsQty
(
List
<
CartGoods
>
oldCartGoodsList
,
CartGoods
cartGoods
,
String
appid
,
String
partnerId
)
{
Integer
qty
=
0
;
Integer
qty
=
0
;
if
(
CollectionUtils
.
isNotEmpty
(
oldCartGoodsList
))
{
if
(
CollectionUtils
.
isNotEmpty
(
oldCartGoodsList
))
{
for
(
CartGoods
goods
:
oldCartGoodsList
)
{
for
(
CartGoods
goods
:
oldCartGoodsList
)
{
...
@@ -2620,7 +2620,7 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService {
...
@@ -2620,7 +2620,7 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService {
if
(
Objects
.
nonNull
(
cartGoods
))
{
if
(
Objects
.
nonNull
(
cartGoods
))
{
qty
+=
cartGoods
.
getQty
();
qty
+=
cartGoods
.
getQty
();
}
}
int
limitCount
=
queryLimitCount
(
appid
);
int
limitCount
=
queryLimitCount
(
partnerId
,
appid
);
if
(
qty
>
limitCount
)
{
if
(
qty
>
limitCount
)
{
throw
new
ServiceException
(
ResponseResult
.
SHOPPING_CART_LIMIT_ADD
);
throw
new
ServiceException
(
ResponseResult
.
SHOPPING_CART_LIMIT_ADD
);
}
}
...
@@ -2630,59 +2630,50 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService {
...
@@ -2630,59 +2630,50 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService {
/**
/**
* 查询购物车限购数量
* 查询购物车限购数量
*/
*/
public
int
queryLimitCount
(
String
appid
)
{
public
int
queryLimitCount
(
String
partnerId
,
String
appid
)
{
int
qty
=
0
;
int
limitCount
=
0
;
Long
expire
=
1L
;
String
redisKey
=
RedisUtil
.
limitCart
+
partnerId
+
"_"
+
appid
;
//购物车内部缓存
//购物车内部缓存
Integer
limitCount
=
redisCache
.
getValue
(
RedisUtil
.
limitCart
+
appid
);
String
value
=
redisCache
.
hashGet
(
redisKey
,
"cartLimitType"
);
if
(
limitCount
!=
null
)
{
if
(
StringUtils
.
isNotBlank
(
value
))
{
if
(
qty
>
limitCount
)
{
return
Integer
.
parseInt
(
value
);
throw
new
ServiceException
(
ResponseResult
.
SHOPPING_CART_LIMIT_ADD
);
}
}
return
qty
;
// String redisKey = limitCartKey + appid;
}
// //生态缓存获取慢
// Object value = redisCache.hashGet(redisKey, "2");
String
redisKey
=
limitCartKey
+
appid
;
// if (value == null) {
//生态缓存获取慢
// return qty;
Object
value
=
redisCache
.
hashGet
(
redisKey
,
"2"
);
// } else {
if
(
value
==
null
)
{
// boolean bool = value.getClass().getName().equals("java.lang.String");
redisCache
.
save
(
RedisUtil
.
limitCart
+
appid
,
0
,
expire
,
TimeUnit
.
MINUTES
);
// if (bool) {
return
qty
;
// return qty;
}
else
{
// }
boolean
bool
=
value
.
getClass
().
getName
().
equals
(
"java.lang.String"
);
// JSONArray jsonArray = (JSONArray) value;
if
(
bool
)
{
// int cartLimitFlag = 0;
redisCache
.
save
(
RedisUtil
.
limitCart
+
appid
,
0
,
expire
,
TimeUnit
.
MINUTES
);
// int cartLimitCount = 0;
return
qty
;
// for (Object object : jsonArray) {
}
// JSONObject jsonObject = (JSONObject) object;
JSONArray
jsonArray
=
(
JSONArray
)
value
;
// HashMap hashMap = JSONObject.parseObject(jsonObject.toJSONString(), HashMap.class);
int
cartLimitFlag
=
0
;
// if ("cartLimitFlag".equals(hashMap.get("appKey"))) {
int
cartLimitCount
=
0
;
// if (StringUtils.isBlank((String) hashMap.get("appValue"))) {
for
(
Object
object
:
jsonArray
)
{
// return qty;
JSONObject
jsonObject
=
(
JSONObject
)
object
;
// }
HashMap
hashMap
=
JSONObject
.
parseObject
(
jsonObject
.
toJSONString
(),
HashMap
.
class
);
// cartLimitFlag = Integer.parseInt((String) hashMap.get("appValue"));
if
(
"cartLimitFlag"
.
equals
(
hashMap
.
get
(
"appKey"
)))
{
// if (cartLimitFlag != 1) {
if
(
StringUtils
.
isBlank
((
String
)
hashMap
.
get
(
"appValue"
)))
{
// return qty;
redisCache
.
save
(
RedisUtil
.
limitCart
+
appid
,
0
,
expire
,
TimeUnit
.
MINUTES
);
// }
return
qty
;
// }
}
// if ("cartLimitCount".equals(hashMap.get("appKey"))) {
cartLimitFlag
=
Integer
.
parseInt
((
String
)
hashMap
.
get
(
"appValue"
));
// if (StringUtils.isBlank((String) hashMap.get("appValue"))) {
if
(
cartLimitFlag
!=
1
)
{
// return qty;
redisCache
.
save
(
RedisUtil
.
limitCart
+
appid
,
0
,
expire
,
TimeUnit
.
MINUTES
);
// }
return
qty
;
// cartLimitCount = Integer.parseInt((String) hashMap.get("appValue"));
}
// return cartLimitCount;
}
// }
if
(
"cartLimitCount"
.
equals
(
hashMap
.
get
(
"appKey"
)))
{
// }
if
(
StringUtils
.
isBlank
((
String
)
hashMap
.
get
(
"appValue"
)))
{
// }
redisCache
.
save
(
RedisUtil
.
limitCart
+
appid
,
0
,
expire
,
TimeUnit
.
MINUTES
);
return
limitCount
;
return
qty
;
}
cartLimitCount
=
Integer
.
parseInt
((
String
)
hashMap
.
get
(
"appValue"
));
redisCache
.
save
(
RedisUtil
.
limitCart
+
appid
,
cartLimitCount
,
expire
,
TimeUnit
.
MINUTES
);
return
cartLimitCount
;
}
}
}
return
qty
;
}
}
...
@@ -2699,7 +2690,7 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService {
...
@@ -2699,7 +2690,7 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService {
sendQty
+=
sendGoods
.
getSendNumber
();
sendQty
+=
sendGoods
.
getSendNumber
();
}
}
}
}
int
cartLimitCount
=
queryLimitCount
(
appid
);
int
cartLimitCount
=
queryLimitCount
(
partnerId
,
appid
);
if
(
checkQty
+
sendQty
>
cartLimitCount
)
{
if
(
checkQty
+
sendQty
>
cartLimitCount
)
{
assortmentSdkService
.
setShoppingCart
(
partnerId
,
storeId
,
userId
,
oldCartGoodsList
,
null
,
tableNumber
,
shoppingCartService
);
assortmentSdkService
.
setShoppingCart
(
partnerId
,
storeId
,
userId
,
oldCartGoodsList
,
null
,
tableNumber
,
shoppingCartService
);
throw
new
ServiceException
(
ResponseResult
.
SHOPPING_CART_LIMIT_ADD
);
throw
new
ServiceException
(
ResponseResult
.
SHOPPING_CART_LIMIT_ADD
);
...
@@ -2717,7 +2708,7 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService {
...
@@ -2717,7 +2708,7 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService {
}
}
}
}
int
cartLimitCount
=
queryLimitCount
(
appid
);
int
cartLimitCount
=
queryLimitCount
(
partnerId
,
appid
);
int
sendQty
=
0
;
int
sendQty
=
0
;
if
(
CollectionUtils
.
isNotEmpty
(
sendActivitys
))
{
if
(
CollectionUtils
.
isNotEmpty
(
sendActivitys
))
{
for
(
ActivityCalculationDiscountResponseDto
.
CalculationDiscountResult
.
SendActivity
sendActivity
:
sendActivitys
)
{
for
(
ActivityCalculationDiscountResponseDto
.
CalculationDiscountResult
.
SendActivity
sendActivity
:
sendActivitys
)
{
...
@@ -3259,7 +3250,7 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService {
...
@@ -3259,7 +3250,7 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService {
Integer
checkQty
=
this
.
checkSkuQty
(
allCartGoodsList
,
cartGoods
);
Integer
checkQty
=
this
.
checkSkuQty
(
allCartGoodsList
,
cartGoods
);
//购物车添加数量限制
//购物车添加数量限制
Integer
productsCount
=
limitGoodsQty
(
allCartGoodsList
,
cartGoods
,
appId
);
Integer
productsCount
=
limitGoodsQty
(
allCartGoodsList
,
cartGoods
,
appId
,
partnerId
);
//查询多个商品库存信息 TODO
//查询多个商品库存信息 TODO
queryManyGoodsStocks
(
replaceGoodsRequestVo
.
getMenuType
(),
replaceGoodsRequestVo
.
getPartnerId
(),
replaceGoodsRequestVo
.
getShopId
(),
productIds
,
productBeanListSpuClass
,
skuId
,
checkQty
);
queryManyGoodsStocks
(
replaceGoodsRequestVo
.
getMenuType
(),
replaceGoodsRequestVo
.
getPartnerId
(),
replaceGoodsRequestVo
.
getShopId
(),
productIds
,
productBeanListSpuClass
,
skuId
,
checkQty
);
...
...
shopping-cart-application-service/src/main/java/cn/freemud/utils/RedisUtil.java
View file @
b94fa912
...
@@ -5,7 +5,7 @@ public class RedisUtil {
...
@@ -5,7 +5,7 @@ public class RedisUtil {
private
final
static
String
ENTER_SHOP_KEY
=
BASE_URL
+
"ENTER_SHOP_KEY_"
;
private
final
static
String
ENTER_SHOP_KEY
=
BASE_URL
+
"ENTER_SHOP_KEY_"
;
private
final
static
String
JOIN_FISSION_ACTIVITIES_KEY
=
BASE_URL
+
"JOIN_FISSION_ACTIVITIES_KEY_"
;
private
final
static
String
JOIN_FISSION_ACTIVITIES_KEY
=
BASE_URL
+
"JOIN_FISSION_ACTIVITIES_KEY_"
;
private
final
static
String
COUPON_APP_SECRET
=
"coupon:app_secret_"
;
private
final
static
String
COUPON_APP_SECRET
=
"coupon:app_secret_"
;
public
static
String
limitCart
=
"kgd:
shoppingcart:cartLimitCount:
"
;
public
static
String
limitCart
=
"kgd:
cart_limit_
"
;
public
static
String
getEnterShopKey
(
String
userId
)
{
public
static
String
getEnterShopKey
(
String
userId
)
{
return
ENTER_SHOP_KEY
+
userId
;
return
ENTER_SHOP_KEY
+
userId
;
...
...
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