|
|
@@ -68,17 +68,23 @@ public class BasketServiceImpl extends ServiceImpl<BasketMapper, Basket> impleme
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- @CacheEvict(cacheNames = "ShopCartItems", key = "#userId")
|
|
|
public void addShopCartItem(ChangeShopCartParam param, String userId) {
|
|
|
Basket basket = new Basket();
|
|
|
- basket.setBasketCount(param.getCount());
|
|
|
- basket.setBasketDate(new Date());
|
|
|
- basket.setProdId(param.getProdId());
|
|
|
- basket.setShopId(param.getShopId());
|
|
|
- basket.setUserId(userId);
|
|
|
- basket.setSkuId(param.getSkuId());
|
|
|
- basket.setDistributionCardNo(param.getDistributionCardNo());
|
|
|
- basketMapper.insert(basket);
|
|
|
+ ShopCartItemDto cartItem = basketMapper.getShopCartItemsByShopIdSkuIdUserId(param.getShopId(), param.getSkuId(), userId);
|
|
|
+ if (cartItem!=null){
|
|
|
+ basket.setBasketCount(cartItem.getBasketCount() + param.getCount());
|
|
|
+ basket.setBasketId(cartItem.getBasketId());
|
|
|
+ basketMapper.updateById(basket);
|
|
|
+ }else {
|
|
|
+ basket.setBasketCount(param.getCount());
|
|
|
+ basket.setBasketDate(new Date());
|
|
|
+ basket.setProdId(param.getProdId());
|
|
|
+ basket.setShopId(param.getShopId());
|
|
|
+ basket.setUserId(userId);
|
|
|
+ basket.setSkuId(param.getSkuId());
|
|
|
+ basket.setDistributionCardNo(param.getDistributionCardNo());
|
|
|
+ basketMapper.insert(basket);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -113,17 +119,18 @@ public class BasketServiceImpl extends ServiceImpl<BasketMapper, Basket> impleme
|
|
|
@Override
|
|
|
public List<ShopCartItemDto> getShopCartItems(String userId, Integer platform) {
|
|
|
// 在这个类里面要调用这里的缓存信息,并没有使用aop,所以不使用注解
|
|
|
- List<ShopCartItemDto> shopCartItemDtoList = cacheManagerUtil.getCache("ShopCartItems", userId);
|
|
|
- if (ObjectUtils.isNotEmpty(shopCartItemDtoList)) {
|
|
|
- return shopCartItemDtoList;
|
|
|
- }
|
|
|
+// List<ShopCartItemDto> shopCartItemDtoList = cacheManagerUtil.getCache("ShopCartItems", userId);
|
|
|
+ List<ShopCartItemDto> shopCartItemDtoList = Lists.newArrayList();
|
|
|
+// if (ObjectUtils.isNotEmpty(shopCartItemDtoList)) {
|
|
|
+// return shopCartItemDtoList;
|
|
|
+// }
|
|
|
shopCartItemDtoList = basketMapper.getShopCartItemsByPlatform(userId, platform);
|
|
|
for (ShopCartItemDto shopCartItemDto : shopCartItemDtoList) {
|
|
|
shopCartItemDto.setProductTotalAmount(Arith.mul(shopCartItemDto.getProdCount(), shopCartItemDto.getPrice()));
|
|
|
shopCartItemDto.setWeight(shopCartItemDto.getWeight());
|
|
|
shopCartItemDto.setWeightUnit(shopCartItemDto.getWeightUnit());
|
|
|
}
|
|
|
- cacheManagerUtil.putCache("ShopCartItems", userId, shopCartItemDtoList);
|
|
|
+// cacheManagerUtil.putCache("ShopCartItems", userId, shopCartItemDtoList);
|
|
|
return shopCartItemDtoList;
|
|
|
}
|
|
|
|