1
|
package com.yohoufo.order.service.impl;
|
1
|
package com.yohoufo.order.service.impl;
|
2
|
|
2
|
|
|
|
3
|
+import com.google.common.collect.Lists;
|
3
|
import com.yoho.core.rest.client.ServiceCaller;
|
4
|
import com.yoho.core.rest.client.ServiceCaller;
|
4
|
import com.yoho.error.ServiceError;
|
5
|
import com.yoho.error.ServiceError;
|
5
|
import com.yoho.error.exception.ServiceException;
|
6
|
import com.yoho.error.exception.ServiceException;
|
|
|
7
|
+import com.yohoufo.common.utils.DateUtil;
|
6
|
import com.yohoufo.dal.order.BuyerOrderGoodsMapper;
|
8
|
import com.yohoufo.dal.order.BuyerOrderGoodsMapper;
|
7
|
import com.yohoufo.dal.order.BuyerOrderMapper;
|
9
|
import com.yohoufo.dal.order.BuyerOrderMapper;
|
8
|
import com.yohoufo.dal.order.SellerOrderGoodsMapper;
|
10
|
import com.yohoufo.dal.order.SellerOrderGoodsMapper;
|
|
@@ -10,8 +12,10 @@ import com.yohoufo.dal.order.model.BuyerOrder; |
|
@@ -10,8 +12,10 @@ import com.yohoufo.dal.order.model.BuyerOrder; |
10
|
import com.yohoufo.dal.order.model.BuyerOrderGoods;
|
12
|
import com.yohoufo.dal.order.model.BuyerOrderGoods;
|
11
|
import com.yohoufo.dal.order.model.SellerOrderGoods;
|
13
|
import com.yohoufo.dal.order.model.SellerOrderGoods;
|
12
|
import com.yohoufo.order.common.OrderListType;
|
14
|
import com.yohoufo.order.common.OrderListType;
|
|
|
15
|
+import com.yohoufo.order.common.OrderStatus;
|
13
|
import com.yohoufo.order.request.OrderListRequest;
|
16
|
import com.yohoufo.order.request.OrderListRequest;
|
14
|
import com.yohoufo.order.response.OrderInfo;
|
17
|
import com.yohoufo.order.response.OrderInfo;
|
|
|
18
|
+import com.yohoufo.order.response.OrderInfoListRsp;
|
15
|
import com.yohoufo.order.service.IBuyerOrderService;
|
19
|
import com.yohoufo.order.service.IBuyerOrderService;
|
16
|
import com.yohoufo.order.common.OrderCodeType;
|
20
|
import com.yohoufo.order.common.OrderCodeType;
|
17
|
import com.yohoufo.order.common.SkupStatus;
|
21
|
import com.yohoufo.order.common.SkupStatus;
|
|
@@ -52,29 +56,22 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService { |
|
@@ -52,29 +56,22 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService { |
52
|
SellerOrderGoodsMapper sellerOrderGoodsMapper;
|
56
|
SellerOrderGoodsMapper sellerOrderGoodsMapper;
|
53
|
|
57
|
|
54
|
|
58
|
|
55
|
- public void getOrderList(OrderListRequest request){
|
59
|
+ /**
|
|
|
60
|
+ * 订单列表
|
|
|
61
|
+ * @param request
|
|
|
62
|
+ * @return
|
|
|
63
|
+ */
|
|
|
64
|
+ public OrderInfoListRsp getOrderList(OrderListRequest request){
|
56
|
|
65
|
|
57
|
- if (request.getUid() < 0){
|
|
|
58
|
- logger.warn("getOrderList uid is {}", request.getUid());
|
|
|
59
|
- throw new ServiceException(ServiceError.ORDER_UID_IS_EMPTY);
|
|
|
60
|
- }
|
66
|
+ // check and init请求参数
|
|
|
67
|
+ List<Integer> statusQuery = initOrderListRequest(request);
|
61
|
|
68
|
|
62
|
- OrderListType orderListType = OrderListType.getOrderListType(request.getType());
|
|
|
63
|
- if (orderListType == null){
|
|
|
64
|
- logger.warn("getOrderList type invalidate, uid is {}, type is {}",request.getUid(), request.getType());
|
|
|
65
|
- throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY);
|
|
|
66
|
- }
|
|
|
67
|
-
|
|
|
68
|
- request.setPage(request.getPage() > 0 ? request.getPage() : 1);
|
|
|
69
|
- request.setLimit( request.getLimit() > 0 ? request.getLimit() : 10 );
|
|
|
70
|
-
|
|
|
71
|
-
|
|
|
72
|
- int total = buyerOrderMapper.selectCntByUidStatus(request.getUid(), orderListType.getStatus());
|
69
|
+ int total = buyerOrderMapper.selectCntByUidStatus(request.getUid(), statusQuery);
|
73
|
|
70
|
|
74
|
int limit = request.getLimit();
|
71
|
int limit = request.getLimit();
|
75
|
int offset = (request.getPage() - 1) * limit;
|
72
|
int offset = (request.getPage() - 1) * limit;
|
76
|
|
73
|
|
77
|
- List<BuyerOrder> buyerOrderList = buyerOrderMapper.selectListByUidStatus(request.getUid(), orderListType.getStatus(),offset, limit);
|
74
|
+ List<BuyerOrder> buyerOrderList = buyerOrderMapper.selectListByUidStatus(request.getUid(), statusQuery,offset, limit);
|
78
|
|
75
|
|
79
|
List<Long> orderCodeList = buyerOrderList.stream().map(BuyerOrder::getOrderCode).collect(Collectors.toList());
|
76
|
List<Long> orderCodeList = buyerOrderList.stream().map(BuyerOrder::getOrderCode).collect(Collectors.toList());
|
80
|
|
77
|
|
|
@@ -82,41 +79,101 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService { |
|
@@ -82,41 +79,101 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService { |
82
|
List<BuyerOrderGoods> buyerOrderGoodsList = buyerOrderGoodsMapper.selectByOrderCode(orderCodeList);
|
79
|
List<BuyerOrderGoods> buyerOrderGoodsList = buyerOrderGoodsMapper.selectByOrderCode(orderCodeList);
|
83
|
Map<Long, BuyerOrderGoods> buyerOrderGoodsMap = buyerOrderGoodsList.stream().collect(Collectors.toMap(BuyerOrderGoods::getOrderCode, Function.identity()));
|
80
|
Map<Long, BuyerOrderGoods> buyerOrderGoodsMap = buyerOrderGoodsList.stream().collect(Collectors.toMap(BuyerOrderGoods::getOrderCode, Function.identity()));
|
84
|
|
81
|
|
85
|
-
|
|
|
86
|
List<Integer> skups = buyerOrderGoodsList.stream().map(BuyerOrderGoods::getSkup).collect(Collectors.toList());
|
82
|
List<Integer> skups = buyerOrderGoodsList.stream().map(BuyerOrderGoods::getSkup).collect(Collectors.toList());
|
87
|
// seller_order_goods ===> 商品信息
|
83
|
// seller_order_goods ===> 商品信息
|
88
|
List<SellerOrderGoods> sellerOrderGoodsList = sellerOrderGoodsMapper.selectBySkups(skups);
|
84
|
List<SellerOrderGoods> sellerOrderGoodsList = sellerOrderGoodsMapper.selectBySkups(skups);
|
89
|
Map<Integer, SellerOrderGoods> sellerOrderGoodsMap = sellerOrderGoodsList.stream().collect(Collectors.toMap(SellerOrderGoods::getId, Function.identity()));
|
85
|
Map<Integer, SellerOrderGoods> sellerOrderGoodsMap = sellerOrderGoodsList.stream().collect(Collectors.toMap(SellerOrderGoods::getId, Function.identity()));
|
90
|
|
86
|
|
|
|
87
|
+ List<OrderInfo> data = Lists.newArrayList();
|
91
|
|
88
|
|
92
|
buyerOrderList.stream().forEach(buyerOrder -> {
|
89
|
buyerOrderList.stream().forEach(buyerOrder -> {
|
93
|
- OrderInfo orderInfo = new OrderInfo();
|
|
|
94
|
- orderInfo.setOrderCode(buyerOrder.getOrderCode());
|
|
|
95
|
- orderInfo.setRealPrice(buyerOrder.getAmount() == null ? "" : buyerOrder.getAmount().toPlainString());
|
90
|
+ OrderInfo orderInfo = convertOrderInfo(buyerOrderGoodsMap, sellerOrderGoodsMap, buyerOrder);
|
|
|
91
|
+ if (orderInfo == null) return;
|
96
|
|
92
|
|
97
|
- BuyerOrderGoods buyerOrderGoods = buyerOrderGoodsMap.get(buyerOrder.getOrderCode());
|
|
|
98
|
- if (buyerOrderGoods == null){
|
|
|
99
|
- return;
|
|
|
100
|
- }
|
|
|
101
|
- orderInfo.setSkup(buyerOrderGoods.getSkup());
|
93
|
+ data.add(orderInfo);
|
102
|
|
94
|
|
103
|
- SellerOrderGoods sellerOrderGoods = sellerOrderGoodsMap.get(buyerOrderGoods.getSkup());
|
|
|
104
|
- orderInfo.setProductName(sellerOrderGoods.getProductName());
|
|
|
105
|
- orderInfo.setImageUrl(sellerOrderGoods.getImageUrl());
|
|
|
106
|
- orderInfo.setColorName(sellerOrderGoods.getColorName());
|
|
|
107
|
- orderInfo.setSizeName(sellerOrderGoods.getSizeName());
|
|
|
108
|
-
|
|
|
109
|
- // 订单状态显示
|
95
|
+ });
|
110
|
|
96
|
|
111
|
- // 按钮显示
|
97
|
+ OrderInfoListRsp orderInfoListRsp = OrderInfoListRsp.builder()
|
|
|
98
|
+ .data(data)
|
|
|
99
|
+ .currPage(request.getPage())
|
|
|
100
|
+ .limit(limit)
|
|
|
101
|
+ .total(total)
|
|
|
102
|
+ .currTotal(data.size())
|
|
|
103
|
+ .pageSize((total % limit == 0) ? (total / limit) : (total / limit + 1)).build();
|
112
|
|
104
|
|
|
|
105
|
+ return orderInfoListRsp;
|
113
|
|
106
|
|
|
|
107
|
+ }
|
114
|
|
108
|
|
|
|
109
|
+ /**
|
|
|
110
|
+ * 获取返回结果
|
|
|
111
|
+ * @param buyerOrderGoodsMap
|
|
|
112
|
+ * @param sellerOrderGoodsMap
|
|
|
113
|
+ * @param buyerOrder
|
|
|
114
|
+ * @return
|
|
|
115
|
+ */
|
|
|
116
|
+ private OrderInfo convertOrderInfo(Map<Long, BuyerOrderGoods> buyerOrderGoodsMap,
|
|
|
117
|
+ Map<Integer, SellerOrderGoods> sellerOrderGoodsMap,
|
|
|
118
|
+ BuyerOrder buyerOrder) {
|
|
|
119
|
+
|
|
|
120
|
+ /**
|
|
|
121
|
+ * 1.查询 buyer_order
|
|
|
122
|
+ * 2.查询 buyer_order_goods ==> skup
|
|
|
123
|
+ * 3.查询 seller_order_goods
|
|
|
124
|
+ */
|
|
|
125
|
+ OrderInfo orderInfo = new OrderInfo();
|
|
|
126
|
+ orderInfo.setOrderCode(buyerOrder.getOrderCode());
|
|
|
127
|
+ orderInfo.setRealPrice(buyerOrder.getAmount() == null ? "" : buyerOrder.getAmount().toPlainString());
|
|
|
128
|
+ // 订单中状态显示
|
|
|
129
|
+ orderInfo.setStatus(buyerOrder.getStatus() == null ? -1 : buyerOrder.getStatus());
|
|
|
130
|
+ OrderStatus orderStatus = OrderStatus.getOrderStatus(orderInfo.getStatus());
|
|
|
131
|
+ orderInfo.setStatuStr(orderStatus == null ? "" : orderStatus.getListStatusStr());
|
|
|
132
|
+
|
|
|
133
|
+ // 按钮显示
|
|
|
134
|
+ orderInfo.setButtons(orderStatus == null ? Lists.newArrayList() : orderStatus.getButtonList());
|
|
|
135
|
+
|
|
|
136
|
+ // 当订单状态是待付款, 显示leftTime
|
|
|
137
|
+ if (orderInfo.getStatus() == OrderStatus.WAITING_PAY.getCode()){
|
|
|
138
|
+ orderInfo.setLeftTime(DateUtil.getCurrentTimeSecond() - buyerOrder.getCreateTime());
|
|
|
139
|
+ }
|
115
|
|
140
|
|
116
|
- });
|
141
|
+ BuyerOrderGoods buyerOrderGoods = buyerOrderGoodsMap.get(buyerOrder.getOrderCode());
|
|
|
142
|
+ if (buyerOrderGoods == null){
|
|
|
143
|
+ return null;
|
|
|
144
|
+ }
|
|
|
145
|
+ orderInfo.setSkup(buyerOrderGoods.getSkup());
|
117
|
|
146
|
|
|
|
147
|
+ SellerOrderGoods sellerOrderGoods = sellerOrderGoodsMap.get(buyerOrderGoods.getSkup());
|
|
|
148
|
+ if (sellerOrderGoods == null){
|
|
|
149
|
+ return null;
|
|
|
150
|
+ }
|
|
|
151
|
+ orderInfo.setProductName(sellerOrderGoods.getProductName());
|
|
|
152
|
+ orderInfo.setImageUrl(sellerOrderGoods.getImageUrl());
|
|
|
153
|
+ orderInfo.setColorName(sellerOrderGoods.getColorName());
|
|
|
154
|
+ orderInfo.setSizeName(sellerOrderGoods.getSizeName());
|
|
|
155
|
+ return orderInfo;
|
|
|
156
|
+ }
|
118
|
|
157
|
|
|
|
158
|
+ /**
|
|
|
159
|
+ * 根据type获取 指定的状态
|
|
|
160
|
+ * @param request
|
|
|
161
|
+ * @return
|
|
|
162
|
+ */
|
|
|
163
|
+ private List<Integer> initOrderListRequest(OrderListRequest request) {
|
|
|
164
|
+ if (request.getUid() < 0){
|
|
|
165
|
+ logger.warn("getOrderList uid is {}", request.getUid());
|
|
|
166
|
+ throw new ServiceException(ServiceError.ORDER_UID_IS_EMPTY);
|
|
|
167
|
+ }
|
119
|
|
168
|
|
|
|
169
|
+ OrderListType orderListType = OrderListType.getOrderListType(request.getType());
|
|
|
170
|
+ if (orderListType == null){
|
|
|
171
|
+ logger.warn("getOrderList type invalidate, uid is {}, type is {}",request.getUid(), request.getType());
|
|
|
172
|
+ throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY);
|
|
|
173
|
+ }
|
120
|
|
174
|
|
|
|
175
|
+ request.setPage(request.getPage() > 0 ? request.getPage() : 1);
|
|
|
176
|
+ request.setLimit( request.getLimit() > 0 ? request.getLimit() : 10 );
|
|
|
177
|
+ return orderListType.getStatusQuery();
|
121
|
}
|
178
|
}
|
122
|
} |
179
|
} |