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 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

View File

@ -95,13 +95,6 @@ public interface CartService {
*/
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.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

View File

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