Commit 22fd82946344cb408d369674a3211bb9b77f30b7

Authored by Jiang
1 parent 0b1c6a6f

修改购物车接口

mobsite-getway-rpc/src/main/java/com/diligrp/mobsite/getway/rpc/impl/ShoppingCartRPCImpl.java
1 1 package com.diligrp.mobsite.getway.rpc.impl;
2 2  
3 3 import java.util.ArrayList;
4   -import java.util.HashMap;
5 4 import java.util.List;
6   -import java.util.Map;
7 5  
8 6 import javax.annotation.Resource;
9 7  
... ... @@ -12,6 +10,7 @@ import org.springframework.util.CollectionUtils;
12 10 import com.b2c.myapp.common.api.shoppingCart.input.ShoppingCartListInput;
13 11 import com.b2c.myapp.common.api.shoppingCart.input.ShoppingCartSaveInput;
14 12 import com.b2c.myapp.common.api.shoppingCart.input.ShoppingCartUpdateInput;
  13 +import com.b2c.myapp.common.api.shoppingCart.output.CartInfo;
15 14 import com.b2c.myapp.common.api.shoppingCart.output.ShoppingCartOutput;
16 15 import com.b2c.myapp.common.utils.BaseOutput;
17 16 import com.b2c.myapp.sdk.service.ShoppingCartService;
... ... @@ -30,7 +29,6 @@ import com.diligrp.mobsite.getway.domain.protocol.cart.ModifyAmountReq;
30 29 import com.diligrp.mobsite.getway.domain.protocol.cart.ModifyAmountResp;
31 30 import com.diligrp.mobsite.getway.domain.protocol.cart.model.CartProduct;
32 31 import com.diligrp.mobsite.getway.domain.protocol.cart.model.CartProductSku;
33   -import com.diligrp.mobsite.getway.domain.protocol.cart.model.ConfirmCartShopInfo;
34 32 import com.diligrp.mobsite.getway.rpc.ShoppingCartRPC;
35 33  
36 34 public class ShoppingCartRPCImpl implements ShoppingCartRPC {
... ... @@ -43,16 +41,17 @@ public class ShoppingCartRPCImpl implements ShoppingCartRPC {
43 41 GetCartByUserResp resp = new GetCartByUserResp();
44 42 ShoppingCartListInput input = new ShoppingCartListInput();
45 43 input.setShopBuyerId(req.getUserId());
46   - BaseOutput<List<ShoppingCartOutput>> response = this.cartService.getCarts(input);
  44 + BaseOutput<CartInfo> response = this.cartService.getCarts(input);
47 45 if (response == null) {
48 46 throw new ServiceException(ResultCode.NETWORK_FAILED, "获取购物车失败");
49 47 }
50 48 if (response.getCode() != com.b2c.myapp.common.utils.ResultCode.OK) {
51 49 throw new ServiceException(ResultCode.BUSINESS_FAILED, response.getResult());
52 50 }
53   - if (CollectionUtils.isEmpty(response.getData())) {
54   - List<CartProduct> cartGoods = new ArrayList<>(response.getData().size());
55   - for (ShoppingCartOutput output : response.getData()) {
  51 + CartInfo data = response.getData();
  52 + if (data != null && !CollectionUtils.isEmpty(data.getShoppingCartOutputs())) {
  53 + List<CartProduct> cartGoods = new ArrayList<>(data.getShoppingCartOutputs().size());
  54 + for (ShoppingCartOutput output : data.getShoppingCartOutputs()) {
56 55 CartProduct cartProduct = new CartProduct();
57 56 cartProduct.setCid(output.getCid());
58 57 cartProduct.setPid(Long.valueOf(output.getPid()));
... ... @@ -133,27 +132,30 @@ public class ShoppingCartRPCImpl implements ShoppingCartRPC {
133 132 ShoppingCartListInput input = new ShoppingCartListInput();
134 133 input.setShopBuyerId(req.getShopBuyerId());
135 134 input.setSkus(req.getSkus().toArray(new String[req.getSkus().size()]));
136   - BaseOutput<List<ShoppingCartOutput>> response = this.cartService.getCarts(input);
  135 + BaseOutput<CartInfo> response = this.cartService.getCarts(input);
137 136 if (response == null) {
138 137 throw new ServiceException(ResultCode.NETWORK_FAILED, "获取购物车失败");
139 138 }
140 139 if (response.getCode() != com.b2c.myapp.common.utils.ResultCode.OK) {
141 140 throw new ServiceException(ResultCode.BUSINESS_FAILED, response.getResult());
142 141 }
  142 + CartInfo data = response.getData();
143 143 ConfirmCartResp resp = new ConfirmCartResp();
144   - List<CartProductSku> skus = new ArrayList<>(response.getData().size());
145   - for (ShoppingCartOutput output : response.getData()) {
146   - CartProductSku sku = new CartProductSku();
147   - sku.setPrice(output.getCurrentPrice());
148   - sku.setOldPrice(output.getPrice());
149   - sku.setProductId(Long.valueOf(output.getPid()));
150   - sku.setProductName(output.getProductName());
151   - sku.setSku(output.getSku());
152   - sku.setBuyNum(output.getQuantity().intValue());
153   - sku.setUnit(output.getSaleUnit());
154   - skus.add(sku);
  144 + if (data != null && !CollectionUtils.isEmpty(data.getShoppingCartOutputs())) {
  145 + List<CartProductSku> skus = new ArrayList<>(data.getShoppingCartOutputs().size());
  146 + for (ShoppingCartOutput output : data.getShoppingCartOutputs()) {
  147 + CartProductSku sku = new CartProductSku();
  148 + sku.setPrice(output.getCurrentPrice());
  149 + sku.setOldPrice(output.getPrice());
  150 + sku.setProductId(Long.valueOf(output.getPid()));
  151 + sku.setProductName(output.getProductName());
  152 + sku.setSku(output.getSku());
  153 + sku.setBuyNum(output.getQuantity().intValue());
  154 + sku.setUnit(output.getSaleUnit());
  155 + skus.add(sku);
  156 + }
  157 + resp.setSkus(skus);
155 158 }
156   - resp.setSkus(skus);
157 159 return resp;
158 160 }
159 161  
... ...