package com.caimei.service.impl; import com.caimei.mapper.ShoppingCartMapper; import com.caimei.model.ResponseJson; import com.caimei.model.dto.CartDto; import com.caimei.model.po.CmMallCartPo; import com.caimei.model.vo.ShopVo; import com.caimei.service.ShoppingCartService; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.HashMap; import java.util.List; import java.util.Map; /** * Description * * @author : plf * @date : 2021/3/23 */ @Service public class ShoppingCartServiceImpl implements ShoppingCartService { @Resource private ShoppingCartMapper shoppingCartMapper; @Override public ResponseJson addShoppingCart(CartDto cart) { CmMallCartPo cartPo = shoppingCartMapper.findCartProduct(cart.getUserId(), cart.getProductId()); if (cartPo == null) { shoppingCartMapper.insertCart(cart); } else { int productCount = cartPo.getProductCount() + cart.getProductCount(); shoppingCartMapper.updateByProductCount(cartPo.getId(), productCount); } Integer cartQuantity = shoppingCartMapper.getCartQuantity(cart.getUserId()); return ResponseJson.success(cartQuantity); } @Override public ResponseJson getCartQuantity(Integer userId) { Integer cartQuantity = shoppingCartMapper.getCartQuantity(userId); return ResponseJson.success(cartQuantity); } @Override public ResponseJson> shoppingInfo(Integer userId) { Map map = new HashMap<>(3); List shopList = shoppingCartMapper.findCartShop(userId); shopList.forEach(shop -> { }); return null; } }