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
c482e803
Commit
c482e803
authored
Nov 02, 2021
by
查志伟
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加更新赠品属性接口
parent
db88828d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
50 additions
and
30 deletions
+50
-30
shopping-cart-application-service/src/main/java/cn/freemud/service/cache/GiftCacheManager.java
+40
-30
shopping-cart-application-service/src/main/java/cn/freemud/service/impl/CartGiftServiceImpl.java
+5
-0
shopping-cart-application-service/src/main/java/cn/freemud/service/impl/ShoppingCartNewServiceImpl.java
+5
-0
No files found.
shopping-cart-application-service/src/main/java/cn/freemud/service/cache/GiftCacheManager.java
View file @
c482e803
...
...
@@ -16,10 +16,7 @@ import org.springframework.stereotype.Component;
import
javax.validation.constraints.NotBlank
;
import
javax.validation.constraints.NotNull
;
import
java.text.MessageFormat
;
import
java.util.HashMap
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.*
;
import
java.util.concurrent.TimeUnit
;
import
java.util.stream.Collectors
;
...
...
@@ -57,34 +54,33 @@ public class GiftCacheManager {
String
redisKey
=
MessageFormat
.
format
(
RedisKeyConstant
.
SAAS_SHOPPING_CART_GIFT_KEY
,
partnerId
,
storeCode
,
userId
);
BoundHashOperations
<
String
,
String
,
String
>
operations
=
redisTemplate
.
boundHashOps
(
redisKey
);
List
<
String
>
values
=
operations
.
values
();
// 将缓存转为对象
List
<
CartGoods
>
oldGiftList
=
CollectionUtils
.
isEmpty
(
values
)
?
new
ArrayList
<>()
:
values
.
stream
().
map
(
v
->
JSON
.
parseObject
(
v
,
CartGoods
.
class
)).
collect
(
Collectors
.
toList
());
// 存放最新的赠品缓存信息
Map
<
String
,
String
>
newValues
=
new
HashMap
<>();
if
(
CollectionUtils
.
isNotEmpty
(
values
))
{
// 缓存里有,筛选出指定活动的赠品数据
List
<
CartGoods
>
oldGiftList
=
values
.
stream
()
.
map
(
v
->
JSON
.
parseObject
(
v
,
CartGoods
.
class
))
.
collect
(
Collectors
.
toList
());
for
(
CartGoods
gift
:
giftList
)
{
// 匹配赠品的商品属性,将原有赠品的属性更新到新计算出的赠品中
Iterator
<
CartGoods
>
it
=
oldGiftList
.
iterator
();
while
(
it
.
hasNext
())
{
CartGoods
old
=
it
.
next
();
boolean
isSameType
=
StringUtils
.
isBlank
(
activityCode
)
||
activityCode
.
equals
(
old
.
getActivityCode
());
if
(!
old
.
getGoodsId
().
equals
(
gift
.
getGoodsId
())
||
!
isSameType
)
continue
;
// 赠品匹配上了,copy赠品属性
gift
.
setExtra
(
old
.
getExtra
());
gift
.
setCartGoodsUid
(
old
.
getCartGoodsUid
());
// 如果赠品为多个同一商品,并且每个商品都有不同的属性,所以这里要移除掉已经匹配上的商品
it
.
remove
();
break
;
}
newValues
.
put
(
gift
.
getCartGoodsUid
(),
JSON
.
toJSONString
(
gift
));
for
(
CartGoods
gift
:
giftList
)
{
// 匹配赠品的商品属性,将原有赠品的属性更新到新计算出的赠品中
Iterator
<
CartGoods
>
it
=
oldGiftList
.
iterator
();
while
(
it
.
hasNext
())
{
CartGoods
old
=
it
.
next
();
boolean
isSameType
=
StringUtils
.
isBlank
(
activityCode
)
||
activityCode
.
equals
(
old
.
getActivityCode
());
if
(!
old
.
getGoodsId
().
equals
(
gift
.
getGoodsId
())
||
!
isSameType
)
continue
;
// 赠品匹配上了,copy赠品属性
gift
.
setExtra
(
old
.
getExtra
());
gift
.
setCartGoodsUid
(
old
.
getCartGoodsUid
());
// 如果赠品为多个同一商品,并且每个商品都有不同的属性,所以这里要移除掉已经匹配上的商品
it
.
remove
();
break
;
}
// oldGiftList中剩下的, 属于其他活动的数据,不变,需要原样放入缓存中
if
(
StringUtils
.
isNotBlank
(
activityCode
))
{
oldGiftList
=
oldGiftList
.
stream
().
filter
(
old
->
!
activityCode
.
equals
(
old
.
getActivityCode
())).
collect
(
Collectors
.
toList
());
for
(
CartGoods
old
:
oldGiftList
)
{
newValues
.
put
(
old
.
getCartGoodsUid
(),
JSON
.
toJSONString
(
old
));
}
newValues
.
put
(
gift
.
getCartGoodsUid
(),
JSON
.
toJSONString
(
gift
));
}
// oldGiftList中剩下的, 属于其他活动的数据,不变,需要原样放入缓存中
if
(
StringUtils
.
isNotBlank
(
activityCode
))
{
oldGiftList
=
oldGiftList
.
stream
().
filter
(
old
->
!
activityCode
.
equals
(
old
.
getActivityCode
())).
collect
(
Collectors
.
toList
());
for
(
CartGoods
old
:
oldGiftList
)
{
newValues
.
put
(
old
.
getCartGoodsUid
(),
JSON
.
toJSONString
(
old
));
}
}
if
(
CollectionUtils
.
isNotEmpty
(
values
))
{
...
...
@@ -135,4 +131,18 @@ public class GiftCacheManager {
BoundHashOperations
<
String
,
String
,
String
>
operations
=
redisTemplate
.
boundHashOps
(
redisKey
);
operations
.
put
(
goods
.
getCartGoodsUid
(),
JSON
.
toJSONString
(
goods
));
}
/**
* 清空赠品的购物车信息
* @param partnerId 商户号
* @param storeCode 门店号
* @param userId 用户id
* @return
*/
public
void
clearGiftCache
(
@NotBlank
String
partnerId
,
@NotBlank
String
storeCode
,
@NotBlank
String
userId
)
{
String
redisKey
=
MessageFormat
.
format
(
RedisKeyConstant
.
SAAS_SHOPPING_CART_GIFT_KEY
,
partnerId
,
storeCode
,
userId
);
redisTemplate
.
delete
(
redisKey
);
}
}
shopping-cart-application-service/src/main/java/cn/freemud/service/impl/CartGiftServiceImpl.java
View file @
c482e803
...
...
@@ -7,6 +7,7 @@ import cn.freemud.service.CartGiftService;
import
cn.freemud.service.cache.GiftCacheManager
;
import
cn.freemud.service.customer.CustomerInfoManager
;
import
lombok.RequiredArgsConstructor
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.stereotype.Service
;
import
java.util.ArrayList
;
...
...
@@ -39,12 +40,16 @@ public class CartGiftServiceImpl implements CartGiftService {
// 查询赠品缓存
CartGoods
goods
=
giftCacheManager
.
queryGiftGoods
(
partnerId
,
storeCode
,
user
.
getMemberId
(),
requestVo
.
getUid
());
List
<
CartGoods
.
CartGoodsExtra
>
attrList
=
new
ArrayList
<>();
List
<
String
>
nameList
=
new
ArrayList
<>();
requestVo
.
getExtra
().
forEach
(
a
->
{
CartGoods
.
CartGoodsExtra
e
=
new
CartGoods
.
CartGoodsExtra
();
e
.
setAttributeId
(
a
.
getAttributeId
());
e
.
setAttributeName
(
a
.
getAttributeName
());
attrList
.
add
(
e
);
nameList
.
add
(
a
.
getAttributeName
());
});
goods
.
setExtra
(
attrList
);
goods
.
setSubName
(
StringUtils
.
join
(
nameList
,
"/"
));
// 更新赠品缓存
giftCacheManager
.
updateGiftGoods
(
partnerId
,
storeCode
,
user
.
getMemberId
(),
goods
);
return
goods
;
...
...
shopping-cart-application-service/src/main/java/cn/freemud/service/impl/ShoppingCartNewServiceImpl.java
View file @
c482e803
...
...
@@ -47,6 +47,7 @@ import cn.freemud.interceptor.BizServiceException;
import
cn.freemud.interceptor.ServiceException
;
import
cn.freemud.redis.RedisCache
;
import
cn.freemud.service.*
;
import
cn.freemud.service.cache.GiftCacheManager
;
import
cn.freemud.service.delivery.DeliveryFactory
;
import
cn.freemud.service.delivery.DeliveryService
;
import
cn.freemud.service.impl.calculate.*
;
...
...
@@ -212,6 +213,8 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService {
@Autowired
private
GetActivityMsgHandle
getActivityMsgHandle
;
@Autowired
private
GiftCacheManager
giftCacheManager
;
/**
* 从微信卡券向购物车中添加商品
...
...
@@ -1033,6 +1036,8 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService {
ShoppingCartRelationService
shoppingCartRelationService
=
shoppingCartRelationFactory
.
cleanAfter
(
shoppingCartClearRequestVo
.
getPartnerId
());
shoppingCartRelationService
.
cleanAfter
(
shoppingCartGoodsResponseVo
,
shoppingCartClearRequestVo
);
// 清空购物车赠品的缓存信息
giftCacheManager
.
clearGiftCache
(
partnerId
,
storeId
,
userId
);
return
ResponseUtil
.
success
(
shoppingCartGoodsResponseVo
);
}
...
...
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