Merge branch 'master' of gitee.com:beijing_hongye_huicheng/lilishop into feature/pg

This commit is contained in:
paulGao 2022-07-21 11:52:17 +08:00
commit 4ec2c1b943
4 changed files with 27 additions and 41 deletions

View File

@ -6,6 +6,7 @@ import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.SerializationException; import org.springframework.data.redis.serializer.SerializationException;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
/** /**
* 要实现对象的缓存定义自己的序列化和反序列化器使用阿里的fastjson来实现的比较多 * 要实现对象的缓存定义自己的序列化和反序列化器使用阿里的fastjson来实现的比较多
@ -13,8 +14,8 @@ import java.nio.charset.Charset;
* @author Bulbasaur * @author Bulbasaur
*/ */
public class FastJsonRedisSerializer<T> implements RedisSerializer<T> { public class FastJsonRedisSerializer<T> implements RedisSerializer<T> {
private static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8"); private static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8;
private Class<T> clazz; private final Class<T> clazz;
public FastJsonRedisSerializer(Class<T> clazz) { public FastJsonRedisSerializer(Class<T> clazz) {
super(); super();
@ -26,7 +27,10 @@ public class FastJsonRedisSerializer<T> implements RedisSerializer<T> {
if (null == t) { if (null == t) {
return new byte[0]; 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 @Override

View File

@ -95,13 +95,6 @@ public interface CartService {
*/ */
void clean(); void clean();
/**
* 清空购物车无效数据
*
* @param way 购物车类型
*/
void cleanChecked(CartTypeEnum way);
/** /**
* 重新写入 * 重新写入
* *

View File

@ -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.GoodsAuthEnum;
import cn.lili.modules.goods.entity.enums.GoodsSalesModeEnum; import cn.lili.modules.goods.entity.enums.GoodsSalesModeEnum;
import cn.lili.modules.goods.entity.enums.GoodsStatusEnum; 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.GoodsSkuService;
import cn.lili.modules.goods.service.WholesaleService; import cn.lili.modules.goods.service.WholesaleService;
import cn.lili.modules.member.entity.dos.Member; 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.PointsGoodsService;
import cn.lili.modules.promotion.service.PromotionGoodsService; import cn.lili.modules.promotion.service.PromotionGoodsService;
import cn.lili.modules.search.entity.dos.EsGoodsIndex; import cn.lili.modules.search.entity.dos.EsGoodsIndex;
import cn.lili.modules.search.service.EsGoodsIndexService;
import cn.lili.modules.search.service.EsGoodsSearchService; import cn.lili.modules.search.service.EsGoodsSearchService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -98,16 +96,6 @@ public class CartServiceImpl implements CartService {
*/ */
@Autowired @Autowired
private EsGoodsSearchService esGoodsSearchService; 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; int newNum = oldNum + num;
this.checkSetGoodsQuantity(cartSkuVO, skuId, newNum); this.checkSetGoodsQuantity(cartSkuVO, skuId, newNum);
} }
cartSkuVO.setPromotionMap(promotionMap);
//计算购物车小计 //计算购物车小计
cartSkuVO.setSubTotal(CurrencyUtil.mul(cartSkuVO.getPurchasePrice(), cartSkuVO.getNum())); cartSkuVO.setSubTotal(CurrencyUtil.mul(cartSkuVO.getPurchasePrice(), cartSkuVO.getNum()));
} else { } else {
@ -254,7 +242,8 @@ public class CartServiceImpl implements CartService {
cartSkuVO.setChecked(checked); cartSkuVO.setChecked(checked);
} }
} }
cache.put(this.getOriginKey(CartTypeEnum.CART), tradeDTO);
this.resetTradeDTO(tradeDTO);
} }
@Override @Override
@ -269,7 +258,8 @@ public class CartServiceImpl implements CartService {
cartSkuVO.setChecked(checked); cartSkuVO.setChecked(checked);
} }
} }
cache.put(this.getOriginKey(CartTypeEnum.CART), tradeDTO);
resetTradeDTO(tradeDTO);
} }
@Override @Override
@ -282,7 +272,7 @@ public class CartServiceImpl implements CartService {
for (CartSkuVO cartSkuVO : cartSkuVOS) { for (CartSkuVO cartSkuVO : cartSkuVOS) {
cartSkuVO.setChecked(checked); cartSkuVO.setChecked(checked);
} }
cache.put(this.getOriginKey(CartTypeEnum.CART), tradeDTO); resetTradeDTO(tradeDTO);
} }
/** /**
@ -296,7 +286,6 @@ public class CartServiceImpl implements CartService {
} }
@Override @Override
@Transactional(rollbackFor = Exception.class)
public void delete(String[] skuIds) { public void delete(String[] skuIds) {
TradeDTO tradeDTO = this.readDTO(CartTypeEnum.CART); TradeDTO tradeDTO = this.readDTO(CartTypeEnum.CART);
List<CartSkuVO> cartSkuVOS = tradeDTO.getSkuList(); List<CartSkuVO> cartSkuVOS = tradeDTO.getSkuList();
@ -309,7 +298,7 @@ public class CartServiceImpl implements CartService {
} }
} }
cartSkuVOS.removeAll(deleteVos); cartSkuVOS.removeAll(deleteVos);
cache.put(this.getOriginKey(CartTypeEnum.CART), tradeDTO); resetTradeDTO(tradeDTO);
} }
@Override @Override
@ -331,17 +320,8 @@ public class CartServiceImpl implements CartService {
tradeDTO.setStoreCoupons(null); tradeDTO.setStoreCoupons(null);
//清除添加过的备注 //清除添加过的备注
tradeDTO.setStoreRemark(null); tradeDTO.setStoreRemark(null);
cache.put(this.getOriginKey(tradeDTO.getCartTypeEnum()), tradeDTO);
}
@Override resetTradeDTO(tradeDTO);
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));
}
} }
@Override @Override

View File

@ -220,7 +220,7 @@ public class StoreServiceImpl extends ServiceImpl<StoreMapper, Store> implements
//获取当前操作的店铺 //获取当前操作的店铺
Store store = getStoreByMember(); Store store = getStoreByMember();
//如果没有申请过店铺新增店铺 //如果没有申请过店铺新增店铺
if (!Optional.ofNullable(store).isPresent()) { if (store != null) {
AuthUser authUser = Objects.requireNonNull(UserContext.getCurrentUser()); AuthUser authUser = Objects.requireNonNull(UserContext.getCurrentUser());
Member member = memberService.getById(authUser.getId()); Member member = memberService.getById(authUser.getId());
store = new Store(member); store = new Store(member);
@ -231,12 +231,21 @@ public class StoreServiceImpl extends ServiceImpl<StoreMapper, Store> implements
BeanUtil.copyProperties(storeCompanyDTO, storeDetail); BeanUtil.copyProperties(storeCompanyDTO, storeDetail);
return storeDetailService.save(storeDetail); return storeDetailService.save(storeDetail);
} else { } else {
store = new Store();
BeanUtil.copyProperties(storeCompanyDTO, store); BeanUtil.copyProperties(storeCompanyDTO, store);
this.updateById(store); this.updateById(store);
//判断是否存在店铺详情如果没有则进行新建如果存在则进行修改 //判断是否存在店铺详情如果没有则进行新建如果存在则进行修改
StoreDetail storeDetail = storeDetailService.getStoreDetail(store.getId()); StoreDetail storeDetail = storeDetailService.getStoreDetail(store.getId());
BeanUtil.copyProperties(storeCompanyDTO, storeDetail); //如果店铺详情为空则new 否则复制对象然后保存即可
return storeDetailService.updateById(storeDetail); if (storeDetail == null) {
storeDetail = new StoreDetail();
storeDetail.setStoreId(store.getId());
BeanUtil.copyProperties(storeCompanyDTO, storeDetail);
return storeDetailService.save(storeDetail);
} else {
BeanUtil.copyProperties(storeCompanyDTO, storeDetail);
return storeDetailService.updateById(storeDetail);
}
} }
} }