Commit c472aa11facf3986af6bb42b12a201a1cb65f235

Authored by jiangchengyong
1 parent c5f3b4ab

购物车相关接口改动

myapp-common/src/main/java/com/b2c/myapp/common/api/shoppingCart/output/CartInfo.java 0 → 100644
  1 +package com.b2c.myapp.common.api.shoppingCart.output;
  2 +
  3 +import io.swagger.annotations.ApiModelProperty;
  4 +
  5 +import java.io.Serializable;
  6 +import java.util.List;
  7 +
  8 +/**
  9 + * Created by jiangchengyong on 2017/2/14.
  10 + */
  11 +public class CartInfo implements Serializable{
  12 + @ApiModelProperty("总金额")
  13 + private Long totalPrice;
  14 + @ApiModelProperty("运费")
  15 + private Long postage;
  16 + @ApiModelProperty("包邮或免运费的最小商品金额")
  17 + private Long freeShippingPrice;
  18 + @ApiModelProperty("购物项清单")
  19 + private List<ShoppingCartOutput> shoppingCartOutputs;
  20 +
  21 + public Long getTotalPrice() {
  22 + return totalPrice;
  23 + }
  24 +
  25 + public void setTotalPrice(Long totalPrice) {
  26 + this.totalPrice = totalPrice;
  27 + }
  28 +
  29 + public Long getPostage() {
  30 + return postage;
  31 + }
  32 +
  33 + public void setPostage(Long postage) {
  34 + this.postage = postage;
  35 + }
  36 +
  37 + public Long getFreeShippingPrice() {
  38 + return freeShippingPrice;
  39 + }
  40 +
  41 + public void setFreeShippingPrice(Long freeShippingPrice) {
  42 + this.freeShippingPrice = freeShippingPrice;
  43 + }
  44 +
  45 + public List<ShoppingCartOutput> getShoppingCartOutputs() {
  46 + return shoppingCartOutputs;
  47 + }
  48 +
  49 + public void setShoppingCartOutputs(List<ShoppingCartOutput> shoppingCartOutputs) {
  50 + this.shoppingCartOutputs = shoppingCartOutputs;
  51 + }
  52 +
  53 + @Override
  54 + public String toString() {
  55 + return "CartInfo{" +
  56 + "totalPrice=" + totalPrice +
  57 + ", postage=" + postage +
  58 + ", freeShippingPrice=" + freeShippingPrice +
  59 + ", shoppingCartOutputs=" + shoppingCartOutputs +
  60 + '}';
  61 + }
  62 +}
... ...
myapp-sdk/src/main/java/com/b2c/myapp/sdk/service/ShoppingCartService.java
... ... @@ -3,6 +3,7 @@ package com.b2c.myapp.sdk.service;
3 3 import com.b2c.myapp.common.api.shoppingCart.input.ShoppingCartListInput;
4 4 import com.b2c.myapp.common.api.shoppingCart.input.ShoppingCartSaveInput;
5 5 import com.b2c.myapp.common.api.shoppingCart.input.ShoppingCartUpdateInput;
  6 +import com.b2c.myapp.common.api.shoppingCart.output.CartInfo;
6 7 import com.b2c.myapp.common.api.shoppingCart.output.ShoppingCartOutput;
7 8 import com.b2c.myapp.common.utils.BaseOutput;
8 9  
... ... @@ -47,6 +48,6 @@ public interface ShoppingCartService extends BaseService {
47 48 * @param shoppingCartListInput
48 49 * @return
49 50 */
50   - BaseOutput<List<ShoppingCartOutput>> getCarts(ShoppingCartListInput shoppingCartListInput);
  51 + BaseOutput<CartInfo> getCarts(ShoppingCartListInput shoppingCartListInput);
51 52  
52 53 }
... ...
myapp-sdk/src/main/java/com/b2c/myapp/sdk/service/impl/ShoppingCartServiceImpl.java
... ... @@ -5,6 +5,7 @@ import com.b2c.myapp.common.api.shoppingCart.input.ShoppingCartDelInput;
5 5 import com.b2c.myapp.common.api.shoppingCart.input.ShoppingCartListInput;
6 6 import com.b2c.myapp.common.api.shoppingCart.input.ShoppingCartSaveInput;
7 7 import com.b2c.myapp.common.api.shoppingCart.input.ShoppingCartUpdateInput;
  8 +import com.b2c.myapp.common.api.shoppingCart.output.CartInfo;
