解决 lilishop4.2.4中存在序列化购物车,促销信息会在序列化后丢失,无法反序列化。
This commit is contained in:
parent
d5aadf6926
commit
5576ae7305
@ -6,6 +6,7 @@ import org.springframework.data.redis.serializer.RedisSerializer;
|
||||
import org.springframework.data.redis.serializer.SerializationException;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/**
|
||||
* 要实现对象的缓存,定义自己的序列化和反序列化器。使用阿里的fastjson来实现的比较多
|
||||
@ -13,8 +14,8 @@ import java.nio.charset.Charset;
|
||||
* @author Bulbasaur
|
||||
*/
|
||||
public class FastJsonRedisSerializer<T> implements RedisSerializer<T> {
|
||||
private static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8");
|
||||
private Class<T> clazz;
|
||||
private static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8;
|
||||
private final Class<T> clazz;
|
||||
|
||||
public FastJsonRedisSerializer(Class<T> clazz) {
|
||||
super();
|
||||
@ -26,7 +27,10 @@ public class FastJsonRedisSerializer<T> implements RedisSerializer<T> {
|
||||
if (null == t) {
|
||||
return new byte[0];
|
||||
}
|
||||
return JSON.toJSONString(t, SerializerFeature.WriteClassName).getBytes(DEFAULT_CHARSET);
|
||||
return JSON.toJSONString(t,
|
||||
SerializerFeature.WriteClassName,
|
||||
SerializerFeature.DisableCircularReferenceDetect)
|
||||
.getBytes(DEFAULT_CHARSET);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -95,13 +95,6 @@ public interface CartService {
|
||||
*/
|
||||
void clean();
|
||||
|
||||
/**
|
||||
* 清空购物车无效数据
|
||||
*
|
||||
* @param way 购物车类型
|
||||
*/
|
||||
void cleanChecked(CartTypeEnum way);
|
||||
|
||||
/**
|
||||
* 重新写入
|
||||
*
|
||||
|
@ -16,7 +16,6 @@ import cn.lili.modules.goods.entity.dos.Wholesale;
|
||||
import cn.lili.modules.goods.entity.enums.GoodsAuthEnum;
|
||||
import cn.lili.modules.goods.entity.enums.GoodsSalesModeEnum;
|
||||
import cn.lili.modules.goods.entity.enums.GoodsStatusEnum;
|
||||
import cn.lili.modules.goods.service.GoodsService;
|
||||
import cn.lili.modules.goods.service.GoodsSkuService;
|
||||
import cn.lili.modules.goods.service.WholesaleService;
|
||||
import cn.lili.modules.member.entity.dos.Member;
|
||||
@ -46,7 +45,6 @@ import cn.lili.modules.promotion.service.MemberCouponService;
|
||||
import cn.lili.modules.promotion.service.PointsGoodsService;
|
||||
import cn.lili.modules.promotion.service.PromotionGoodsService;
|
||||
import cn.lili.modules.search.entity.dos.EsGoodsIndex;
|
||||
import cn.lili.modules.search.service.EsGoodsIndexService;
|
||||
import cn.lili.modules.search.service.EsGoodsSearchService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -98,16 +96,6 @@ public class CartServiceImpl implements CartService {
|
||||
*/
|
||||
@Autowired
|
||||
private EsGoodsSearchService esGoodsSearchService;
|
||||
/**
|
||||
* 商品索引
|
||||
*/
|
||||
@Autowired
|
||||
private EsGoodsIndexService goodsIndexService;
|
||||
/**
|
||||
* ES商品
|
||||
*/
|
||||
@Autowired
|
||||
private GoodsService goodsService;
|
||||
/**
|
||||
* 砍价
|
||||
*/
|
||||
@ -161,7 +149,7 @@ public class CartServiceImpl implements CartService {
|
||||
int newNum = oldNum + num;
|
||||
this.checkSetGoodsQuantity(cartSkuVO, skuId, newNum);
|
||||
}
|
||||
|
||||
cartSkuVO.setPromotionMap(promotionMap);
|
||||
//计算购物车小计
|
||||
cartSkuVO.setSubTotal(CurrencyUtil.mul(cartSkuVO.getPurchasePrice(), cartSkuVO.getNum()));
|
||||
} else {
|
||||
@ -254,7 +242,8 @@ public class CartServiceImpl implements CartService {
|
||||
cartSkuVO.setChecked(checked);
|
||||
}
|
||||
}
|
||||
cache.put(this.getOriginKey(CartTypeEnum.CART), tradeDTO);
|
||||
|
||||
this.resetTradeDTO(tradeDTO);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -269,7 +258,8 @@ public class CartServiceImpl implements CartService {
|
||||
cartSkuVO.setChecked(checked);
|
||||
}
|
||||
}
|
||||
cache.put(this.getOriginKey(CartTypeEnum.CART), tradeDTO);
|
||||
|
||||
resetTradeDTO(tradeDTO);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -282,7 +272,7 @@ public class CartServiceImpl implements CartService {
|
||||
for (CartSkuVO cartSkuVO : cartSkuVOS) {
|
||||
cartSkuVO.setChecked(checked);
|
||||
}
|
||||
cache.put(this.getOriginKey(CartTypeEnum.CART), tradeDTO);
|
||||
resetTradeDTO(tradeDTO);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -296,7 +286,6 @@ public class CartServiceImpl implements CartService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void delete(String[] skuIds) {
|
||||
TradeDTO tradeDTO = this.readDTO(CartTypeEnum.CART);
|
||||
List<CartSkuVO> cartSkuVOS = tradeDTO.getSkuList();
|
||||
@ -309,7 +298,7 @@ public class CartServiceImpl implements CartService {
|
||||
}
|
||||
}
|
||||
cartSkuVOS.removeAll(deleteVos);
|
||||
cache.put(this.getOriginKey(CartTypeEnum.CART), tradeDTO);
|
||||
resetTradeDTO(tradeDTO);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -331,17 +320,8 @@ public class CartServiceImpl implements CartService {
|
||||
tradeDTO.setStoreCoupons(null);
|
||||
//清除添加过的备注
|
||||
tradeDTO.setStoreRemark(null);
|
||||
cache.put(this.getOriginKey(tradeDTO.getCartTypeEnum()), tradeDTO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanChecked(CartTypeEnum way) {
|
||||
if (way.equals(CartTypeEnum.CART)) {
|
||||
TradeDTO tradeDTO = this.readDTO(CartTypeEnum.CART);
|
||||
this.cleanChecked(tradeDTO);
|
||||
} else {
|
||||
cache.remove(this.getOriginKey(way));
|
||||
}
|
||||
resetTradeDTO(tradeDTO);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
x
Reference in New Issue
Block a user