Commit 22fd82946344cb408d369674a3211bb9b77f30b7

Authored by Jiang
1 parent 0b1c6a6f

修改购物车接口

mobsite-getway-rpc/src/main/java/com/diligrp/mobsite/getway/rpc/impl/ShoppingCartRPCImpl.java
1 package com.diligrp.mobsite.getway.rpc.impl; 1 package com.diligrp.mobsite.getway.rpc.impl;
2 2
3 import java.util.ArrayList; 3 import java.util.ArrayList;
4 -import java.util.HashMap;  
5 import java.util.List; 4 import java.util.List;
6 -import java.util.Map;  
7 5
8 import javax.annotation.Resource; 6 import javax.annotation.Resource;
9 7
@@ -12,6 +10,7 @@ import org.springframework.util.CollectionUtils; @@ -12,6 +10,7 @@ import org.springframework.util.CollectionUtils;
12 import com.b2c.myapp.common.api.shoppingCart.input.ShoppingCartListInput; 10 import com.b2c.myapp.common.api.shoppingCart.input.ShoppingCartListInput;
13 import com.b2c.myapp.common.api.shoppingCart.input.ShoppingCartSaveInput; 11 import com.b2c.myapp.common.api.shoppingCart.input.ShoppingCartSaveInput;
14 import com.b2c.myapp.common.api.shoppingCart.input.ShoppingCartUpdateInput; 12 import com.b2c.myapp.common.api.shoppingCart.input.ShoppingCartUpdateInput;
  13 +import com.b2c.myapp.common.api.shoppingCart.output.CartInfo;
15 import com.b2c.myapp.common.api.shoppingCart.output.ShoppingCartOutput; 14 import com.b2c.myapp.common.api.shoppingCart.output.ShoppingCartOutput;
16 import com.b2c.myapp.common.utils.BaseOutput; 15 import com.b2c.myapp.common.utils.BaseOutput;
17 import com.b2c.myapp.sdk.service.ShoppingCartService; 16 import com.b2c.myapp.sdk.service.ShoppingCartService;
@@ -30,7 +29,6 @@ import com.diligrp.mobsite.getway.domain.protocol.cart.ModifyAmountReq; @@ -30,7 +29,6 @@ import com.diligrp.mobsite.getway.domain.protocol.cart.ModifyAmountReq;
30 import com.diligrp.mobsite.getway.domain.protocol.cart.ModifyAmountResp; 29 import com.diligrp.mobsite.getway.domain.protocol.cart.ModifyAmountResp;
31 import com.diligrp.mobsite.getway.domain.protocol.cart.model.CartProduct; 30 import com.diligrp.mobsite.getway.domain.protocol.cart.model.CartProduct;
32 import com.diligrp.mobsite.getway.domain.protocol.cart.model.CartProductSku; 31 import com.diligrp.mobsite.getway.domain.protocol.cart.model.CartProductSku;
33 -import com.diligrp.mobsite.getway.domain.protocol.cart.model.ConfirmCartShopInfo;  
34 import com.diligrp.mobsite.getway.rpc.ShoppingCartRPC; 32 import com.diligrp.mobsite.getway.rpc.ShoppingCartRPC;
35 33
36 public class ShoppingCartRPCImpl implements ShoppingCartRPC { 34 public class ShoppingCartRPCImpl implements ShoppingCartRPC {
@@ -43,16 +41,17 @@ public class ShoppingCartRPCImpl implements ShoppingCartRPC { @@ -43,16 +41,17 @@ public class ShoppingCartRPCImpl implements ShoppingCartRPC {
43 GetCartByUserResp resp = new GetCartByUserResp(); 41 GetCartByUserResp resp = new GetCartByUserResp();
44 ShoppingCartListInput input = new ShoppingCartListInput(); 42 ShoppingCartListInput input = new ShoppingCartListInput();
45 input.setShopBuyerId(req.getUserId()); 43 input.setShopBuyerId(req.getUserId());
46 - BaseOutput<List<ShoppingCartOutput>> response = this.cartService.getCarts(input); 44 + BaseOutput<CartInfo> response = this.cartService.getCarts(input);
47 if (response == null) { 45 if (response == null) {
48 throw new ServiceException(ResultCode.NETWORK_FAILED, "获取购物车失败"); 46 throw new ServiceException(ResultCode.NETWORK_FAILED, "获取购物车失败");
49 } 47 }
50 if (response.getCode() != com.b2c.myapp.common.utils.ResultCode.OK) { 48 if (response.getCode() != com.b2c.myapp.common.utils.ResultCode.OK) {
51 throw new ServiceException(ResultCode.BUSINESS_FAILED, response.getResult()); 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 CartProduct cartProduct = new CartProduct(); 55 CartProduct cartProduct = new CartProduct();
57 cartProduct.setCid(output.getCid()); 56 cartProduct.setCid(output.getCid());
58 cartProduct.setPid(Long.valueOf(output.getPid())); 57 cartProduct.setPid(Long.valueOf(output.getPid()));
@@ -133,27 +132,30 @@ public class ShoppingCartRPCImpl implements ShoppingCartRPC { @@ -133,27 +132,30 @@ public class ShoppingCartRPCImpl implements ShoppingCartRPC {
133 ShoppingCartListInput input = new ShoppingCartListInput(); 132 ShoppingCartListInput input = new ShoppingCartListInput();
134 input.setShopBuyerId(req.getShopBuyerId()); 133 input.setShopBuyerId(req.getShopBuyerId());
135 input.setSkus(req.getSkus().toArray(new String[req.getSkus().size()])); 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 if (response == null) { 136 if (response == null) {
138 throw new ServiceException(ResultCode.NETWORK_FAILED, "获取购物车失败"); 137 throw new ServiceException(ResultCode.NETWORK_FAILED, "获取购物车失败");
139 } 138 }
140 if (response.getCode() != com.b2c.myapp.common.utils.ResultCode.OK) { 139 if (response.getCode() != com.b2c.myapp.common.utils.ResultCode.OK) {
141 throw new ServiceException(ResultCode.BUSINESS_FAILED, response.getResult()); 140 throw new ServiceException(ResultCode.BUSINESS_FAILED, response.getResult());
142 } 141 }
  142 + CartInfo data = response.getData();
143 ConfirmCartResp resp = new ConfirmCartResp(); 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 return resp; 159 return resp;
158 } 160 }
159 161