8 9 import com.b2c.myapp.common.api.shoppingCart.output.ShoppingCartOutput;
9 10 import com.b2c.myapp.common.utils.BaseOutput;
10 11 import com.b2c.myapp.sdk.service.ShoppingCartService;
... ... @@ -88,7 +89,7 @@ public class ShoppingCartServiceImpl extends BaseServiceImpl implements Shopping
88 89 * @return
89 90 */
90 91 @Override
91   - public BaseOutput<List<ShoppingCartOutput>> getCarts(ShoppingCartListInput shoppingCartListInput) {
92   - return super.httpPost("/api/shoppingCart/getCarts", shoppingCartListInput, new TypeReference<BaseOutput<List<ShoppingCartOutput>>>() {},true);
  92 + public BaseOutput<CartInfo> getCarts(ShoppingCartListInput shoppingCartListInput) {
  93 + return super.httpPost("/api/shoppingCart/getCarts", shoppingCartListInput, new TypeReference<BaseOutput<CartInfo>>() {},true);
93 94 }
94 95 }
... ...
myapp-web/src/main/java/com/b2c/myapp/api/ShoppingCartApi.java
... ... @@ -3,6 +3,7 @@ package com.b2c.myapp.api;
3 3  
4 4 import com.b2c.myapp.common.api.shopBuyer.input.ShopBuyerListInput;
5 5 import com.b2c.myapp.common.api.shoppingCart.input.*;
  6 +import com.b2c.myapp.common.api.shoppingCart.output.CartInfo;
