From 5576ae73056a13faf1050f7096c01bc6d8148d5b Mon Sep 17 00:00:00 2001 From: Chopper Date: Tue, 19 Jul 2022 18:45:08 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=20lilishop4.2.4=E4=B8=AD?= =?UTF-8?q?=E5=AD=98=E5=9C=A8=E5=BA=8F=E5=88=97=E5=8C=96=E8=B4=AD=E7=89=A9?= =?UTF-8?q?=E8=BD=A6=EF=BC=8C=E4=BF=83=E9=94=80=E4=BF=A1=E6=81=AF=E4=BC=9A?= =?UTF-8?q?=E5=9C=A8=E5=BA=8F=E5=88=97=E5=8C=96=E5=90=8E=E4=B8=A2=E5=A4=B1?= =?UTF-8?q?=EF=BC=8C=E6=97=A0=E6=B3=95=E5=8F=8D=E5=BA=8F=E5=88=97=E5=8C=96?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/redis/FastJsonRedisSerializer.java | 10 ++++-- .../order/cart/service/CartService.java | 7 ---- .../order/cart/service/CartServiceImpl.java | 36 +++++-------------- 3 files changed, 15 insertions(+), 38 deletions(-) diff --git a/framework/src/main/java/cn/lili/cache/config/redis/FastJsonRedisSerializer.java b/framework/src/main/java/cn/lili/cache/config/redis/FastJsonRedisSerializer.java index d59e29cf..f0071468 100644 --- a/framework/src/main/java/cn/lili/cache/config/redis/FastJsonRedisSerializer.java +++ b/framework/src/main/java/cn/lili/cache/config/redis/FastJsonRedisSerializer.java @@ -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 implements RedisSerializer { - private static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8"); - private Class clazz; + private static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8; + private final Class clazz; public FastJsonRedisSerializer(Class clazz) { super(); @@ -26,7 +27,10 @@ public class FastJsonRedisSerializer implements RedisSerializer { 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 diff --git a/framework/src/main/java/cn/lili/modules/order/cart/service/CartService.java b/framework/src/main/java/cn/lili/modules/order/cart/service/CartService.java index 01b3866d..d11d8aa8 100644 --- a/framework/src/main/java/cn/lili/modules/order/cart/service/CartService.java +++ b/framework/src/main/java/cn/lili/modules/order/cart/service/CartService.java @@ -95,13 +95,6 @@ public interface CartService { */ void clean(); - /** - * 清空购物车无效数据 - * - * @param way 购物车类型 - */ - void cleanChecked(CartTypeEnum way); - /** * 重新写入 * diff --git a/framework/src/main/java/cn/lili/modules/order/cart/service/CartServiceImpl.java b/framework/src/main/java/cn/lili/modules/order/cart/service/CartServiceImpl.java index f64769be..3fafa5be 100644 --- a/framework/src/main/java/cn/lili/modules/order/cart/service/CartServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/order/cart/service/CartServiceImpl.java @@ -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 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