|
@@ -5,10 +5,13 @@ import cn.newfeifan.mall.module.product.api.sku.ProductSkuApi;
|
|
|
import cn.newfeifan.mall.module.product.api.sku.dto.ProductSkuRespDTO;
|
|
|
import cn.newfeifan.mall.module.product.api.spu.ProductSpuApi;
|
|
|
import cn.newfeifan.mall.module.product.api.spu.dto.ProductSpuRespDTO;
|
|
|
+import cn.newfeifan.mall.module.sale.dal.dataobject.shop.ShopDO;
|
|
|
+import cn.newfeifan.mall.module.sale.dal.mysql.shop.ShopMapper;
|
|
|
import cn.newfeifan.mall.module.trade.controller.app.cart.vo.*;
|
|
|
import cn.newfeifan.mall.module.trade.convert.cart.TradeCartConvert;
|
|
|
import cn.newfeifan.mall.module.trade.dal.dataobject.cart.CartDO;
|
|
|
import cn.newfeifan.mall.module.trade.dal.mysql.cart.CartMapper;
|
|
|
+import io.swagger.v3.oas.annotations.media.Schema;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
@@ -34,6 +37,9 @@ import static java.util.Collections.emptyList;
|
|
|
@Validated
|
|
|
public class CartServiceImpl implements CartService {
|
|
|
|
|
|
+ @Resource
|
|
|
+ private ShopMapper shopMapper;
|
|
|
+
|
|
|
@Resource
|
|
|
private CartMapper cartMapper;
|
|
|
|
|
@@ -143,14 +149,37 @@ public class CartServiceImpl implements CartService {
|
|
|
|
|
|
// 查询 SPU、SKU 列表
|
|
|
List<ProductSpuRespDTO> spus = productSpuApi.getSpuList(convertSet(carts, CartDO::getSpuId));
|
|
|
- List<ProductSkuRespDTO> skus = productSkuApi.getSkuList(convertSet(carts, CartDO::getSkuId));
|
|
|
+ List<ProductSkuRespDTO> skus = productSkuApi.getSkuList(convertSet(carts, CartDO::getSkuId));//Ben 已为skus每项补上了shopid
|
|
|
|
|
|
// 如果 SPU 被删除,则删除购物车对应的商品。延迟删除
|
|
|
// 为什么不是 SKU 被删除呢?因为 SKU 被删除时,还可以通过 SPU 选择其它 SKU
|
|
|
deleteCartIfSpuDeleted(carts, spus);
|
|
|
|
|
|
+ AppCartListRespVO appCartListRespVO = TradeCartConvert.INSTANCE.convertList(carts, spus, skus);
|
|
|
+
|
|
|
+ Map<Long,List<Long>> shopSkuMap = new HashMap<Long,List<Long>>();
|
|
|
+ for(ProductSkuRespDTO productSkuRespDTO:skus){
|
|
|
+ Long shopId = productSkuRespDTO.getShopId();
|
|
|
+ Long skuId = productSkuRespDTO.getId();
|
|
|
+ List<Long> skuIds = shopSkuMap.get(shopId);
|
|
|
+ if(skuIds==null){
|
|
|
+ skuIds = new ArrayList<Long>();
|
|
|
+ shopSkuMap.put(shopId,skuIds);
|
|
|
+ }
|
|
|
+ skuIds.add(skuId);
|
|
|
+ }
|
|
|
+ appCartListRespVO.setShopSkuMap(shopSkuMap);
|
|
|
+
|
|
|
+ List<ShopDO> shopDOList = shopMapper.selectList("id", shopSkuMap.keySet());
|
|
|
+ //key为店铺ID,value为店铺名
|
|
|
+ Map<Long,String> shopNameMap = new HashMap<Long,String>();
|
|
|
+ for(ShopDO shopDO:shopDOList){
|
|
|
+ shopNameMap.put(shopDO.getId(),shopDO.getName());
|
|
|
+ }
|
|
|
+ appCartListRespVO.setShopNameMap(shopNameMap);
|
|
|
+
|
|
|
// 拼接数据
|
|
|
- return TradeCartConvert.INSTANCE.convertList(carts, spus, skus);
|
|
|
+ return appCartListRespVO;
|
|
|
}
|
|
|
|
|
|
@Override
|