6 7 import com.b2c.myapp.common.api.shoppingCart.output.ShoppingCartOutput;
7 8 import com.b2c.myapp.common.utils.BaseOutput;
8 9 import com.b2c.myapp.common.utils.base.Page;
... ... @@ -109,11 +110,10 @@ public class ShoppingCartApi extends BaseRestFulApi {
109 110 @ApiImplicitParam(paramType = "body",name = "shoppingCartListInput",dataType = "ShoppingCartListInput", required = true, value = "skus为null时,返回该用户下所有购物项")
110 111 @RequestMapping(value = "/getCarts", method = RequestMethod.POST)
111 112 @ResponseBody
112   - public BaseOutput<List<ShoppingCartOutput>> getCarts(@RequestBody ShoppingCartListInput shoppingCartListInput){
113   - BaseOutput<List<ShoppingCartOutput>> output = BaseOutput.success();
  113 + public BaseOutput<CartInfo> getCarts(@RequestBody ShoppingCartListInput shoppingCartListInput){
  114 + BaseOutput<CartInfo> output = BaseOutput.success();
114 115 try {
115   - List<ShoppingCartOutput> result = BeanConver.copeList(shoppingCartService.getCarts(shoppingCartListInput),ShoppingCartOutput.class);
116   - output.setData(result);
  116 + output.setData(shoppingCartService.getCarts(shoppingCartListInput));
117 117 } catch (Exception e) {
118 118 handleException(output, e);
119 119 }
... ...
myapp-web/src/main/java/com/b2c/myapp/service/ShoppingCartService.java
1 1 package com.b2c.myapp.service;
2 2  
3 3 import com.b2c.myapp.common.api.shoppingCart.input.ShoppingCartListInput;
  4 +import com.b2c.myapp.common.api.shoppingCart.output.CartInfo;
4 5 import com.b2c.myapp.common.api.shoppingCart.output.ShoppingCartOutput;
5 6 import com.b2c.myapp.domain.ShoppingCart;
6 7  
... ... @@ -45,6 +46,6 @@ public interface ShoppingCartService extends BaseService&lt;ShoppingCart, Long&gt; {
45 46 * @param shoppingCartListInput
46 47 * @return
47 48 */
48   - List<ShoppingCartOutput> getCarts(ShoppingCartListInput shoppingCartListInput);
  49 + CartInfo getCarts(ShoppingCartListInput shoppingCartListInput);
49 50  
50 51 }
... ...
myapp-web/src/main/java/com/b2c/myapp/service/impl/ShoppingCartServiceImpl.java
1 1 package com.b2c.myapp.service.impl;
2 2  
3 3 import com.b2c.myapp.common.api.shop.input.ShopListInput;
  4 +import com.b2c.myapp.common.api.shopBuyer.output.ShopBuyerKeyOutput;
4 5 import com.b2c.myapp.common.api.shoppingCart.input.ShoppingCartListInput;
  6 +import com.b2c.myapp.common.api.shoppingCart.output.CartInfo;
5 7 import com.b2c.myapp.common.api.shoppingCart.output.ShoppingCartOutput;
6 8 import com.b2c.myapp.common.utils.base.BaseDao;
  9 +import com.b2c.myapp.dao.ShopDao;
  10 +import com.b2c.myapp.domain.Shop;
  11 +import com.b2c.myapp.domain.ShopBuyer;
7 12 import com.b2c.myapp.domain.ShoppingCart;
8 13 import com.b2c.myapp.rpc.TitanClientRPCService;
  14 +import com.b2c.myapp.service.ShopBuyerService;
  15 +import com.b2c.myapp.service.ShopService;
9 16 import com.b2c.myapp.service.ShoppingCartService;
10 17 import com.b2c.myapp.dao.ShoppingCartDao;
11 18  
... ... @@ -39,6 +46,10 @@ public class ShoppingCartServiceImpl extends BaseServiceImpl&lt;ShoppingCart, Long&gt;
39 46 @Autowired
40 47 private ShoppingCartDao shoppingCartDao;
41 48 @Autowired
  49 + private ShopService shopService;
  50 + @Autowired
  51 + private ShopBuyerService shopBuyerService;
  52 + @Autowired
42 53 private TitanClientRPCService titanService;
43 54  
44 55 public BaseDao<ShoppingCart, Long> getDao() {
... ... @@ -115,7 +126,7 @@ public class ShoppingCartServiceImpl extends BaseServiceImpl&lt;ShoppingCart, Long&gt;
115 126 * @return
116 127 */
117 128 @Override
118   - public List<ShoppingCartOutput> getCarts(ShoppingCartListInput shoppingCartListInput) {
  129 + public CartInfo getCarts(ShoppingCartListInput shoppingCartListInput) {
119 130 List<ShoppingCart> shoppingCarts = null;
120 131 if(null == shoppingCartListInput.getSkus()||shoppingCartListInput.getSkus().length==0){
121 132 //购物车
... ... @@ -131,6 +142,8 @@ public class ShoppingCartServiceImpl extends BaseServiceImpl&lt;ShoppingCart, Long&gt;
131 142 ) {
132 143 skus.add(shoppingCartOutput.getSku());
133 144 }
  145 +
  146 + Long totalPrice = 0l;
134 147 Map<String, Product> productMap = titanService.getSkuInfoMap(skus);
135 148 for (ShoppingCartOutput shoppingCartOutput:shoppingCartOutputs
136 149 ) {
... ... @@ -140,8 +153,20 @@ public class ShoppingCartServiceImpl extends BaseServiceImpl&lt;ShoppingCart, Long&gt;
140 153 shoppingCartOutput.setCid(product.getCid());
141 154 shoppingCartOutput.setProductName(product.getName());
142 155 shoppingCartOutput.setSaleUnit(UnitEnum.getNameById(sku.getStoreUnit()));
  156 + totalPrice += shoppingCartOutput.getCurrentPrice();
  157 + }
  158 +
  159 + CartInfo cartInfo = new CartInfo();
  160 + cartInfo.setShoppingCartOutputs(shoppingCartOutputs);
  161 +
  162 + ShopBuyerKeyOutput shopBuyerKeyOutput = shopBuyerService.getShopBuyerKeys(shoppingCartListInput.getShopBuyerId());
  163 + Shop shop = shopService.get(shopBuyerKeyOutput.getShopId());
  164 + if(shop != null){
  165 + cartInfo.setPostage(shop.getPostage());
  166 + cartInfo.setFreeShippingPrice(shop.getFreeShippingPrice());
  167 + cartInfo.setTotalPrice(totalPrice);
143 168 }
144   - return shoppingCartOutputs;
  169 + return cartInfo;
145 170 }
146 171  
147 172 /**
... ...