Commit 2cf80df0 by 徐康

购物车增加过期时间

parent 9c4e5029
......@@ -46,6 +46,7 @@ import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.stream.Collectors;
......@@ -88,6 +89,14 @@ public interface ShoppingCartBaseService {
BaseResponse<List<CartGoods>> setCartGoodsList(CartParamDto cartParamDto, String trackingNo);
/**
* 设置购物车商品行集合信息,带过期时间
*
* @param cartParamDto
* @return
*/
BaseResponse<List<CartGoods>> setCartGoodsList(CartParamDto cartParamDto, String trackingNo, long expire, TimeUnit timeUnit);
/**
* 设置购物车代金券信息
*
* @param cartParamDto
......
......@@ -47,6 +47,7 @@ import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
......@@ -140,6 +141,24 @@ public class ShoppingCartBaseServiceImpl implements ShoppingCartBaseService {
}
@Override
public BaseResponse<List<CartGoods>> setCartGoodsList(CartParamDto cartParamDto, String trackingNo, long expire, TimeUnit timeUnit) {
try {
String redisKey = getShoppingCartGoodsKey(cartParamDto);
BoundHashOperations<String, String, CartGoods> operations = redisTemplate.boundHashOps(redisKey);
this.clear(cartParamDto, trackingNo);
Map<String, CartGoods> cartGoodsMap = cartParamDto.getCartGoodsList().parallelStream()
.filter(k -> StringUtils.isNotEmpty(k.getCartGoodsUid()))
.collect(Collectors.toMap(CartGoods::getCartGoodsUid, Function.identity(), (k1, k2) -> k1));
operations.putAll(cartGoodsMap);
operations.expire(expire, timeUnit);
return CartResponseUtil.success();
} catch (Exception e) {
ErrorLog.printErrorLog("assortment-shoppingcart-sdk", trackingNo, e.getMessage(), "setCartGoodsList", cartParamDto, e, Level.ERROR);
return null;
}
}
@Override
public BaseResponse<String> setCartCouponCode(CartParamDto cartParamDto, String trackingNo) {
try {
String redisKey = getShoppingCartCouponCodeKey(cartParamDto);
......
......@@ -38,6 +38,7 @@ import cn.freemud.entities.dto.GetMenuResponseDto.DataBean.RootNodeBean.Children
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
/**
......@@ -58,6 +59,9 @@ public class AssortmentSdkService {
@Autowired
private StoreItemClient storeItemClient;
@Value("${mccafe.universal.shopId}")
private String mcCafeUniversalShopId;
/**
* 调用聚合sdk获取单个商品行信息
*
......@@ -181,7 +185,12 @@ public class AssortmentSdkService {
cartParamDto.setTableNumber(tableNumber);
cartParamDto.setUserId(useId);
cartParamDto.setCartGoodsList(JSONArray.parseArray(JSONObject.toJSONString(cartGoodsList), com.freemud.sdk.api.assortment.shoppingcart.domain.CartGoods.class));
BaseResponse<List<com.freemud.sdk.api.assortment.shoppingcart.domain.CartGoods>> baseResponse = shoppingCartService.setCartGoodsList(cartParamDto, LogThreadLocal.getTrackingNo());
BaseResponse<List<com.freemud.sdk.api.assortment.shoppingcart.domain.CartGoods>> baseResponse = null;
if(!mcCafeUniversalShopId.equals(storeId)) {
baseResponse = shoppingCartService.setCartGoodsList(cartParamDto, LogThreadLocal.getTrackingNo());
} else {
baseResponse = shoppingCartService.setCartGoodsList(cartParamDto, LogThreadLocal.getTrackingNo(), 10, TimeUnit.DAYS);
}
if (baseResponse == null || !ResponseResult.SUCCESS.getCode().equals(baseResponse.getCode())) {
return null;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment