Commit b68f966e0ba26071daafadfc1e9ec04136c977eb

Authored by jiangchengyong
1 parent 66e82453

购物车总价计算update和修改个人信息

myapp-common/src/main/java/com/b2c/myapp/common/api/buyerInfo/input/BuyerInfoUpdateInput.java
... ... @@ -20,11 +20,13 @@ public class BuyerInfoUpdateInput implements Serializable{
20 20 public BuyerInfoUpdateInput() {
21 21 }
22 22  
  23 +
  24 + @ApiModelProperty(value = "")
  25 + private Long id;
23 26 /**
24 27 * 手机号
25 28 */
26 29 @ApiModelProperty(value = "手机号",required = true)
27   - @NotBlank(message="手机号不能为空")
28 30 private String mobilePhone;
29 31 /**
30 32 * 密码
... ... @@ -62,6 +64,14 @@ public class BuyerInfoUpdateInput implements Serializable{
62 64 @ApiModelProperty(value = "状态(1:有效 2:无效)")
63 65 private Integer yn;
64 66  
  67 + public Long getId() {
  68 + return id;
  69 + }
  70 +
  71 + public void setId(Long id) {
  72 + this.id = id;
  73 + }
  74 +
65 75 public void setMobilePhone (String mobilePhone){
66 76 this.mobilePhone = mobilePhone;
67 77 }
... ... @@ -114,6 +124,8 @@ public class BuyerInfoUpdateInput implements Serializable{
114 124 public String toString(){
115 125 StringBuffer sb = new StringBuffer();
116 126 sb.append("BuyerInfo [");
  127 + sb.append(", id = ");
  128 + sb.append(id);
117 129 sb.append(", mobilePhone = ");
118 130 sb.append(mobilePhone);
119 131 sb.append(", accountPwd = ");
... ...
myapp-common/src/main/java/com/b2c/myapp/common/api/sellerInfo/input/SellerInfoUpdateInput.java
... ... @@ -27,7 +27,6 @@ public class SellerInfoUpdateInput implements Serializable{
27 27 * 手机号
28 28 */
29 29 @ApiModelProperty(value = "手机号",required = true)
30   - @NotBlank(message="手机号不能为空")
31 30 private String mobilePhone;
32 31 /**
33 32 * 密码
... ...
myapp-common/src/main/java/com/b2c/myapp/common/api/shoppingCart/input/ShoppingCartInput.java
... ... @@ -6,6 +6,7 @@ import org.hibernate.validator.constraints.NotBlank;
6 6  
7 7 import javax.validation.constraints.NotNull;
8 8 import java.io.Serializable;
  9 +import java.math.BigDecimal;
9 10 import java.util.Date;
10 11  
11 12  
... ... @@ -43,9 +44,9 @@ public class ShoppingCartInput implements Serializable{
43 44 @NotBlank(message="名称不能为空")
44 45 private String sku;
45 46 /**
46   - * 单价
  47 + * 单价,单位(分)
47 48 */
48   - @ApiModelProperty(value = "单价",required = true)
  49 + @ApiModelProperty(value = "单价,单位(分)",required = true)
49 50 @NotNull(message="单价不能为空")
50 51 private Long price;
51 52 /**
... ... @@ -53,7 +54,7 @@ public class ShoppingCartInput implements Serializable{
53 54 */
54 55 @ApiModelProperty(value = "数量",required = true)
55 56 @NotNull(message="数量不能为空")
56   - private Long quantity;
  57 + private BigDecimal quantity;
57 58 /**
58 59 * 商品ID
59 60 */
... ... @@ -116,12 +117,15 @@ public class ShoppingCartInput implements Serializable{
116 117 public Long getPrice(){
117 118 return this.price;
118 119 }
119   - public void setQuantity (Long quantity){
120   - this.quantity = quantity;
  120 +
  121 + public BigDecimal getQuantity() {
  122 + return quantity;
121 123 }
122   - public Long getQuantity(){
123   - return this.quantity;
  124 +
  125 + public void setQuantity(BigDecimal quantity) {
  126 + this.quantity = quantity;
124 127 }
  128 +
125 129 public void setPid (String pid){
126 130 this.pid = pid;
127 131 }
... ...
myapp-common/src/main/java/com/b2c/myapp/common/api/shoppingCart/input/ShoppingCartSaveInput.java
... ... @@ -6,6 +6,7 @@ import org.hibernate.validator.constraints.NotBlank;
6 6  
7 7 import javax.validation.constraints.NotNull;
8 8 import java.io.Serializable;
  9 +import java.math.BigDecimal;
9 10  
10 11  
11 12 /**
... ... @@ -46,7 +47,7 @@ public class ShoppingCartSaveInput implements Serializable{
46 47 */
47 48 @ApiModelProperty(value = "数量",required = true)
48 49 @NotNull(message="数量不能为空")
49   - private Long quantity;
  50 + private BigDecimal quantity;
50 51 /**
51 52 * 商品ID
52 53 */
... ... @@ -78,12 +79,15 @@ public class ShoppingCartSaveInput implements Serializable{
78 79 public Long getPrice(){
79 80 return this.price;
80 81 }
81   - public void setQuantity (Long quantity){
82   - this.quantity = quantity;
  82 +
  83 + public BigDecimal getQuantity() {
  84 + return quantity;
83 85 }
84   - public Long getQuantity(){
85   - return this.quantity;
  86 +
  87 + public void setQuantity(BigDecimal quantity) {
  88 + this.quantity = quantity;
86 89 }
  90 +
87 91 public void setPid (String pid){
88 92 this.pid = pid;
89 93 }
... ...
myapp-common/src/main/java/com/b2c/myapp/common/api/shoppingCart/input/ShoppingCartUpdateInput.java
... ... @@ -5,6 +5,7 @@ import io.swagger.annotations.ApiModelProperty;
5 5  
6 6 import javax.validation.constraints.NotNull;
7 7 import java.io.Serializable;
  8 +import java.math.BigDecimal;
8 9 import java.util.Date;
9 10  
10 11  
... ... @@ -38,7 +39,7 @@ public class ShoppingCartUpdateInput implements Serializable{
38 39 * 数量
39 40 */
40 41 @ApiModelProperty(value = "数量")
41   - private Long quantity;
  42 + private BigDecimal quantity;
42 43  
43 44 public void setShopBuyerId (Long shopBuyerId){
44 45 this.shopBuyerId = shopBuyerId;
... ... @@ -58,11 +59,13 @@ public class ShoppingCartUpdateInput implements Serializable{
58 59 public Long getPrice(){
59 60 return this.price;
60 61 }
61   - public void setQuantity (Long quantity){
62   - this.quantity = quantity;
  62 +
  63 + public BigDecimal getQuantity() {
  64 + return quantity;
63 65 }
64   - public Long getQuantity(){
65   - return this.quantity;
  66 +
  67 + public void setQuantity(BigDecimal quantity) {
  68 + this.quantity = quantity;
66 69 }
67 70  
68 71 public String toString(){
... ...
myapp-common/src/main/java/com/b2c/myapp/common/api/shoppingCart/output/CartInfo.java
... ... @@ -3,14 +3,15 @@ package com.b2c.myapp.common.api.shoppingCart.output;
3 3 import io.swagger.annotations.ApiModelProperty;
4 4  
5 5 import java.io.Serializable;
  6 +import java.math.BigDecimal;
6 7 import java.util.List;
7 8  
8 9 /**
9 10 * Created by jiangchengyong on 2017/2/14.
10 11 */
11 12 public class CartInfo implements Serializable{
12   - @ApiModelProperty("总金额")
13   - private Long totalPrice;
  13 + @ApiModelProperty("总金额,单位分")
  14 + private BigDecimal totalPrice;
14 15 @ApiModelProperty("运费")
15 16 private Long postage;
16 17 @ApiModelProperty("包邮或免运费的最小商品金额")
... ... @@ -18,11 +19,11 @@ public class CartInfo implements Serializable{
18 19 @ApiModelProperty("购物项清单")
19 20 private List<ShoppingCartOutput> shoppingCartOutputs;
20 21  
21   - public Long getTotalPrice() {
  22 + public BigDecimal getTotalPrice() {
22 23 return totalPrice;
23 24 }
24 25  
25   - public void setTotalPrice(Long totalPrice) {
  26 + public void setTotalPrice(BigDecimal totalPrice) {
26 27 this.totalPrice = totalPrice;
27 28 }
28 29  
... ...
myapp-common/src/main/java/com/b2c/myapp/common/api/shoppingCart/output/ShoppingCartOutput.java
... ... @@ -3,6 +3,7 @@ package com.b2c.myapp.common.api.shoppingCart.output;
3 3 import io.swagger.annotations.ApiModelProperty;
4 4  
5 5 import java.io.Serializable;
  6 +import java.math.BigDecimal;
6 7 import java.util.Date;
7 8  
8 9  
... ... @@ -42,7 +43,7 @@ public class ShoppingCartOutput implements Serializable {
42 43 * 数量
43 44 */
44 45 @ApiModelProperty(value = "数量")
45   - private Long quantity;
  46 + private BigDecimal quantity;
46 47 /**
47 48 * 商品ID
48 49 */
... ... @@ -114,12 +115,15 @@ public class ShoppingCartOutput implements Serializable {
114 115 public Long getPrice(){
115 116 return this.price;
116 117 }
117   - public void setQuantity (Long quantity){
118   - this.quantity = quantity;
  118 +
  119 + public BigDecimal getQuantity() {
  120 + return quantity;
119 121 }
120   - public Long getQuantity(){
121   - return this.quantity;
  122 +
  123 + public void setQuantity(BigDecimal quantity) {
  124 + this.quantity = quantity;
122 125 }
  126 +
123 127 public void setPid (String pid){
124 128 this.pid = pid;
125 129 }
... ...
myapp-web/src/main/java/com/b2c/myapp/api/BuyerInfoApi.java
... ... @@ -84,6 +84,7 @@ public class BuyerInfoApi extends BaseRestFulApi {
84 84 BaseOutput<Boolean> output = BaseOutput.success();
85 85 try {
86 86 BeanValidator.validator(buyerInfoUpdateInput);
  87 + CommonUtils.throwParamError(null == buyerInfoUpdateInput.getMobilePhone() && null == buyerInfoUpdateInput.getId(),String.format("缺少修改的唯一标识(id或手机号)"));
87 88 Boolean result = buyerInfoService.update(BeanConver.copeBean(buyerInfoUpdateInput,BuyerInfo.class))>0;
88 89 output.setData(result);
89 90 } catch (Exception e) {
... ...
myapp-web/src/main/java/com/b2c/myapp/api/SellerInfoApi.java
... ... @@ -84,6 +84,7 @@ public class SellerInfoApi extends BaseRestFulApi {
84 84 BaseOutput<Boolean> output = BaseOutput.success();
85 85 try {
86 86 BeanValidator.validator(sellerInfoUpdateInput);
  87 + CommonUtils.throwParamError(null == sellerInfoUpdateInput.getMobilePhone() && null == sellerInfoUpdateInput.getId(),String.format("缺少修改的唯一标识(id或手机号)"));
87 88 Boolean result = sellerInfoService.update(BeanConver.copeBean(sellerInfoUpdateInput,SellerInfo.class))>0;
88 89 output.setData(result);
89 90 } catch (Exception e) {
... ...
myapp-web/src/main/java/com/b2c/myapp/domain/ShoppingCart.java
... ... @@ -2,6 +2,7 @@ package com.b2c.myapp.domain;
2 2  
3 3 import com.b2c.myapp.common.utils.base.BaseDomain;
4 4  
  5 +import java.math.BigDecimal;
5 6 import java.util.*;
6 7  
7 8 /**
... ... @@ -33,7 +34,7 @@ import java.util.*;
33 34 /**
34 35 * 数量
35 36 */
36   - private Long quantity;
  37 + private BigDecimal quantity;
37 38  
38 39 /**
39 40 * 商品ID
... ... @@ -81,12 +82,15 @@ import java.util.*;
81 82 public Long getPrice(){
82 83 return this.price;
83 84 }
84   - public void setQuantity (Long quantity){
85   - this.quantity = quantity;
  85 +
  86 + public BigDecimal getQuantity() {
  87 + return quantity;
86 88 }
87   - public Long getQuantity(){
88   - return this.quantity;
  89 +
  90 + public void setQuantity(BigDecimal quantity) {
  91 + this.quantity = quantity;
89 92 }
  93 +
90 94 public void setPid (String pid){
91 95 this.pid = pid;
92 96 }
... ...
myapp-web/src/main/java/com/b2c/myapp/service/impl/ShoppingCartServiceImpl.java
... ... @@ -20,6 +20,7 @@ import com.b2c.myapp.utils.BeanConver;
20 20 import com.diligrp.titan.sdk.constant.UnitEnum;
21 21 import com.diligrp.titan.sdk.domain.Product;
22 22 import com.diligrp.titan.sdk.domain.Sku;
  23 +import com.diligrp.website.util.format.MoneyUtils;
23 24 import org.apache.commons.collections.CollectionUtils;
24 25 import org.slf4j.Logger;
25 26 import org.slf4j.LoggerFactory;
... ... @@ -29,6 +30,7 @@ import org.springframework.cache.annotation.Cacheable;
29 30 import org.springframework.cache.annotation.Caching;
30 31 import org.springframework.stereotype.Service;
31 32  
  33 +import java.math.BigDecimal;
32 34 import java.util.ArrayList;
33 35 import java.util.Collections;
34 36 import java.util.List;
... ... @@ -75,7 +77,7 @@ public class ShoppingCartServiceImpl extends BaseServiceImpl&lt;ShoppingCart, Long&gt;
75 77 ShoppingCart shoppingCartPo = shoppingCartList.get(0);
76 78 shoppingCart.setId(shoppingCartPo.getId());
77 79 //多次添加数量累加
78   - shoppingCart.setQuantity(shoppingCartPo.getQuantity()+shoppingCart.getQuantity());
  80 + shoppingCart.setQuantity(shoppingCartPo.getQuantity().add(shoppingCart.getQuantity()));
79 81 shoppingCartDao.update(shoppingCart);
80 82 }
81 83  
... ... @@ -143,7 +145,7 @@ public class ShoppingCartServiceImpl extends BaseServiceImpl&lt;ShoppingCart, Long&gt;
143 145 skus.add(shoppingCartOutput.getSku());
144 146 }
145 147  
146   - Long totalPrice = 0l;
  148 + BigDecimal totalPrice = new BigDecimal(0);
147 149 Map<String, Product> productMap = titanService.getSkuInfoMap(skus);
148 150 for (ShoppingCartOutput shoppingCartOutput:shoppingCartOutputs
149 151 ) {
... ... @@ -153,7 +155,8 @@ public class ShoppingCartServiceImpl extends BaseServiceImpl&lt;ShoppingCart, Long&gt;
153 155 shoppingCartOutput.setCid(product.getCid());
154 156 shoppingCartOutput.setProductName(product.getName());
155 157 shoppingCartOutput.setSaleUnit(UnitEnum.getNameById(sku.getStoreUnit()));
156   - totalPrice += shoppingCartOutput.getCurrentPrice()*shoppingCartOutput.getQuantity();
  158 + BigDecimal price = new BigDecimal(shoppingCartOutput.getCurrentPrice());
  159 + totalPrice = totalPrice.add(shoppingCartOutput.getQuantity().multiply(price));
157 160 }
158 161  
159 162 CartInfo cartInfo = new CartInfo();
... ...
myapp-web/src/main/resources/mybatis/BuyerInfoMapper.xml
... ... @@ -189,7 +189,13 @@
189 189 <update id="update" parameterType="com.b2c.myapp.domain.BuyerInfo" >
190 190 UPDATE t_buyer_info
191 191 <include refid="UPDATE_COLUMN_SET"/>
192   - WHERE mobile_phone = #{mobilePhone}
  192 + WHERE 1 = 1
  193 + <if test="id != null and id != ''">
  194 + and `id`=#{id}
  195 + </if>
  196 + <if test="mobile_phone != null and mobile_phone != ''">
  197 + and `mobile_phone`=#{mobilePhone}
  198 + </if>
193 199 </update>
194 200  
195 201  
... ...
myapp-web/src/main/resources/mybatis/SellerInfoMapper.xml
... ... @@ -156,7 +156,13 @@
156 156 <update id="update" parameterType="com.b2c.myapp.domain.SellerInfo" >
157 157 UPDATE t_seller_info
158 158 <include refid="UPDATE_COLUMN_SET"/>
159   - WHERE mobile_phone = #{mobilePhone}
  159 + WHERE 1 = 1
  160 + <if test="id != null and id != ''">
  161 + and `id`=#{id}
  162 + </if>
  163 + <if test="mobile_phone != null and mobile_phone != ''">
  164 + and `mobile_phone`=#{mobilePhone}
  165 + </if>
160 166 </update>
161 167  
162 168  
... ...