Commit c5ebf3d4 by 刘鹏飞

redis操作改为RedisCache进行操作

parent 366cde99
......@@ -3,7 +3,9 @@ package com.freemud.sdk.api.assortment.shoppingcart.service.impl;
import ch.qos.logback.classic.Level;
import cn.freemud.base.entity.BaseResponse;
import cn.freemud.redis.RedisCache;
import com.alibaba.fastjson.JSONObject;
import com.freemud.application.sdk.api.couponcenter.online.service.FMActiveSdkService;
import com.freemud.application.sdk.api.log.ApiLog;
import com.freemud.application.sdk.api.log.ErrorLog;
import com.freemud.sdk.api.assortment.shoppingcart.adapter.CollageOrderSdkAdapter;
import com.freemud.sdk.api.assortment.shoppingcart.constant.CartResponseConstant;
......@@ -53,8 +55,8 @@ public class CollageCartBaseServiceImpl implements ShoppingCartBaseService {
@Autowired
private RedisCache redisCache;
@Autowired
private RedisTemplate redisTemplate;
/* @Autowired
private RedisTemplate redisTemplate;*/
@Override
public BaseResponse<List<CartAddItem>> detailCart(CartParamDto cartParamDto, String trackingNo) {
......@@ -68,7 +70,7 @@ public class CollageCartBaseServiceImpl implements ShoppingCartBaseService {
doCheck(cartParamDto);
// 构建缓存key
String collageCartHashKey = genCollageCarHashKey(cartParamDto.getPartnerId(), cartParamDto.getStoreId(), cartParamDto.getUserId());
BoundHashOperations<String, String, CartGoods> operations = redisTemplate.boundHashOps(collageCartHashKey);
BoundHashOperations<String, String, CartGoods> operations = redisCache.getRedisTemplate().boundHashOps(collageCartHashKey);
List<CartGoods> cartGoodsList = operations.values();
return CartResponseUtil.success(cartGoodsList);
} catch (Exception e) {
......@@ -99,13 +101,24 @@ public class CollageCartBaseServiceImpl implements ShoppingCartBaseService {
@Override
public BaseResponse<List<CartGoods>> setCartGoodsList(CartParamDto cartParamDto, String trackingNo) {
try {
RedisTemplate redisTemplate = redisCache.getRedisTemplate();
String redisKey = genCollageCarHashKey(cartParamDto.getPartnerId(), cartParamDto.getStoreId(), cartParamDto.getUserId());
BoundHashOperations<String, String, CartGoods> operations = redisTemplate.boundHashOps(redisKey);
// 获取拼单购物车的有效期
// 如果购物车已经存在则获取剩余的时间,如果不存在,则设置有效期为1小时(拼单的有效期为1小时)
Long expire =3600L;
// 如果购物车已经存在则获取剩余的时间,如果不存在,则判断拼单是否失效
// 获取拼单的剩余时间作为有效期
Long expire =0L;
if(redisTemplate.hasKey(redisKey)){
expire =operations.getExpire();
expire = operations.getExpire();
}else{
// 如果不存在则使用拼单基础信息的剩余时间作为有效期
// 如果拼单基础信息也过期了,直接返回不做操作
expire = redisTemplate.boundHashOps(genCollageBaseHashKey(cartParamDto.getPartnerId(), cartParamDto.getStoreId(), cartParamDto.getUserId())).getExpire();
if(expire < -1){
ApiLog.info("设置拼单购物车,拼单已经失效,param:"+ JSONObject.toJSONString(cartParamDto));
return null;
}
}
this.clear(cartParamDto, trackingNo);
......@@ -148,6 +161,9 @@ public class CollageCartBaseServiceImpl implements ShoppingCartBaseService {
@Override
public BaseResponse<CartGoods> getCartGoods(CartParamDto cartParamDto, String trackingNo) {
try {
RedisTemplate redisTemplate = redisCache.getRedisTemplate();
String redisKey = genCollageCarHashKey(cartParamDto.getPartnerId(),cartParamDto.getStoreId(),cartParamDto.getUserId());
BoundHashOperations<String, String, CartGoods> operations = redisTemplate.boundHashOps(redisKey);
CartGoods cartGoods = operations.get(cartParamDto.getCartGoodsUid());
......@@ -161,6 +177,9 @@ public class CollageCartBaseServiceImpl implements ShoppingCartBaseService {
@Override
public BaseResponse<List<CartGoods>> updateGoodsQty(CartParamDto cartParamDto, String trackingNo) {
try {
RedisTemplate redisTemplate = redisCache.getRedisTemplate();
String redisKey = genCollageCarHashKey(cartParamDto.getPartnerId(),cartParamDto.getStoreId(),cartParamDto.getUserId());
BoundHashOperations<String, String, CartGoods> operations = redisTemplate.boundHashOps(redisKey);
CartGoods cartGoods = operations.get(cartParamDto.getCartGoodsUid());
......@@ -374,6 +393,9 @@ public class CollageCartBaseServiceImpl implements ShoppingCartBaseService {
*/
public List<String> getCollageCartGoodsUids(String partnerId,String storeId,String crateUserId,String userId){
try {
RedisTemplate redisTemplate = redisCache.getRedisTemplate();
String collageMemberKey = genCollageMemberHashKey(partnerId, storeId, crateUserId);
BoundHashOperations<String, String, List<String>> operations = redisTemplate.boundHashOps(collageMemberKey);
List<String> goodsUids = operations.get(userId);
......@@ -415,6 +437,8 @@ public class CollageCartBaseServiceImpl implements ShoppingCartBaseService {
public List<CartGoods> removeGoodsUids(String partnerId, String storeId, String userId,List<String> goodsUids) {
RedisTemplate redisTemplate = redisCache.getRedisTemplate();
String redisKey = genCollageCarHashKey(partnerId,storeId,userId);
BoundHashOperations<String, String, CartGoods> operations = redisTemplate.boundHashOps(redisKey);
if(null != goodsUids && !goodsUids.isEmpty()){
......
......@@ -119,7 +119,6 @@ public class ShoppingCartCollageServiceImpl extends AbstractShoppingCartImpl imp
UserLoginInfoDto userLoginInfoDto = convert2UserLoginInfoDto(currentUserInfoVo);
String currentUserId = currentUserInfoVo.getMemberId();
//String currentSessionId = addShoppingCartGoodsRequestVo.getSessionId();
String partnerId = addShoppingCartGoodsRequestVo.getPartnerId();
String storeId = addShoppingCartGoodsRequestVo.getShopId();
String appId = addShoppingCartGoodsRequestVo.getAppId();
......
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