Commit 9e0e540a1bcd2c766a617254f09cda4abbb86ec4
1 parent
03338362
优化订单提交商品库查询及验证逻辑,订单预估金额解决商品单位为斤小数点问题
Showing
27 changed files
with
391 additions
and
305 deletions
b2c-orders-client/pom.xml
b2c-orders-client/src/main/java/com/b2c/orders/domain/client/dto/request/OrderDetailRequestDto.java
... | ... | @@ -2,6 +2,8 @@ package com.b2c.orders.domain.client.dto.request; |
2 | 2 | |
3 | 3 | import java.io.Serializable; |
4 | 4 | |
5 | +import javax.validation.constraints.NotNull; | |
6 | + | |
5 | 7 | import io.swagger.annotations.ApiParam; |
6 | 8 | |
7 | 9 | public class OrderDetailRequestDto implements Serializable { |
... | ... | @@ -12,6 +14,7 @@ public class OrderDetailRequestDto implements Serializable { |
12 | 14 | private static final long serialVersionUID = 1588667432248557550L; |
13 | 15 | |
14 | 16 | @ApiParam("订单id") |
17 | + @NotNull(message = "订单id不能为空") | |
15 | 18 | private Long orderId; |
16 | 19 | |
17 | 20 | public Long getOrderId() { |
... | ... |
b2c-orders-client/src/main/java/com/b2c/orders/domain/client/dto/request/OrderItemDto.java
1 | 1 | package com.b2c.orders.domain.client.dto.request; |
2 | 2 | |
3 | 3 | import java.io.Serializable; |
4 | +import java.math.BigDecimal; | |
4 | 5 | |
5 | 6 | import javax.validation.constraints.NotNull; |
6 | 7 | |
... | ... | @@ -18,7 +19,8 @@ public class OrderItemDto implements Serializable { |
18 | 19 | private String sku; |
19 | 20 | @ApiParam("购买数量") |
20 | 21 | @NotNull(message = "购买数量不能为空") |
21 | - private Integer amount; | |
22 | + private BigDecimal amount; | |
23 | + private Long skuPrice; | |
22 | 24 | |
23 | 25 | public String getSku() { |
24 | 26 | return sku; |
... | ... | @@ -28,12 +30,20 @@ public class OrderItemDto implements Serializable { |
28 | 30 | this.sku = sku; |
29 | 31 | } |
30 | 32 | |
31 | - public Integer getAmount() { | |
33 | + public BigDecimal getAmount() { | |
32 | 34 | return amount; |
33 | 35 | } |
34 | 36 | |
35 | - public void setAmount(Integer amount) { | |
37 | + public void setAmount(BigDecimal amount) { | |
36 | 38 | this.amount = amount; |
37 | 39 | } |
38 | 40 | |
41 | + public Long getSkuPrice() { | |
42 | + return skuPrice; | |
43 | + } | |
44 | + | |
45 | + public void setSkuPrice(Long skuPrice) { | |
46 | + this.skuPrice = skuPrice; | |
47 | + } | |
48 | + | |
39 | 49 | } |
... | ... |
b2c-orders-client/src/main/java/com/b2c/orders/domain/client/dto/request/SubmitOrderRequestDto.java
... | ... | @@ -3,6 +3,9 @@ package com.b2c.orders.domain.client.dto.request; |
3 | 3 | import java.io.Serializable; |
4 | 4 | import java.util.List; |
5 | 5 | |
6 | +import javax.validation.constraints.NotNull; | |
7 | +import javax.validation.constraints.Size; | |
8 | + | |
6 | 9 | import io.swagger.annotations.ApiModelProperty; |
7 | 10 | |
8 | 11 | public class SubmitOrderRequestDto implements Serializable { |
... | ... | @@ -13,28 +16,38 @@ public class SubmitOrderRequestDto implements Serializable { |
13 | 16 | private static final long serialVersionUID = 5060629945327592074L; |
14 | 17 | |
15 | 18 | @ApiModelProperty(value = "买家绑定店铺的id") |
19 | + @NotNull(message = "买家绑定店铺id不能为空") | |
16 | 20 | private Long shopBuyerId; |
17 | 21 | @ApiModelProperty(value = "市场id", required = true) |
22 | + @NotNull(message = "市场id不能为空") | |
18 | 23 | private Long marketId; |
19 | 24 | @ApiModelProperty(value = "配送类型", required = true) |
25 | + @NotNull(message = "送货类型不能为空") | |
20 | 26 | private Integer deliveryType; |
21 | 27 | @ApiModelProperty(value = "买家备注说明", required = true) |
22 | 28 | private String buyerMemo; |
23 | 29 | @ApiModelProperty(value = "送货时间") |
24 | 30 | private String deliveryTime; |
25 | 31 | @ApiModelProperty("收货人姓名") |
32 | + @NotNull(message = "收货人姓名不能为空") | |
26 | 33 | private String receiverName; |
27 | 34 | @ApiModelProperty("送货地址") |
35 | + @NotNull(message = "送货地址不能为空") | |
28 | 36 | private String deliveryAddress; |
29 | 37 | @ApiModelProperty("城市id") |
38 | + @NotNull(message = "城市id不能为空") | |
30 | 39 | private Long cityId; |
31 | 40 | @ApiModelProperty("城市名称") |
41 | + @NotNull(message = "城市名称不能为空") | |
32 | 42 | private String cityName; |
33 | 43 | @ApiModelProperty("收货人电话") |
44 | + @NotNull(message = "收货人电话不能为空") | |
34 | 45 | private String receiverPhoneNumber; |
35 | 46 | @ApiModelProperty(value = "提货时间") |
36 | 47 | private String reservationTime; |
37 | 48 | @ApiModelProperty(value = "订单项", required = true) |
49 | + @NotNull(message = "订单项不能为空") | |
50 | + @Size(min = 1, message = "订单项不能为空") | |
38 | 51 | private List<OrderItemDto> orderItems; |
39 | 52 | |
40 | 53 | public Long getShopBuyerId() { |
... | ... |
b2c-orders-client/src/main/java/com/b2c/orders/domain/client/dto/response/OrderDetailResponseDto.java
1 | 1 | package com.b2c.orders.domain.client.dto.response; |
2 | 2 | |
3 | 3 | import java.io.Serializable; |
4 | +import java.math.BigDecimal; | |
4 | 5 | |
5 | 6 | public class OrderDetailResponseDto implements Serializable { |
6 | 7 | |
... | ... | @@ -31,12 +32,13 @@ public class OrderDetailResponseDto implements Serializable { |
31 | 32 | private String deliveryAddress; |
32 | 33 | /** 提货时间 */ |
33 | 34 | private String reservationTime; |
35 | + private String pickUpAddress; | |
34 | 36 | /** 订单提交时间 */ |
35 | 37 | private String submitTime; |
36 | 38 | /** 支付类型 */ |
37 | 39 | private Integer payType; |
38 | 40 | /** 预计总金额 */ |
39 | - private Long totalPrice; | |
41 | + private BigDecimal totalPrice; | |
40 | 42 | /** |
41 | 43 | * 实际价格,有商家接单后修改 |
42 | 44 | */ |
... | ... | @@ -119,6 +121,14 @@ public class OrderDetailResponseDto implements Serializable { |
119 | 121 | this.reservationTime = reservationTime; |
120 | 122 | } |
121 | 123 | |
124 | + public String getPickUpAddress() { | |
125 | + return pickUpAddress; | |
126 | + } | |
127 | + | |
128 | + public void setPickUpAddress(String pickUpAddress) { | |
129 | + this.pickUpAddress = pickUpAddress; | |
130 | + } | |
131 | + | |
122 | 132 | public String getSubmitTime() { |
123 | 133 | return submitTime; |
124 | 134 | } |
... | ... | @@ -135,11 +145,11 @@ public class OrderDetailResponseDto implements Serializable { |
135 | 145 | this.payType = payType; |
136 | 146 | } |
137 | 147 | |
138 | - public Long getTotalPrice() { | |
148 | + public BigDecimal getTotalPrice() { | |
139 | 149 | return totalPrice; |
140 | 150 | } |
141 | 151 | |
142 | - public void setTotalPrice(Long totalPrice) { | |
152 | + public void setTotalPrice(BigDecimal totalPrice) { | |
143 | 153 | this.totalPrice = totalPrice; |
144 | 154 | } |
145 | 155 | |
... | ... |
b2c-orders-client/src/main/java/com/b2c/orders/domain/client/dto/response/OrderListResponseDto.java
1 | 1 | package com.b2c.orders.domain.client.dto.response; |
2 | 2 | |
3 | +import java.io.Serializable; | |
4 | +import java.math.BigDecimal; | |
3 | 5 | import java.util.List; |
4 | 6 | |
5 | 7 | import com.fasterxml.jackson.annotation.JsonInclude; |
... | ... | @@ -8,7 +10,12 @@ import com.fasterxml.jackson.annotation.JsonInclude.Include; |
8 | 10 | import io.swagger.annotations.ApiModelProperty; |
9 | 11 | |
10 | 12 | @JsonInclude(Include.NON_EMPTY) |
11 | -public class OrderListResponseDto { | |
13 | +public class OrderListResponseDto implements Serializable { | |
14 | + | |
15 | + /** | |
16 | + * | |
17 | + */ | |
18 | + private static final long serialVersionUID = 3948759694608213551L; | |
12 | 19 | |
13 | 20 | @ApiModelProperty("订单id") |
14 | 21 | private Long id; |
... | ... | @@ -62,6 +69,8 @@ public class OrderListResponseDto { |
62 | 69 | */ |
63 | 70 | @ApiModelProperty("提货时间") |
64 | 71 | private String reservationTime; |
72 | + @ApiModelProperty("提货地址") | |
73 | + private String pickUpAddress; | |
65 | 74 | /** |
66 | 75 | * 买家确认收货时间 |
67 | 76 | */ |
... | ... | @@ -81,7 +90,7 @@ public class OrderListResponseDto { |
81 | 90 | * 总金额 |
82 | 91 | */ |
83 | 92 | @ApiModelProperty("总金额") |
84 | - private Long totalPrice; | |
93 | + private BigDecimal totalPrice; | |
85 | 94 | /** |
86 | 95 | * 接单后修改的价格 |
87 | 96 | */ |
... | ... | @@ -181,6 +190,14 @@ public class OrderListResponseDto { |
181 | 190 | this.reservationTime = reservationTime; |
182 | 191 | } |
183 | 192 | |
193 | + public String getPickUpAddress() { | |
194 | + return pickUpAddress; | |
195 | + } | |
196 | + | |
197 | + public void setPickUpAddress(String pickUpAddress) { | |
198 | + this.pickUpAddress = pickUpAddress; | |
199 | + } | |
200 | + | |
184 | 201 | public String getBuyerConfirmTime() { |
185 | 202 | return buyerConfirmTime; |
186 | 203 | } |
... | ... | @@ -205,11 +222,11 @@ public class OrderListResponseDto { |
205 | 222 | this.payType = payType; |
206 | 223 | } |
207 | 224 | |
208 | - public Long getTotalPrice() { | |
225 | + public BigDecimal getTotalPrice() { | |
209 | 226 | return totalPrice; |
210 | 227 | } |
211 | 228 | |
212 | - public void setTotalPrice(Long totalPrice) { | |
229 | + public void setTotalPrice(BigDecimal totalPrice) { | |
213 | 230 | this.totalPrice = totalPrice; |
214 | 231 | } |
215 | 232 | |
... | ... |
b2c-orders-client/src/test/java/com/b2c/orders/client/service/OrderServiceTestCase.java deleted
100644 → 0
1 | -package com.b2c.orders.client.service; | |
2 | - | |
3 | -import static org.junit.Assert.*; | |
4 | - | |
5 | -import java.util.ArrayList; | |
6 | -import java.util.List; | |
7 | - | |
8 | -import org.junit.After; | |
9 | -import org.junit.AfterClass; | |
10 | -import org.junit.Assert; | |
11 | -import org.junit.Before; | |
12 | -import org.junit.BeforeClass; | |
13 | -import org.junit.Test; | |
14 | - | |
15 | -import com.b2c.orders.domain.client.OrderClient; | |
16 | -import com.b2c.orders.domain.client.dto.request.OrderItemDto; | |
17 | -import com.b2c.orders.domain.client.dto.request.SubmitOrderRequestDto; | |
18 | -import com.b2c.orders.domain.client.dto.response.ApiResponse; | |
19 | -import com.b2c.orders.domain.client.service.OrderService; | |
20 | -import com.b2c.orders.enums.DeliveryType; | |
21 | - | |
22 | -public class OrderServiceTestCase { | |
23 | - | |
24 | - private static OrderService orderService; | |
25 | - | |
26 | - @BeforeClass | |
27 | - public static void setUpBeforeClass() throws Exception { | |
28 | - OrderClient client = new OrderClient("http://orders.zandeapp.com", ""); | |
29 | - orderService = client.getOrderService(); | |
30 | - } | |
31 | - | |
32 | - @Test | |
33 | - public void testSubmit() { | |
34 | - SubmitOrderRequestDto request = new SubmitOrderRequestDto(); | |
35 | - request.setBuyerMemo("不要放鸡精味精"); | |
36 | - request.setDeliveryType(DeliveryType.Self.getIndex()); | |
37 | - request.setMarketId(1L); | |
38 | - List<OrderItemDto> orderItems = new ArrayList<>(); | |
39 | - OrderItemDto orderItem = new OrderItemDto(); | |
40 | - orderItem.setAmount(2); | |
41 | - orderItem.setSku("1bKvCngjj0w"); | |
42 | - orderItems.add(orderItem); | |
43 | - request.setOrderItems(orderItems); | |
44 | - request.setReservationTime("2016-12-22 18:00:00"); | |
45 | - request.setShopBuyerId(1L); | |
46 | - ApiResponse response = orderService.submit(request); | |
47 | - Assert.assertTrue(response.isSuccess()); | |
48 | - } | |
49 | - | |
50 | -} |
b2c-orders-commons/src/main/java/com/b2c/orders/commons/constant/Constant.java
... | ... | @@ -2,36 +2,6 @@ package com.b2c.orders.commons.constant; |
2 | 2 | |
3 | 3 | public class Constant { |
4 | 4 | |
5 | - // /** | |
6 | - // * 商家未接单,订单超时api接口地址 | |
7 | - // */ | |
8 | - // public static final String ORDER_TAKEN_TIMEOUT_CALL_URL = | |
9 | - // "http://orders.zandeapp.com/api/takenTimeout"; | |
10 | - // /** | |
11 | - // * 买家未付款,订单超时api接口 | |
12 | - // */ | |
13 | - // public static final String ORDER_PAYMENT_TIMEOUT_CALL_URL = | |
14 | - // "http://orders.zandeapp.com/api/paymentTimeout"; | |
15 | - // /** | |
16 | - // * 商家未接单,订单超时时间 | |
17 | - // */ | |
18 | - // public static final int ORDER_TAKEN_TIMEOUT_SECONDS = 2 * 60 * 60; | |
19 | - // /** | |
20 | - // * 买家未支付,订单超时时间 | |
21 | - // */ | |
22 | - // public static final int ORDER_PAYMENT_TIMEOUT_SECONDS = 60; | |
23 | - // /** | |
24 | - // * 买家超过{@link ORDER_CONFIRM_TIMEOUT_SECONDS}秒没有确认收货或者卖家超过{@link | |
25 | - // ORDER_CONFIRM_TIMEOUT_SECONDS}没有确认收款,dtms调用接口地址自动确认收货、收款 | |
26 | - // */ | |
27 | - // public static final String ORDER_CONFIRM_TIMEOUT_CALL_URL = | |
28 | - // "http://orders.zandeapp.com/api/dtmsConfirm"; | |
29 | - // /** | |
30 | - // * 买家超过这个时间(单位:秒)没有确认收货或者卖家超过这个时间(单位:秒)没有确认收款,dtms调用{@link | |
31 | - // ORDER_CONFIRM_TIMEOUT_CALL_URL}订单接口确认收货、收款 | |
32 | - // */ | |
33 | - // public static final int ORDER_CONFIRM_TIMEOUT_SECONDS = 24 * 60 * 60; | |
34 | - | |
35 | 5 | private String domain; |
36 | 6 | private String orderTakenTimeoutCallUrlKey; |
37 | 7 | private String orderPaymentTimeoutCallUrlKey; |
... | ... |
b2c-orders-commons/src/main/java/com/b2c/orders/commons/constant/MqPushMessageCode.java
0 → 100644
1 | +package com.b2c.orders.commons.constant; | |
2 | + | |
3 | +public final class MqPushMessageCode { | |
4 | + | |
5 | + /** | |
6 | + * 商家接单推送 | |
7 | + */ | |
8 | + public static final int SELLER_TAKEN_PUSH_TO_BUYER = 1; | |
9 | + /** | |
10 | + * 商家修改价格推送 | |
11 | + */ | |
12 | + public static final int SELLER_MODIFIED_PRICE_PUSH_TO_BUYER = 2; | |
13 | + /** | |
14 | + * 订单完成推送给商家 | |
15 | + */ | |
16 | + public static final int ORDER_COMPLETED_PUSH_TO_BUYER = 3; | |
17 | + /** | |
18 | + * 商家拒绝接单推送给买家 | |
19 | + */ | |
20 | + public static final int SELLER_REFUSED_PUSH_TO_BUYER = 4; | |
21 | + /** | |
22 | + * 新订单推送给商家 | |
23 | + */ | |
24 | + public static final int NEW_ORDER_PUSH_TO_SELLER = 5; | |
25 | + /** | |
26 | + * 订单待送货推送推送给商家 | |
27 | + */ | |
28 | + public static final int PENDING_DELIVERY_PUSH_TO_SELLER = 6; | |
29 | + /** | |
30 | + * 买家取消订单推送给商家 | |
31 | + */ | |
32 | + public static final int ORDER_CANCELED_PUSH_TO_SELLER = 7; | |
33 | + /** | |
34 | + * 买家已付款推行给商家 | |
35 | + */ | |
36 | + public static final int BUYER_PAID_PUSH_TO_SELLER = 8; | |
37 | + /** | |
38 | + * 待接单推送给商家 | |
39 | + */ | |
40 | + public static final int PENDING_TAKEN_PUSH_TO_SELLER = 9; | |
41 | +} | |
... | ... |
b2c-orders-dao/src/main/resources/sqlmap-config.xml
... | ... | @@ -12,7 +12,7 @@ |
12 | 12 | <setting name="aggressiveLazyLoading" value="false" /> |
13 | 13 | <!-- 查询时,关闭关联对象即时加载以提高性能 --> |
14 | 14 | <setting name="lazyLoadingEnabled" value="true" /> |
15 | - <setting name="logImpl" value="STDOUT_LOGGING" /> | |
15 | + <!-- <setting name="logImpl" value="STDOUT_LOGGING" /> --> | |
16 | 16 | </settings> |
17 | 17 | |
18 | 18 | <!-- 全局别名设置,在映射文件中只需写别名,而不必写出整个类路径 --> |
... | ... |
b2c-orders-dao/src/main/resources/sqlmap/OrderMapper.xml
... | ... | @@ -38,6 +38,7 @@ |
38 | 38 | <result property="tradeName" column="trade_name" /> |
39 | 39 | <result property="cityId" column="city_id" /> |
40 | 40 | <result property="cityName" column="city_name" /> |
41 | + <result property="pickUpAddress" column="pick_up_address" /> | |
41 | 42 | <collection property="orderItems" column="id" |
42 | 43 | select="com.b2c.orders.dao.impl.OrderItemDaoBean.findByOrderId" /> |
43 | 44 | </resultMap> |
... | ... | @@ -58,6 +59,7 @@ |
58 | 59 | ,t1.pay_time |
59 | 60 | ,t1.delivery_time |
60 | 61 | ,t1.delivery_address |
62 | + ,t1.receiver_name | |
61 | 63 | ,t1.receiver_phone_number |
62 | 64 | ,t1.reservation_time |
63 | 65 | ,t1.buyer_confirm_time |
... | ... | @@ -76,6 +78,7 @@ |
76 | 78 | ,t1.trade_name |
77 | 79 | ,t1.city_id |
78 | 80 | ,t1.city_name |
81 | + ,t1.pick_up_address | |
79 | 82 | </sql> |
80 | 83 | |
81 | 84 | <sql id="selectCondition"> |
... | ... | @@ -219,7 +222,8 @@ |
219 | 222 | total_price, |
220 | 223 | trade_name, |
221 | 224 | city_id, |
222 | - city_name | |
225 | + city_name, | |
226 | + pick_up_address | |
223 | 227 | ) VALUES( |
224 | 228 | #{id}, |
225 | 229 | #{buyerId}, |
... | ... | @@ -246,7 +250,8 @@ |
246 | 250 | #{totalPrice}, |
247 | 251 | #{tradeName}, |
248 | 252 | #{cityId}, |
249 | - #{cityName} | |
253 | + #{cityName}, | |
254 | + #{pickUpAddress} | |
250 | 255 | ) |
251 | 256 | ]]> |
252 | 257 | </insert> |
... | ... |
b2c-orders-domain/pom.xml
... | ... | @@ -17,7 +17,7 @@ |
17 | 17 | <dependency> |
18 | 18 | <groupId>${project.groupId}</groupId> |
19 | 19 | <artifactId>b2c-orders-client</artifactId> |
20 | - <version>0.0.3-SNAPSHOT</version> | |
20 | + <version>0.0.4-SNAPSHOT</version> | |
21 | 21 | </dependency> |
22 | 22 | <dependency> |
23 | 23 | <groupId>org.projectlombok</groupId> |
... | ... |
b2c-orders-domain/src/main/java/com/b2c/orders/domain/Order.java
... | ... | @@ -4,6 +4,8 @@ |
4 | 4 | */ |
5 | 5 | package com.b2c.orders.domain; |
6 | 6 | |
7 | +import java.math.BigDecimal; | |
8 | +import java.math.RoundingMode; | |
7 | 9 | import java.util.Date; |
8 | 10 | import java.util.List; |
9 | 11 | |
... | ... | @@ -90,6 +92,7 @@ public class Order extends BaseDomain { |
90 | 92 | private String deliveryAddress; |
91 | 93 | /** 提货时间 */ |
92 | 94 | private Date reservationTime; |
95 | + private String pickUpAddress; | |
93 | 96 | /** 买家确认收货时间 */ |
94 | 97 | private Date buyerConfirmTime; |
95 | 98 | /** |
... | ... | @@ -101,7 +104,7 @@ public class Order extends BaseDomain { |
101 | 104 | /** 支付类型 */ |
102 | 105 | private PayType payType; |
103 | 106 | /** 预计总金额 */ |
104 | - private Long totalPrice; | |
107 | + private BigDecimal totalPrice; | |
105 | 108 | /** |
106 | 109 | * 实际价格,有商家接单后修改 |
107 | 110 | */ |
... | ... | @@ -145,4 +148,12 @@ public class Order extends BaseDomain { |
145 | 148 | return false; |
146 | 149 | } |
147 | 150 | |
151 | + @JsonIgnore | |
152 | + public Double getTotalPriceDoubleValue() { | |
153 | + if (this.totalPrice == null) { | |
154 | + return null; | |
155 | + } | |
156 | + return this.totalPrice.divide(new BigDecimal(100)).setScale(2, RoundingMode.HALF_UP).doubleValue(); | |
157 | + } | |
158 | + | |
148 | 159 | } |
149 | 160 | \ No newline at end of file |
... | ... |
b2c-orders-domain/src/main/java/com/b2c/orders/domain/OrderItem.java
... | ... | @@ -4,6 +4,7 @@ |
4 | 4 | */ |
5 | 5 | package com.b2c.orders.domain; |
6 | 6 | |
7 | +import java.math.BigDecimal; | |
7 | 8 | import java.sql.Timestamp; |
8 | 9 | |
9 | 10 | import lombok.Data; |
... | ... | @@ -36,7 +37,7 @@ public class OrderItem extends BaseDomain { |
36 | 37 | private String skuPicture; |
37 | 38 | private String priceUnit; |
38 | 39 | private Long skuPrice; |
39 | - private Integer amount; | |
40 | + private BigDecimal amount; | |
40 | 41 | private Timestamp createTime; |
41 | 42 | private Timestamp editTime; |
42 | 43 | private Long versionNum; |
... | ... |
b2c-orders-domain/src/main/java/com/b2c/orders/domain/vo/OrderItemVo.java
1 | 1 | package com.b2c.orders.domain.vo; |
2 | 2 | |
3 | +import java.math.BigDecimal; | |
4 | + | |
3 | 5 | import com.b2c.orders.domain.rpc.Product; |
4 | 6 | |
5 | 7 | public class OrderItemVo { |
6 | 8 | |
7 | - private Integer amount; | |
9 | + private BigDecimal amount; | |
8 | 10 | private Product product; |
9 | 11 | |
10 | - public Integer getAmount() { | |
12 | + public BigDecimal getAmount() { | |
11 | 13 | return amount; |
12 | 14 | } |
13 | 15 | |
14 | - public void setAmount(Integer amount) { | |
16 | + public void setAmount(BigDecimal amount) { | |
15 | 17 | this.amount = amount; |
16 | 18 | } |
17 | 19 | |
... | ... |
b2c-orders-manager/src/main/java/com/b2c/orders/manager/impl/OrderManagerBean.java
1 | 1 | package com.b2c.orders.manager.impl; |
2 | 2 | |
3 | +import java.math.BigDecimal; | |
3 | 4 | import java.text.DateFormat; |
4 | 5 | import java.text.ParseException; |
5 | 6 | import java.text.SimpleDateFormat; |
... | ... | @@ -17,6 +18,7 @@ import org.springframework.stereotype.Component; |
17 | 18 | import org.springframework.transaction.annotation.Propagation; |
18 | 19 | import org.springframework.transaction.annotation.Transactional; |
19 | 20 | |
21 | +import com.b2c.orders.commons.constant.MqPushMessageCode; | |
20 | 22 | import com.b2c.orders.commons.exceptions.ApplicationException; |
21 | 23 | import com.b2c.orders.commons.exceptions.BuyerException; |
22 | 24 | import com.b2c.orders.commons.exceptions.OrderException; |
... | ... | @@ -54,7 +56,6 @@ import com.b2c.orders.service.rpc.param.UnlockBalanceParam; |
54 | 56 | import com.diligrp.website.util.dao.BaseQuery; |
55 | 57 | import com.diligrp.website.util.web.PageTemplate; |
56 | 58 | |
57 | -@Transactional(propagation = Propagation.REQUIRED, rollbackFor = ApplicationException.class) | |
58 | 59 | @Component |
59 | 60 | public class OrderManagerBean implements OrderManager { |
60 | 61 | |
... | ... | @@ -111,11 +112,12 @@ public class OrderManagerBean implements OrderManager { |
111 | 112 | throw new OrderException(ApplicationException.DATA_EXCEPTION, "提货时间不能为空"); |
112 | 113 | } |
113 | 114 | po.setReservationTime(df.parse(orderVo.getReservationTime())); |
115 | + po.setPickUpAddress(shop.getShopAddress()); | |
114 | 116 | } else { |
115 | 117 | throw new OrderException(ApplicationException.DATA_EXCEPTION, "未知的配送类型"); |
116 | 118 | } |
117 | 119 | po.setOrderStatus(OrderStatus.PendingTake); |
118 | - long totalPrice = 0; | |
120 | + BigDecimal totalPrice = new BigDecimal(0L).setScale(1); | |
119 | 121 | List<OrderItem> orderItems = new ArrayList<>(orderVo.getOrderItems().size()); |
120 | 122 | int itemIdx = 1; |
121 | 123 | Set<String> productNameSet = new LinkedHashSet<>(); |
... | ... | @@ -138,7 +140,8 @@ public class OrderManagerBean implements OrderManager { |
138 | 140 | orderItem.setSkuTitle(product.getSkuTitle()); |
139 | 141 | orderItem.setPriceUnit(product.getPriceUnit()); |
140 | 142 | orderItems.add(orderItem); |
141 | - totalPrice += product.getSkuPrice() * orderItemVo.getAmount(); | |
143 | + totalPrice = totalPrice.add(orderItemVo.getAmount().multiply(new BigDecimal(product.getSkuPrice()))) | |
144 | + .setScale(1); | |
142 | 145 | } |
143 | 146 | for (String productName : productNameSet) { |
144 | 147 | sb.append(productName).append("+"); |
... | ... | @@ -161,7 +164,17 @@ public class OrderManagerBean implements OrderManager { |
161 | 164 | this.orderLogDao.save(log); |
162 | 165 | // 发送dtms消息 |
163 | 166 | this.dtmsRPC.sendOrderTakenTimeoutDtms(po.getId()); |
164 | - // this.notifyUser(po); | |
167 | + // 推送给商家 | |
168 | + OrderMQDto orderDto = new OrderMQDto(); | |
169 | + orderDto.setBuyerId(po.getBuyerId()); | |
170 | + orderDto.setCode(MqPushMessageCode.NEW_ORDER_PUSH_TO_SELLER); | |
171 | + orderDto.setUserRole(UserType.SELLER.getIndex()); | |
172 | + orderDto.setId(po.getId()); | |
173 | + orderDto.setOrderStatus(po.getOrderStatus().getIndex()); | |
174 | + orderDto.setSellerId(po.getSellerId()); | |
175 | + this.dtmsRPC.sendMQDtmsMessage(orderDto); | |
176 | + orderDto.setCode(MqPushMessageCode.PENDING_TAKEN_PUSH_TO_SELLER); | |
177 | + this.dtmsRPC.sendMQDtmsMessage(orderDto); | |
165 | 178 | return po.getId(); |
166 | 179 | } |
167 | 180 | |
... | ... | @@ -202,15 +215,16 @@ public class OrderManagerBean implements OrderManager { |
202 | 215 | this.orderLogDao.save(log); |
203 | 216 | // 发送dtms订单支付超时消息 |
204 | 217 | this.dtmsRPC.sendOrderPayTimeoutDtms(orderId); |
205 | - this.notifyUser(po); | |
206 | - } | |
207 | - | |
208 | - private void notifyUser(Order order) throws DtmsRPCException { | |
218 | + // 推送给买家 | |
209 | 219 | OrderMQDto orderDto = new OrderMQDto(); |
210 | - orderDto.setBuyerId(order.getBuyerId()); | |
211 | - orderDto.setId(order.getId()); | |
212 | - orderDto.setOrderStatus(order.getOrderStatus().getIndex()); | |
213 | - orderDto.setSellerId(order.getSellerId()); | |
220 | + orderDto.setBuyerId(po.getBuyerId()); | |
221 | + orderDto.setCode(MqPushMessageCode.SELLER_TAKEN_PUSH_TO_BUYER); | |
222 | + orderDto.setId(po.getId()); | |
223 | + orderDto.setOrderStatus(po.getOrderStatus().getIndex()); | |
224 | + orderDto.setSellerId(po.getSellerId()); | |
225 | + orderDto.setShopName(po.getShopName()); | |
226 | + this.dtmsRPC.sendMQDtmsMessage(orderDto); | |
227 | + orderDto.setCode(MqPushMessageCode.SELLER_MODIFIED_PRICE_PUSH_TO_BUYER); | |
214 | 228 | this.dtmsRPC.sendMQDtmsMessage(orderDto); |
215 | 229 | } |
216 | 230 | |
... | ... | @@ -259,7 +273,15 @@ public class OrderManagerBean implements OrderManager { |
259 | 273 | param.setTradePrice(po.getRealTotalPrice()); |
260 | 274 | this.shopBuyerRPC.lockBalance(param); |
261 | 275 | } |
262 | - this.notifyUser(po); | |
276 | + // 推送给商家 | |
277 | + OrderMQDto orderDto = new OrderMQDto(); | |
278 | + orderDto.setBuyerId(po.getBuyerId()); | |
279 | + orderDto.setCode(MqPushMessageCode.BUYER_PAID_PUSH_TO_SELLER); | |
280 | + orderDto.setUserRole(UserType.SELLER.getIndex()); | |
281 | + orderDto.setId(po.getId()); | |
282 | + orderDto.setOrderStatus(po.getOrderStatus().getIndex()); | |
283 | + orderDto.setSellerId(po.getSellerId()); | |
284 | + this.dtmsRPC.sendMQDtmsMessage(orderDto); | |
263 | 285 | } |
264 | 286 | |
265 | 287 | @Override |
... | ... | @@ -296,7 +318,16 @@ public class OrderManagerBean implements OrderManager { |
296 | 318 | param.setTradeName(po.getTradeName()); |
297 | 319 | param.setTradePrice(po.getRealTotalPrice()); |
298 | 320 | this.shopBuyerRPC.debit(param); |
299 | - this.notifyUser(po); | |
321 | + // 推送给买家 | |
322 | + OrderMQDto orderDto = new OrderMQDto(); | |
323 | + orderDto.setBuyerId(po.getBuyerId()); | |
324 | + orderDto.setCode(MqPushMessageCode.ORDER_COMPLETED_PUSH_TO_BUYER); | |
325 | + orderDto.setUserRole(UserType.BUYER.getIndex()); | |
326 | + orderDto.setId(po.getId()); | |
327 | + orderDto.setOrderStatus(po.getOrderStatus().getIndex()); | |
328 | + orderDto.setSellerId(po.getSellerId()); | |
329 | + orderDto.setShopName(po.getShopName()); | |
330 | + this.dtmsRPC.sendMQDtmsMessage(orderDto); | |
300 | 331 | } |
301 | 332 | |
302 | 333 | @Override |
... | ... | @@ -333,7 +364,14 @@ public class OrderManagerBean implements OrderManager { |
333 | 364 | param.setTradeName(po.getTradeName()); |
334 | 365 | param.setTradePrice(po.getRealTotalPrice()); |
335 | 366 | this.shopBuyerRPC.debit(param); |
336 | - this.notifyUser(po); | |
367 | + // 推送给买家 | |
368 | + OrderMQDto orderDto = new OrderMQDto(); | |
369 | + orderDto.setBuyerId(po.getBuyerId()); | |
370 | + orderDto.setCode(MqPushMessageCode.ORDER_COMPLETED_PUSH_TO_BUYER); | |
371 | + orderDto.setUserRole(UserType.BUYER.getIndex()); | |
372 | + orderDto.setId(po.getId()); | |
373 | + orderDto.setOrderStatus(po.getOrderStatus().getIndex()); | |
374 | + orderDto.setSellerId(po.getSellerId()); | |
337 | 375 | } |
338 | 376 | |
339 | 377 | @Override |
... | ... | @@ -364,7 +402,15 @@ public class OrderManagerBean implements OrderManager { |
364 | 402 | log.setUserId(sellerId); |
365 | 403 | log.setUserType(UserType.SELLER); |
366 | 404 | this.orderLogDao.save(log); |
367 | - this.notifyUser(po); | |
405 | + // 推送给买家 | |
406 | + OrderMQDto orderDto = new OrderMQDto(); | |
407 | + orderDto.setBuyerId(po.getBuyerId()); | |
408 | + orderDto.setCode(MqPushMessageCode.SELLER_REFUSED_PUSH_TO_BUYER); | |
409 | + orderDto.setUserRole(UserType.BUYER.getIndex()); | |
410 | + orderDto.setId(po.getId()); | |
411 | + orderDto.setOrderStatus(po.getOrderStatus().getIndex()); | |
412 | + orderDto.setShopName(po.getShopName()); | |
413 | + orderDto.setSellerId(po.getSellerId()); | |
368 | 414 | } |
369 | 415 | |
370 | 416 | @Override |
... | ... | @@ -399,7 +445,14 @@ public class OrderManagerBean implements OrderManager { |
399 | 445 | UnlockBalanceParam param = new UnlockBalanceParam(); |
400 | 446 | this.shopBuyerRPC.unlockBalance(param); |
401 | 447 | } |
402 | - this.notifyUser(po); | |
448 | + // 推送给商家 | |
449 | + OrderMQDto orderDto = new OrderMQDto(); | |
450 | + orderDto.setBuyerId(po.getBuyerId()); | |
451 | + orderDto.setCode(MqPushMessageCode.ORDER_CANCELED_PUSH_TO_SELLER); | |
452 | + orderDto.setUserRole(UserType.SELLER.getIndex()); | |
453 | + orderDto.setId(po.getId()); | |
454 | + orderDto.setOrderStatus(po.getOrderStatus().getIndex()); | |
455 | + orderDto.setSellerId(po.getSellerId()); | |
403 | 456 | } |
404 | 457 | |
405 | 458 | @Override |
... | ... | @@ -444,7 +497,6 @@ public class OrderManagerBean implements OrderManager { |
444 | 497 | log.setOrderId(orderId); |
445 | 498 | log.setUserType(UserType.SYSTEM); |
446 | 499 | this.orderLogDao.save(log); |
447 | - this.notifyUser(po); | |
448 | 500 | } |
449 | 501 | |
450 | 502 | @Override |
... | ... | @@ -469,7 +521,8 @@ public class OrderManagerBean implements OrderManager { |
469 | 521 | log.setUserType(UserType.SYSTEM); |
470 | 522 | this.orderLogDao.save(log); |
471 | 523 | if (po.getPayType().equals(PayType.Online)) { |
472 | - this.shopBuyerRPC.debit(null); | |
524 | + DebitParam param = new DebitParam(); | |
525 | + this.shopBuyerRPC.debit(param); | |
473 | 526 | } |
474 | 527 | } |
475 | 528 | |
... | ... | @@ -497,7 +550,6 @@ public class OrderManagerBean implements OrderManager { |
497 | 550 | } |
498 | 551 | } |
499 | 552 | |
500 | - @Transactional(propagation = Propagation.SUPPORTS) | |
501 | 553 | @Override |
502 | 554 | public PageTemplate list(BaseQuery query, UserType userType) { |
503 | 555 | if (UserType.BUYER.equals(userType)) { |
... | ... |
b2c-orders-rpc/src/main/java/com/b2c/orders/service/rpc/ProductRPCService.java deleted
100644 → 0
b2c-orders-rpc/src/main/java/com/b2c/orders/service/rpc/impl/ProductRPCServiceImpl.java deleted
100644 → 0
1 | -package com.b2c.orders.service.rpc.impl; | |
2 | - | |
3 | -import java.util.Arrays; | |
4 | -import java.util.HashMap; | |
5 | -import java.util.Map; | |
6 | -import java.util.Map.Entry; | |
7 | - | |
8 | -import org.apache.commons.collections.MapUtils; | |
9 | -import org.slf4j.Logger; | |
10 | -import org.slf4j.LoggerFactory; | |
11 | -import org.springframework.beans.factory.annotation.Autowired; | |
12 | -import org.springframework.stereotype.Service; | |
13 | - | |
14 | -import com.b2c.orders.commons.exceptions.ApplicationException; | |
15 | -import com.b2c.orders.commons.exceptions.ProductException; | |
16 | -import com.b2c.orders.commons.utils.CollectionUtils; | |
17 | -import com.b2c.orders.domain.rpc.Product; | |
18 | -import com.b2c.orders.service.rpc.ProductRPCService; | |
19 | -import com.diligrp.titan.sdk.TitanClient; | |
20 | -import com.diligrp.titan.sdk.output.BaseOutput; | |
21 | -import com.diligrp.titan.sdk.service.ProductService; | |
22 | - | |
23 | -@Service | |
24 | -public class ProductRPCServiceImpl implements ProductRPCService { | |
25 | - | |
26 | - private static final Logger LOG = LoggerFactory.getLogger(ProductRPCServiceImpl.class); | |
27 | - private static final Map<Integer, String> SKU_UNIT_MAP = new HashMap<>(); | |
28 | - | |
29 | - @Autowired | |
30 | - private TitanClient titanClient; | |
31 | - | |
32 | - static { | |
33 | - SKU_UNIT_MAP.put(1483, "份"); | |
34 | - SKU_UNIT_MAP.put(1484, "个"); | |
35 | - SKU_UNIT_MAP.put(1485, "斤"); | |
36 | - } | |
37 | - | |
38 | - @Override | |
39 | - public Product findById(Long id) { | |
40 | - // TODO Auto-generated method stub | |
41 | - return null; | |
42 | - } | |
43 | - | |
44 | - @Override | |
45 | - public Product findBySku(String sku) throws ProductException { | |
46 | - ProductService productRPCService = this.titanClient.getProductService(); | |
47 | - BaseOutput<Map<String, com.diligrp.titan.sdk.domain.Product>> rpcResponse = productRPCService | |
48 | - .getSkuInfoMap(Arrays.asList(sku)); | |
49 | - if (rpcResponse.getCode() != 200) { | |
50 | - LOG.error(rpcResponse.getResult()); | |
51 | - throw new ProductException(ApplicationException.DATA_EXCEPTION, "根据sku查询商品信息失败"); | |
52 | - } | |
53 | - Map<String, com.diligrp.titan.sdk.domain.Product> skuMap = rpcResponse.getData(); | |
54 | - if (MapUtils.isEmpty(skuMap)) { | |
55 | - return null; | |
56 | - } | |
57 | - com.diligrp.titan.sdk.domain.Product rpcProduct = skuMap.get(sku); | |
58 | - Product product = new Product(); | |
59 | - product.setId(rpcProduct.getPid()); | |
60 | - product.setName(rpcProduct.getName()); | |
61 | - product.setSku(sku); | |
62 | - if (CollectionUtils.isEmpty(rpcProduct.getSkus())) { | |
63 | - throw new ProductException(ApplicationException.DATA_EXCEPTION, "商品sku信息为空"); | |
64 | - } | |
65 | - com.diligrp.titan.sdk.domain.Sku targetSku = null; | |
66 | - for (com.diligrp.titan.sdk.domain.Sku skuInfo : rpcProduct.getSkus()) { | |
67 | - if (skuInfo.getSku().equals(sku)) { | |
68 | - targetSku = skuInfo; | |
69 | - } | |
70 | - } | |
71 | - if (targetSku == null) { | |
72 | - throw new ProductException(ApplicationException.DATA_EXCEPTION, "商品sku信息不存在"); | |
73 | - } | |
74 | - product.setSkuPrice((long) targetSku.getPrice()); | |
75 | - if (!SKU_UNIT_MAP.containsKey(targetSku.getStoreUnit())) { | |
76 | - throw new ProductException(ApplicationException.DATA_EXCEPTION, "商品单位不存在"); | |
77 | - } | |
78 | - product.setPriceUnit(SKU_UNIT_MAP.get(targetSku.getStoreUnit())); | |
79 | - if (targetSku.getAttributesMap() != null) { | |
80 | - StringBuffer buf = new StringBuffer(); | |
81 | - for (Entry<String, String> entry : targetSku.getAttributesMap().entrySet()) { | |
82 | - buf.append(entry.getKey()).append(":").append(entry.getValue()).append(";"); | |
83 | - } | |
84 | - product.setSkuAttributes(buf.toString()); | |
85 | - } | |
86 | - product.setSkuPicture(rpcProduct.getDefaultPic()); | |
87 | - product.setSkuTitle(rpcProduct.getName()); | |
88 | - return product; | |
89 | - } | |
90 | - | |
91 | -} |
b2c-orders-rpc/src/main/java/com/b2c/orders/service/rpc/param/OrderMQDto.java
... | ... | @@ -15,6 +15,9 @@ public class OrderMQDto implements Serializable { |
15 | 15 | private Long buyerId; |
16 | 16 | private Long sellerId; |
17 | 17 | private Integer orderStatus; |
18 | + private Integer code; | |
19 | + private Integer userRole; | |
20 | + private String shopName; | |
18 | 21 | |
19 | 22 | public String getTopic() { |
20 | 23 | return topic; |
... | ... | @@ -64,4 +67,28 @@ public class OrderMQDto implements Serializable { |
64 | 67 | this.orderStatus = orderStatus; |
65 | 68 | } |
66 | 69 | |
70 | + public Integer getCode() { | |
71 | + return code; | |
72 | + } | |
73 | + | |
74 | + public void setCode(Integer code) { | |
75 | + this.code = code; | |
76 | + } | |
77 | + | |
78 | + public Integer getUserRole() { | |
79 | + return userRole; | |
80 | + } | |
81 | + | |
82 | + public void setUserRole(Integer userRole) { | |
83 | + this.userRole = userRole; | |
84 | + } | |
85 | + | |
86 | + public String getShopName() { | |
87 | + return shopName; | |
88 | + } | |
89 | + | |
90 | + public void setShopName(String shopName) { | |
91 | + this.shopName = shopName; | |
92 | + } | |
93 | + | |
67 | 94 | } |
... | ... |
b2c-orders-web/src/main/java/com/b2c/orders/web/controller/OrderController.java
... | ... | @@ -38,7 +38,7 @@ public class OrderController extends VelocitySupport { |
38 | 38 | @RequestMapping(value = "/list", method = RequestMethod.GET) |
39 | 39 | public ModelAndView list(BaseQuery query) { |
40 | 40 | PageTemplate pt = this.orderService.list(query, UserType.SYSTEM); |
41 | - return this.toVM("list", pt).addObject("queryParam", query).addObject("orderStatusMap", | |
41 | + return this.toVM("list", pt).addObject("query", query).addObject("orderStatusMap", | |
42 | 42 | OrderStatus.getInitMaps()).addObject("payTypes", PayType.values()); |
43 | 43 | } |
44 | 44 | |
... | ... |
b2c-orders-web/src/main/java/com/b2c/orders/web/restful/OrderRestController.java
... | ... | @@ -3,12 +3,18 @@ package com.b2c.orders.web.restful; |
3 | 3 | import java.text.DateFormat; |
4 | 4 | import java.text.SimpleDateFormat; |
5 | 5 | import java.util.ArrayList; |
6 | -import java.util.LinkedHashSet; | |
6 | +import java.util.HashMap; | |
7 | +import java.util.HashSet; | |
7 | 8 | import java.util.List; |
9 | +import java.util.Map; | |
10 | +import java.util.Map.Entry; | |
8 | 11 | import java.util.Set; |
9 | 12 | |
10 | 13 | import javax.validation.Valid; |
11 | 14 | |
15 | +import org.apache.commons.collections.MapUtils; | |
16 | +import org.slf4j.Logger; | |
17 | +import org.slf4j.LoggerFactory; | |
12 | 18 | import org.springframework.beans.factory.annotation.Autowired; |
13 | 19 | import org.springframework.cglib.beans.BeanCopier; |
14 | 20 | import org.springframework.http.MediaType; |
... | ... | @@ -24,6 +30,8 @@ import com.b2c.dtms.client.domain.dto.DtmsCallbackMessage; |
24 | 30 | import com.b2c.dtms.common.enums.dtms.HandleCode; |
25 | 31 | import com.b2c.dtms.domain.DtmsCallBackReturn; |
26 | 32 | import com.b2c.orders.commons.exceptions.ApplicationException; |
33 | +import com.b2c.orders.commons.exceptions.OrderException; | |
34 | +import com.b2c.orders.commons.exceptions.ProductException; | |
27 | 35 | import com.b2c.orders.dao.utils.Query; |
28 | 36 | import com.b2c.orders.domain.Order; |
29 | 37 | import com.b2c.orders.domain.OrderItem; |
... | ... | @@ -54,8 +62,10 @@ import com.b2c.orders.domain.vo.OrderVo; |
54 | 62 | import com.b2c.orders.enums.PayType; |
55 | 63 | import com.b2c.orders.enums.UserType; |
56 | 64 | import com.b2c.orders.service.OrderService; |
57 | -import com.b2c.orders.service.rpc.ProductRPCService; | |
58 | 65 | import com.b2c.orders.service.rpc.ShopBuyerRPCService; |
66 | +import com.diligrp.titan.sdk.TitanClient; | |
67 | +import com.diligrp.titan.sdk.output.BaseOutput; | |
68 | +import com.diligrp.titan.sdk.service.ProductService; | |
59 | 69 | import com.diligrp.website.util.dao.BaseQuery; |
60 | 70 | import com.diligrp.website.util.web.PageTemplate; |
61 | 71 | |
... | ... | @@ -64,22 +74,36 @@ import io.swagger.annotations.ApiOperation; |
64 | 74 | |
65 | 75 | @Api("订单api") |
66 | 76 | @RestController |
67 | -@RequestMapping("/api") | |
77 | +@RequestMapping(value = "/api", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) | |
68 | 78 | public class OrderRestController { |
69 | 79 | |
80 | + private static final Logger LOG = LoggerFactory.getLogger(OrderRestController.class); | |
81 | + | |
70 | 82 | private BeanCopier orderItemCopier = BeanCopier.create(OrderItem.class, OrderItemResponseDto.class, false); |
71 | 83 | @Autowired |
72 | 84 | private OrderService orderService; |
73 | 85 | @Autowired |
74 | 86 | private ShopBuyerRPCService shopBuyerRPC; |
75 | 87 | @Autowired |
76 | - private ProductRPCService productRPC; | |
88 | + private TitanClient titanClient; | |
89 | + | |
90 | + public static final Map<Integer, String> SKU_UNIT_MAP = new HashMap<>(); | |
91 | + | |
92 | + static { | |
93 | + SKU_UNIT_MAP.put(1483, "份"); | |
94 | + SKU_UNIT_MAP.put(1484, "个"); | |
95 | + SKU_UNIT_MAP.put(1485, "斤"); | |
96 | + } | |
77 | 97 | |
78 | 98 | @ApiOperation("提交订单") |
79 | 99 | @RequestMapping(value = "/submit", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) |
80 | 100 | public ApiDataResponse<SubmitOrderResponseDto> submit(@RequestBody @Valid SubmitOrderRequestDto order, |
81 | 101 | BindingResult br) { |
82 | 102 | ApiDataResponse<SubmitOrderResponseDto> dto = new ApiDataResponse<>(); |
103 | + if (br.hasErrors()) { | |
104 | + dto.setMessage(br.getFieldError().getDefaultMessage()); | |
105 | + return dto; | |
106 | + } | |
83 | 107 | try { |
84 | 108 | OrderVo vo = new OrderVo(); |
85 | 109 | Buyer buyer = this.shopBuyerRPC.findBuyerByBuyerShopId(order.getShopBuyerId()); |
... | ... | @@ -99,14 +123,7 @@ public class OrderRestController { |
99 | 123 | vo.setReceiverPhoneNumber(order.getReceiverPhoneNumber()); |
100 | 124 | vo.setReservationTime(order.getReservationTime()); |
101 | 125 | vo.setShopBuyerId(order.getShopBuyerId()); |
102 | - List<OrderItemVo> orderItems = new ArrayList<>(order.getOrderItems().size()); | |
103 | - for (OrderItemDto orderItemDto : order.getOrderItems()) { | |
104 | - OrderItemVo orderItemVo = new OrderItemVo(); | |
105 | - orderItemVo.setAmount(orderItemDto.getAmount()); | |
106 | - Product product = this.productRPC.findBySku(orderItemDto.getSku()); | |
107 | - orderItemVo.setProduct(product); | |
108 | - orderItems.add(orderItemVo); | |
109 | - } | |
126 | + List<OrderItemVo> orderItems = this.buildOrderItems(order.getOrderItems()); | |
110 | 127 | vo.setOrderItems(orderItems); |
111 | 128 | Long orderId = this.orderService.submit(vo); |
112 | 129 | SubmitOrderResponseDto data = new SubmitOrderResponseDto(); |
... | ... | @@ -120,10 +137,84 @@ public class OrderRestController { |
120 | 137 | return dto; |
121 | 138 | } |
122 | 139 | |
140 | + private List<OrderItemVo> buildOrderItems(List<OrderItemDto> orderItemDtoList) | |
141 | + throws OrderException, ProductException { | |
142 | + ProductService productRPCService = this.titanClient.getProductService(); | |
143 | + Set<String> skus = new HashSet<>(); | |
144 | + for (OrderItemDto dto : orderItemDtoList) { | |
145 | + if (skus.contains(dto.getSku())) { | |
146 | + throw new OrderException(ApplicationException.DATA_EXCEPTION, "存在相同的sku"); | |
147 | + } | |
148 | + skus.add(dto.getSku()); | |
149 | + } | |
150 | + BaseOutput<Map<String, com.diligrp.titan.sdk.domain.Product>> rpcResponse = productRPCService | |
151 | + .getSkuInfoMap(new ArrayList<>(skus)); | |
152 | + if (rpcResponse.getCode() != 200) { | |
153 | + LOG.error(rpcResponse.getResult()); | |
154 | + throw new ProductException(ApplicationException.DATA_EXCEPTION, "根据sku查询商品信息失败"); | |
155 | + } | |
156 | + Map<String, com.diligrp.titan.sdk.domain.Product> skuMap = rpcResponse.getData(); | |
157 | + if (MapUtils.isEmpty(skuMap)) { | |
158 | + throw new ProductException(ApplicationException.DATA_EXCEPTION, "根据sku查询商品信息为空"); | |
159 | + } | |
160 | + if (skuMap.size() != skus.size()) { | |
161 | + throw new ProductException(ApplicationException.DATA_EXCEPTION, "查询sku信息不一致"); | |
162 | + } | |
163 | + List<OrderItemVo> orderItemVoLIst = new ArrayList<>(); | |
164 | + for (OrderItemDto dto : orderItemDtoList) { | |
165 | + com.diligrp.titan.sdk.domain.Product rpcProduct = skuMap.get(dto.getSku()); | |
166 | + Product product = new Product(); | |
167 | + product.setId(rpcProduct.getPid()); | |
168 | + product.setName(rpcProduct.getName()); | |
169 | + product.setSku(dto.getSku()); | |
170 | + if (CollectionUtils.isEmpty(rpcProduct.getSkus())) { | |
171 | + throw new ProductException(ApplicationException.DATA_EXCEPTION, "商品sku信息为空"); | |
172 | + } | |
173 | + // 获取sku信息 | |
174 | + com.diligrp.titan.sdk.domain.Sku targetSku = null; | |
175 | + for (com.diligrp.titan.sdk.domain.Sku skuInfo : rpcProduct.getSkus()) { | |
176 | + if (skuInfo.getSku().equals(dto.getSku())) { | |
177 | + targetSku = skuInfo; | |
178 | + } | |
179 | + } | |
180 | + if (targetSku == null) { | |
181 | + throw new ProductException(ApplicationException.DATA_EXCEPTION, "商品sku信息不存在"); | |
182 | + } | |
183 | + // 校验sku中的价格和提交的价格是否一致 | |
184 | + long price = targetSku.getPrice(); | |
185 | + if (!dto.getSkuPrice().equals(price)) { | |
186 | + throw new ProductException(ApplicationException.DATA_EXCEPTION, "商品价格不一致"); | |
187 | + } | |
188 | + product.setSkuPrice(price); | |
189 | + if (!SKU_UNIT_MAP.containsKey(targetSku.getStoreUnit())) { | |
190 | + throw new ProductException(ApplicationException.DATA_EXCEPTION, "商品单位不存在"); | |
191 | + } | |
192 | + product.setPriceUnit(SKU_UNIT_MAP.get(targetSku.getStoreUnit())); | |
193 | + if (targetSku.getAttributesMap() != null) { | |
194 | + StringBuffer buf = new StringBuffer(); | |
195 | + for (Entry<String, String> entry : targetSku.getAttributesMap().entrySet()) { | |
196 | + buf.append(entry.getKey()).append(":").append(entry.getValue()).append(";"); | |
197 | + } | |
198 | + product.setSkuAttributes(buf.toString()); | |
199 | + } | |
200 | + product.setSkuPicture(rpcProduct.getDefaultPic()); | |
201 | + product.setSkuTitle(rpcProduct.getName()); | |
202 | + OrderItemVo vo = new OrderItemVo(); | |
203 | + vo.setAmount(dto.getAmount()); | |
204 | + vo.setProduct(product); | |
205 | + orderItemVoLIst.add(vo); | |
206 | + } | |
207 | + return orderItemVoLIst; | |
208 | + } | |
209 | + | |
123 | 210 | @ApiOperation("商家接单") |
124 | 211 | @RequestMapping(value = "/take", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) |
125 | 212 | public ApiResponse take(@RequestBody @Valid TakeOrderRequestDto request, BindingResult br) { |
126 | 213 | ApiResponse dto = new ApiResponse(); |
214 | + if (br.hasErrors()) { | |
215 | + dto.setMessage(br.getFieldError().getDefaultMessage()); | |
216 | + return dto; | |
217 | + } | |
127 | 218 | try { |
128 | 219 | this.orderService.take(request.getOrderId(), request.getSellerId(), request.getTotalPrice()); |
129 | 220 | dto.setCode(ApiResponse.RESPONSE_CODE_SUCCESS); |
... | ... | @@ -138,6 +229,10 @@ public class OrderRestController { |
138 | 229 | @RequestMapping(value = "/pay", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) |
139 | 230 | public ApiResponse pay(@RequestBody @Valid PayOrderRequestDto request, BindingResult br) { |
140 | 231 | ApiResponse dto = new ApiResponse(); |
232 | + if (br.hasErrors()) { | |
233 | + dto.setMessage(br.getFieldError().getDefaultMessage()); | |
234 | + return dto; | |
235 | + } | |
141 | 236 | try { |
142 | 237 | this.orderService.pay(request.getOrderId(), request.getShopBuyerId(), |
143 | 238 | PayType.getPayType(request.getPayType())); |
... | ... | @@ -153,6 +248,10 @@ public class OrderRestController { |
153 | 248 | @RequestMapping(value = "/buyerConfirm", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) |
154 | 249 | public ApiResponse buyerConfirm(@RequestBody @Valid BuyerConfirmRequestDto request, BindingResult br) { |
155 | 250 | ApiResponse response = new ApiResponse(); |
251 | + if (br.hasErrors()) { | |
252 | + response.setMessage(br.getFieldError().getDefaultMessage()); | |
253 | + return response; | |
254 | + } | |
156 | 255 | try { |
157 | 256 | this.orderService.buyerConfirm(request.getOrderId(), request.getShopBuyerId()); |
158 | 257 | response.setCode(ApiResponse.RESPONSE_CODE_SUCCESS); |
... | ... | @@ -167,6 +266,10 @@ public class OrderRestController { |
167 | 266 | @RequestMapping(value = "/sellerConfirm", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) |
168 | 267 | public ApiResponse sellerConfirm(@RequestBody @Valid SellerConfirmRequestDto request, BindingResult br) { |
169 | 268 | ApiResponse response = new ApiResponse(); |
269 | + if (br.hasErrors()) { | |
270 | + response.setMessage(br.getFieldError().getDefaultMessage()); | |
271 | + return response; | |
272 | + } | |
170 | 273 | try { |
171 | 274 | this.orderService.sellerConfirm(request.getOrderId(), request.getSellerId()); |
172 | 275 | response.setCode(ApiResponse.RESPONSE_CODE_SUCCESS); |
... | ... | @@ -178,7 +281,7 @@ public class OrderRestController { |
178 | 281 | } |
179 | 282 | |
180 | 283 | @RequestMapping(value = "/dtmsConfirm", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) |
181 | - public DtmsCallBackReturn dtmsConfirm(@RequestBody DtmsCallbackMessage request, BindingResult br) { | |
284 | + public DtmsCallBackReturn dtmsConfirm(@RequestBody DtmsCallbackMessage request) { | |
182 | 285 | DtmsCallBackReturn response = new DtmsCallBackReturn(); |
183 | 286 | try { |
184 | 287 | this.orderService.dtmsConfirm(Long.valueOf(request.getBizId())); |
... | ... | @@ -194,6 +297,10 @@ public class OrderRestController { |
194 | 297 | @RequestMapping(value = "/refuse", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) |
195 | 298 | public ApiResponse sellerRefuse(@RequestBody @Valid SellerRefuseRequestDto request, BindingResult br) { |
196 | 299 | ApiResponse response = new ApiResponse(); |
300 | + if (br.hasErrors()) { | |
301 | + response.setMessage(br.getFieldError().getDefaultMessage()); | |
302 | + return response; | |
303 | + } | |
197 | 304 | try { |
198 | 305 | this.orderService.refuse(request.getOrderId(), request.getSellerId(), request.getRefuseReason()); |
199 | 306 | response.setCode(ApiResponse.RESPONSE_CODE_SUCCESS); |
... | ... | @@ -208,6 +315,10 @@ public class OrderRestController { |
208 | 315 | @RequestMapping(value = "/cancel", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) |
209 | 316 | public ApiResponse buyerCancel(@RequestBody @Valid BuyerCancelRequestDto request, BindingResult br) { |
210 | 317 | ApiResponse response = new ApiResponse(); |
318 | + if (br.hasErrors()) { | |
319 | + response.setMessage(br.getFieldError().getDefaultMessage()); | |
320 | + return response; | |
321 | + } | |
211 | 322 | try { |
212 | 323 | this.orderService.cancel(request.getOrderId(), request.getShopBuyerId()); |
213 | 324 | response.setCode(ApiResponse.RESPONSE_CODE_SUCCESS); |
... | ... | @@ -219,7 +330,7 @@ public class OrderRestController { |
219 | 330 | } |
220 | 331 | |
221 | 332 | @RequestMapping(value = "/takenTimeout", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) |
222 | - public DtmsCallBackReturn takenTimeout(@RequestBody DtmsCallbackMessage request, BindingResult br) { | |
333 | + public DtmsCallBackReturn takenTimeout(@RequestBody DtmsCallbackMessage request) { | |
223 | 334 | DtmsCallBackReturn response = new DtmsCallBackReturn(); |
224 | 335 | try { |
225 | 336 | this.orderService.takenTimeout(Long.valueOf(request.getBizId())); |
... | ... | @@ -246,20 +357,33 @@ public class OrderRestController { |
246 | 357 | |
247 | 358 | @ApiOperation("订单详情") |
248 | 359 | @RequestMapping(value = "/detail", method = RequestMethod.GET) |
249 | - public ApiDataResponse<OrderDetailResponseDto> detail(OrderDetailRequestDto request) { | |
360 | + public ApiDataResponse<OrderDetailResponseDto> detail(@Valid OrderDetailRequestDto request, BindingResult br) { | |
250 | 361 | ApiDataResponse<OrderDetailResponseDto> response = new ApiDataResponse<>(); |
362 | + if (br.hasErrors()) { | |
363 | + response.setMessage(br.getFieldError().getDefaultMessage()); | |
364 | + return response; | |
365 | + } | |
251 | 366 | Order po = this.orderService.detail(request.getOrderId()); |
252 | 367 | OrderDetailResponseDto dto = new OrderDetailResponseDto(); |
253 | 368 | dto.setBuyerMemo(po.getBuyerMemo()); |
254 | 369 | dto.setDeliveryAddress(po.getDeliveryAddress()); |
255 | 370 | DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
256 | - dto.setDeliveryTime(df.format(po.getDeliveryTime())); | |
371 | + if (po.getDeliveryTime() != null) { | |
372 | + dto.setDeliveryTime(df.format(po.getDeliveryTime())); | |
373 | + } | |
257 | 374 | dto.setDeliveryType(po.getDeliveryType().getIndex()); |
258 | 375 | dto.setOrderStatus(po.getOrderStatus().getIndex()); |
259 | - dto.setPayStatus(po.getPayStatus().getIndex()); | |
260 | - dto.setPayType(po.getPayType().getIndex()); | |
376 | + if (po.getPayStatus() != null) { | |
377 | + dto.setPayStatus(po.getPayStatus().getIndex()); | |
378 | + } | |
379 | + if (po.getPayType() != null) { | |
380 | + dto.setPayType(po.getPayType().getIndex()); | |
381 | + } | |
261 | 382 | dto.setRealTotalPrice(po.getRealTotalPrice()); |
262 | - dto.setReservationTime(df.format(po.getReservationTime())); | |
383 | + if (po.getReservationTime() != null) { | |
384 | + dto.setReservationTime(df.format(po.getReservationTime())); | |
385 | + } | |
386 | + dto.setPickUpAddress(po.getPickUpAddress()); | |
263 | 387 | dto.setSubmitTime(df.format(po.getSubmitTime())); |
264 | 388 | dto.setTotalPrice(po.getTotalPrice()); |
265 | 389 | response.setData(dto); |
... | ... |
b2c-orders-web/src/main/resources/log4j.xml
b2c-orders-web/src/main/resources/logback.xml
... | ... | @@ -71,7 +71,7 @@ |
71 | 71 | <logger name="java.sql.Statement" level="DEBUG" /> |
72 | 72 | <logger name="java.sql.PreparedStatement" level="DEBUG" /> |
73 | 73 | |
74 | - <root level="DEBUG"> | |
74 | + <root level="INFO"> | |
75 | 75 | <!-- <appender-ref ref="ORDERS-WEB" /> --> |
76 | 76 | <appender-ref ref="STDOUT" /> |
77 | 77 | <appender-ref ref="org.apache.ibatis" /> |
... | ... |
b2c-orders-web/src/main/webapp/WEB-INF/vm/list.vm
... | ... | @@ -8,19 +8,25 @@ |
8 | 8 | <table class="table-condensed table-width"> |
9 | 9 | <tr> |
10 | 10 | <td class="col-md-1">订单编号</td> |
11 | - <td class="col-md-2"><input type="text" id="orderId" name="param[id]" placeholder="最大允许输入19位数字" value="$!{queryParam.param.id}"></td> | |
11 | + <td class="col-md-2"><input type="text" id="orderId" name="param[id]" placeholder="最大允许输入19位数字" value="$!{query.param.id}"></td> | |
12 | 12 | <td class="col-md-1">买家手机号</td> |
13 | - <td class="col-md-2"><input type="text" id="buyerPhoneNumber" name="param[buyerPhoneNumber]" placeholder="请输入11位手机号码" value="$!{queryParam.param.buyerPhoneNumber}"></td> | |
13 | + <td class="col-md-2"><input type="text" id="buyerPhoneNumber" name="param[buyerPhoneNumber]" placeholder="请输入11位手机号码" value="$!{query.param.buyerPhoneNumber}"></td> | |
14 | + <td>下单日期</td> | |
15 | + <td colspan='5'> | |
16 | + <input name="param[submitBeginTime]" id="submitBeginTime" readonly value="$!{query.param.submitBeginTime}" onClick="WdatePicker({dateFmt:'yyyy-M-d HH:mm:ss',startDate:'%y-%M-%d 00:00:00'})" type="text" placeholder="开始时间"/> | |
17 | + - | |
18 | + <input name="param[submitEndTime]" id="submitEndTime" readonly value="$!{query.param.submitEndTime}" onClick="WdatePicker({dateFmt:'yyyy-M-d HH:mm:ss',startDate:'%y-%M-%d 23:59:59'})" type="text" placeholder="结束时间"/> | |
19 | + </td> | |
14 | 20 | </tr> |
15 | 21 | <tr> |
16 | 22 | <td class="col-md-1">卖家手机号</td> |
17 | - <td class="col-md-2"><input type="text" id="sellerPhoneNumber" name="param[sellerPhoneNumber]" placeholder="请输入11位手机号码" value="$!{queryParam.param.sellerPhoneNumber}"></td> | |
23 | + <td class="col-md-2"><input type="text" id="sellerPhoneNumber" name="param[sellerPhoneNumber]" placeholder="请输入11位手机号码" value="$!{query.param.sellerPhoneNumber}"></td> | |
18 | 24 | <td class="col-md-1">订单状态</td> |
19 | 25 | <td class="col-md-2"> |
20 | 26 | <select name="param[orderStatus]"> |
21 | 27 | <option value="">全部</option> |
22 | 28 | #foreach(${item} in ${orderStatusMap.entrySet()}) |
23 | - #if($!{queryParam.orderStatus}==$!{item.key}) | |
29 | + #if($!{query.param.orderStatus}==$!{item.key}) | |
24 | 30 | <option value="$!{item.key}" selected = "selected">$!{item.value.name}</option> |
25 | 31 | #else |
26 | 32 | <option value="$!{item.key}">$!{item.value.name}</option> |
... | ... | @@ -33,7 +39,7 @@ |
33 | 39 | <select name="param[payType]" id="payType"> |
34 | 40 | <option value="">全部</option> |
35 | 41 | #foreach(${item} in ${payTypes}) |
36 | - #if($!{queryParam.payType}==$!{item.index}) | |
42 | + #if($!{query.param.payType}==$!{item.index}) | |
37 | 43 | <option value="$!{item.index}" selected = "selected">$!{item.name}</option> |
38 | 44 | #else |
39 | 45 | <option value="$!{item.index}">$!{item.name}</option> |
... | ... | @@ -43,47 +49,10 @@ |
43 | 49 | </td> |
44 | 50 | <td class="align-right col-md-3"> |
45 | 51 | <button type="button" id="queryBtn" class="btn btn-primary btn-sm"><i class="glyphicon glyphicon-search"></i>查询</button> |
46 | - <a class="btn btn-default btn-sm" data-toggle="collapse" href="#collapseThree"> | |
47 | - <i class="glyphicon glyphicon-filter"></i>高级过滤 | |
48 | - </a> | |
49 | 52 | <button type="button" class="btn btn-default btn-sm" onClick="XUI.form.reset()"><i class="glyphicon glyphicon-repeat"></i>重置</button> |
50 | 53 | </td> |
51 | 54 | </tr> |
52 | 55 | </table> |
53 | - <div id="collapseThree" class="accordion-body collapse"> | |
54 | - <div class="accordion-inner"> | |
55 | - <table class="table-condensed table-width"> | |
56 | - <tr> | |
57 | - <td class="col-md-1"> | |
58 | - 买家帐号 | |
59 | - </td> | |
60 | - <td class="col-md-2"> | |
61 | - <input type="text" name="buyerName" value="$!{queryParam.buyerName}" > | |
62 | - </td> | |
63 | - <td class="col-md-1"> | |
64 | - 卖家帐号 | |
65 | - </td> | |
66 | - <td class="col-md-2"> | |
67 | - <input type="text" name="sellerName" value="$!{queryParam.sellerName}"> | |
68 | - </td> | |
69 | - <td class="col-md-1"> | |
70 | - 店铺名称 | |
71 | - </td> | |
72 | - <td class="col-md-5"> | |
73 | - <input type="text" name="shopName" value="$!{queryParam.shopName}"> | |
74 | - </td> | |
75 | - </tr> | |
76 | - <tr> | |
77 | - <td>下单日期</td> | |
78 | - <td colspan='5'> | |
79 | - <input name="param[submitBeginTime]" id="submitBeginTime" readonly value="$!{queryParam.submitBeginTime}" onClick="WdatePicker({dateFmt:'yyyy-M-d HH:mm:ss',startDate:'%y-%M-%d 00:00:00'})" type="text" placeholder="开始时间"/> | |
80 | - - | |
81 | - <input name="param[submitBeginTime]" id="submitEndTime" readonly value="$!{queryParam.submitEndTime}" onClick="WdatePicker({dateFmt:'yyyy-M-d HH:mm:ss',startDate:'%y-%M-%d 23:59:59'})" type="text" placeholder="结束时间"/> | |
82 | - </td> | |
83 | - </tr> | |
84 | - </table> | |
85 | - </div> | |
86 | - </div> | |
87 | 56 | </form> |
88 | 57 | <!-- 表格数据 --> |
89 | 58 | <table class="table table-striped table-bordered table-condensed grid table-hover"> |
... | ... |
b2c-orders-web/src/main/webapp/WEB-INF/vm/tabbasic.vm
... | ... | @@ -117,9 +117,7 @@ |
117 | 117 | #if($!{velocityCount} == 1) |
118 | 118 | <td class="textC" rowspan="$!{model.orderItems.size()}"> |
119 | 119 | <span style="color:red"> |
120 | - #if($!{model.totalPrice}!=0) | |
121 | - $currencyTool.cent2TenNoSymbol($!{model.totalPrice})元 | |
122 | - #end | |
120 | + $!{model.totalPriceDoubleValue} | |
123 | 121 | </span> |
124 | 122 | </td> |
125 | 123 | <td class="textC" rowspan="$!{model.orderItems.size()}"> |
... | ... |
b2c-orders-web/src/test/java/TestCase.java deleted
100644 → 0
1 | -import static org.junit.Assert.*; | |
2 | - | |
3 | -import java.text.SimpleDateFormat; | |
4 | -import java.util.Date; | |
5 | - | |
6 | -import org.junit.Test; | |
7 | - | |
8 | -public class TestCase { | |
9 | - | |
10 | - @Test | |
11 | - public void test() { | |
12 | - System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(1481360497951L))); | |
13 | - } | |
14 | - | |
15 | -} |
pom.xml
... | ... | @@ -539,7 +539,7 @@ |
539 | 539 | <!-- 店铺接口签名 --> |
540 | 540 | <orders.rpc.shopClient.sign>FzZGZxd2VycXdlYXNzZHZzdnp4Y3Z</orders.rpc.shopClient.sign> |
541 | 541 | <!-- 消息中心配置 --> |
542 | - <mq.namesrvAddr>10.28.11.158:9876</mq.namesrvAddr> | |
542 | + <mq.namesrvAddr>10.28.10.215:9876</mq.namesrvAddr> | |
543 | 543 | <mq.producerGroup>orders</mq.producerGroup> |
544 | 544 | </properties> |
545 | 545 | </profile> |
... | ... |