Merge branch 'dev_order' into test6.8.2
Showing
4 changed files
with
102 additions
and
24 deletions
@@ -99,7 +99,7 @@ public class SellerOrderController { | @@ -99,7 +99,7 @@ public class SellerOrderController { | ||
99 | @ResponseBody | 99 | @ResponseBody |
100 | public ApiResponse batchCancel(@RequestParam(name = "uid", required = true)int uid, | 100 | public ApiResponse batchCancel(@RequestParam(name = "uid", required = true)int uid, |
101 | @RequestParam(name = "batchNo", required = true)String batchNo, | 101 | @RequestParam(name = "batchNo", required = true)String batchNo, |
102 | - @RequestParam(name="num", defaultValue = "1", required = false)int num, | 102 | + @RequestParam(name="num")int num, |
103 | @RequestParam(name = "skupList", required = true)String skupList | 103 | @RequestParam(name = "skupList", required = true)String skupList |
104 | 104 | ||
105 | ) throws GatewayException { | 105 | ) throws GatewayException { |
@@ -8,15 +8,18 @@ import com.yohoufo.dal.order.BuyerOrderMapper; | @@ -8,15 +8,18 @@ import com.yohoufo.dal.order.BuyerOrderMapper; | ||
8 | import com.yohoufo.dal.order.OrderCouponMapper; | 8 | import com.yohoufo.dal.order.OrderCouponMapper; |
9 | import com.yohoufo.dal.order.SellerOrderGoodsMapper; | 9 | import com.yohoufo.dal.order.SellerOrderGoodsMapper; |
10 | import com.yohoufo.dal.order.SellerOrderMapper; | 10 | import com.yohoufo.dal.order.SellerOrderMapper; |
11 | +import com.yohoufo.dal.order.model.BuyerOrder; | ||
11 | import com.yohoufo.dal.order.model.OrderCoupon; | 12 | import com.yohoufo.dal.order.model.OrderCoupon; |
12 | import com.yohoufo.dal.order.model.SellerOrder; | 13 | import com.yohoufo.dal.order.model.SellerOrder; |
13 | import com.yohoufo.dal.order.model.SellerOrderGoods; | 14 | import com.yohoufo.dal.order.model.SellerOrderGoods; |
14 | import com.yohoufo.order.common.RefundCase; | 15 | import com.yohoufo.order.common.RefundCase; |
16 | +import com.yohoufo.order.common.TransferCase; | ||
15 | import com.yohoufo.order.event.BeforeDepotReceiveEvent; | 17 | import com.yohoufo.order.event.BeforeDepotReceiveEvent; |
16 | import com.yohoufo.order.event.BeforeSellerDeliverEvent; | 18 | import com.yohoufo.order.event.BeforeSellerDeliverEvent; |
17 | import com.yohoufo.order.event.BillLogEvent; | 19 | import com.yohoufo.order.event.BillLogEvent; |
18 | import com.yohoufo.order.model.bo.CouponBo; | 20 | import com.yohoufo.order.model.bo.CouponBo; |
19 | import com.yohoufo.order.model.request.PaymentRequest; | 21 | import com.yohoufo.order.model.request.PaymentRequest; |
22 | +import com.yohoufo.order.model.request.TransferMoneyRequest; | ||
20 | import com.yohoufo.order.service.IPaymentService; | 23 | import com.yohoufo.order.service.IPaymentService; |
21 | import com.yohoufo.order.service.concurrent.ThreadPoolFactory; | 24 | import com.yohoufo.order.service.concurrent.ThreadPoolFactory; |
22 | import com.yohoufo.order.service.proxy.CouponProxyService; | 25 | import com.yohoufo.order.service.proxy.CouponProxyService; |
@@ -85,23 +88,14 @@ public class BuyerOrderCancelService { | @@ -85,23 +88,14 @@ public class BuyerOrderCancelService { | ||
85 | 88 | ||
86 | //TODO 整个过程异步去执行(考虑退费依赖订单状态) | 89 | //TODO 整个过程异步去执行(考虑退费依赖订单状态) |
87 | //(退费)退保证金给卖家 | 90 | //(退费)退保证金给卖家 |
88 | - SellerOrder sellerOrder = sellerOrderMapper.selectByOrderCode(orderCode); | ||
89 | - int sellerUid = sellerOrder.getUid(); | ||
90 | - long sellerOrderCode = sellerOrder.getOrderCode(); | ||
91 | - BigDecimal earnestMoney = sellerOrder.getEarnestMoney(); | ||
92 | - PaymentRequest req = PaymentRequest.builder().uid(sellerUid) | ||
93 | - .orderCode(sellerOrderCode).refundAmount(earnestMoney.doubleValue()) | ||
94 | - .build(); | ||
95 | - BillLogEvent.BillLogEventBuilder bleb = BillLogEvent.builder() | ||
96 | - .buyerUid(buyerUid).sellerUid(sellerUid).orderCode(sellerOrder.getOrderCode()) | ||
97 | - .payType(sellerOrder.getPayment()).refundCase(RefundCase.SELLER_EARNEST_MONEY) | ||
98 | - .skup(skup); | ||
99 | - payRefundService.refund(req, bleb); | ||
100 | - | ||
101 | //(转账)瓜分指定赔偿款给卖家和平台 | 91 | //(转账)瓜分指定赔偿款给卖家和平台 |
92 | + TransferCase transferCase = TransferCase.BUYER_CANCEL_BEFORE_SELLER_DELIVER; | ||
102 | //(退费)扣除赔偿款,计算剩余的货款,退给买家 | 93 | //(退费)扣除赔偿款,计算剩余的货款,退给买家 |
103 | - BuyerCancelAfterProcessTask bcapt = new BuyerCancelAfterProcessTask(); | 94 | + BuyerCancelAfterProcessTask bcapt = new BuyerCancelAfterProcessTask(buyerUid, orderCode, skup, |
95 | + compensate, transferCase); | ||
104 | ThreadPoolFactory.getBuyerCancelThreadPool().submit(bcapt); | 96 | ThreadPoolFactory.getBuyerCancelThreadPool().submit(bcapt); |
97 | + logger.info("use one thread to execute buyer cancel BeforeSellerDeliver buyerUid {}, orderCode {}, skup {}, compensate {}, transferCase {}", | ||
98 | + buyerUid, orderCode, skup, compensate, transferCase); | ||
105 | } | 99 | } |
106 | } | 100 | } |
107 | 101 | ||
@@ -124,18 +118,73 @@ public class BuyerOrderCancelService { | @@ -124,18 +118,73 @@ public class BuyerOrderCancelService { | ||
124 | targetGoods.setExceptStatus(SkupStatus.SELL_OUT.getCode()); | 118 | targetGoods.setExceptStatus(SkupStatus.SELL_OUT.getCode()); |
125 | sellerOrderGoodsMapper.updateStatusBySkpu(targetGoods); | 119 | sellerOrderGoodsMapper.updateStatusBySkpu(targetGoods); |
126 | 120 | ||
127 | - //TODO 整个过程异步去执行(考虑退费依赖订单状态) | 121 | + //整个过程异步去执行(考虑退费依赖订单状态) |
128 | //(退费)退保证金给卖家 | 122 | //(退费)退保证金给卖家 |
129 | - | ||
130 | //(转账)瓜分指定赔偿款给卖家和平台 | 123 | //(转账)瓜分指定赔偿款给卖家和平台 |
131 | //(退费)扣除赔偿款,计算剩余的货款,退给买家 | 124 | //(退费)扣除赔偿款,计算剩余的货款,退给买家 |
125 | + TransferCase transferCase = TransferCase.BUYER_CANCEL_BEFORE_DEPOT_RECEIVE; | ||
126 | + BuyerCancelAfterProcessTask bcapt = new BuyerCancelAfterProcessTask(buyerUid, orderCode, skup, | ||
127 | + compensate, transferCase); | ||
128 | + ThreadPoolFactory.getBuyerCancelThreadPool().submit(bcapt); | ||
129 | + logger.info("use one thread to execute buyer cancel BeforeDepotReceive buyerUid {}, orderCode {}, skup {}, compensate {}, transferCase {}", | ||
130 | + buyerUid, orderCode, skup, compensate, transferCase); | ||
132 | } | 131 | } |
133 | } | 132 | } |
134 | 133 | ||
135 | class BuyerCancelAfterProcessTask implements Callable{ | 134 | class BuyerCancelAfterProcessTask implements Callable{ |
135 | + int buyerUid; | ||
136 | + long orderCode; | ||
137 | + int skup; | ||
138 | + OrderDynamicConfig.BuyerCancelCompensateNode compensate; | ||
139 | + TransferCase transferCase; | ||
140 | + | ||
141 | + public BuyerCancelAfterProcessTask(int buyerUid, long orderCode, int skup, OrderDynamicConfig. | ||
142 | + BuyerCancelCompensateNode compensate, TransferCase transferCase) { | ||
143 | + this.buyerUid = buyerUid; | ||
144 | + this.orderCode = orderCode; | ||
145 | + this.skup = skup; | ||
146 | + this.compensate = compensate; | ||
147 | + this.transferCase = transferCase; | ||
148 | + } | ||
136 | 149 | ||
137 | @Override | 150 | @Override |
138 | public Object call() throws Exception { | 151 | public Object call() throws Exception { |
152 | + // 整个过程异步去执行(考虑退费依赖订单状态) | ||
153 | + //(退费)退保证金给卖家 | ||
154 | + SellerOrder sellerOrder = sellerOrderMapper.selectByOrderCode(orderCode); | ||
155 | + int sellerUid = sellerOrder.getUid(); | ||
156 | + long sellerOrderCode = sellerOrder.getOrderCode(); | ||
157 | + BigDecimal earnestMoney = sellerOrder.getEarnestMoney(); | ||
158 | + PaymentRequest req = PaymentRequest.builder().uid(sellerUid) | ||
159 | + .orderCode(sellerOrderCode).refundAmount(earnestMoney.doubleValue()) | ||
160 | + .build(); | ||
161 | + BillLogEvent.BillLogEventBuilder bleb = BillLogEvent.builder() | ||
162 | + .buyerUid(buyerUid).sellerUid(sellerUid).orderCode(sellerOrder.getOrderCode()) | ||
163 | + .payType(sellerOrder.getPayment()).refundCase(RefundCase.SELLER_EARNEST_MONEY) | ||
164 | + .skup(skup); | ||
165 | + payRefundService.refund(req, bleb); | ||
166 | + | ||
167 | + //(转账)瓜分指定赔偿款给卖家和平台 | ||
168 | + | ||
169 | + TransferMoneyRequest tmReq = TransferMoneyRequest.builder().buyerOrderCode(orderCode) | ||
170 | + .type(transferCase.getCode()).transferCase(transferCase).build(); | ||
171 | + paymentService.transferMon(tmReq); | ||
172 | + | ||
173 | + //(退费)扣除赔偿款,计算剩余的货款,退给买家 | ||
174 | + BigDecimal compensateMoney = compensate.getBuyerCompensateMoney(); | ||
175 | + | ||
176 | + | ||
177 | + BuyerOrder buyerOrder = buyerOrderMapper.selectByOrderCode(orderCode); | ||
178 | + BigDecimal leftBuyerMoney = buyerOrder.getAmount().subtract(compensateMoney); | ||
179 | + PaymentRequest rprOfBuyer = PaymentRequest.builder().uid(buyerUid) | ||
180 | + .orderCode(orderCode).refundAmount(leftBuyerMoney.doubleValue()) | ||
181 | + .build(); | ||
182 | + BillLogEvent.BillLogEventBuilder blebOfBuyer = BillLogEvent.builder() | ||
183 | + .buyerUid(buyerUid).sellerUid(sellerUid).orderCode(orderCode) | ||
184 | + .payType(buyerOrder.getPayment()).refundCase(RefundCase.BUYER_GOODS_MONEY) | ||
185 | + .skup(skup); | ||
186 | + payRefundService.refund(rprOfBuyer, blebOfBuyer); | ||
187 | + | ||
139 | return null; | 188 | return null; |
140 | } | 189 | } |
141 | } | 190 | } |
1 | package com.yohoufo.order.service.impl; | 1 | package com.yohoufo.order.service.impl; |
2 | 2 | ||
3 | +import com.google.common.collect.Sets; | ||
3 | import com.yoho.error.ServiceError; | 4 | import com.yoho.error.ServiceError; |
4 | import com.yoho.error.exception.ServiceException; | 5 | import com.yoho.error.exception.ServiceException; |
5 | import com.yohobuy.ufo.model.order.bo.GoodsInfo; | 6 | import com.yohobuy.ufo.model.order.bo.GoodsInfo; |
@@ -313,11 +314,19 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi | @@ -313,11 +314,19 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi | ||
313 | Long batchNo = sbcppdn.getBatchNo(); | 314 | Long batchNo = sbcppdn.getBatchNo(); |
314 | List<Integer> needOffShelveSkups = sbcppdn.getNeedOffShelveSkups(); | 315 | List<Integer> needOffShelveSkups = sbcppdn.getNeedOffShelveSkups(); |
315 | Map<Integer, SkupDto> tskupMap = sbcppdn.getTskupMap(); | 316 | Map<Integer, SkupDto> tskupMap = sbcppdn.getTskupMap(); |
316 | - Set<Integer> skupSet = tskupMap.keySet(); | ||
317 | - if(productProxyService.sellerBatchUpdateStatus(new ArrayList<>(skupSet), ProductProxyService.PrdShelvelStatus.off)){ | 317 | + Set<Integer> skupSets = tskupMap.keySet(); |
318 | + List<Integer> needCancelSkups ; | ||
319 | + int num = sbcppdn.getNum(); | ||
320 | + if (num >= skupSets.size()){ | ||
321 | + needCancelSkups = new ArrayList<>(skupSets); | ||
322 | + }else{ | ||
323 | + needCancelSkups = new ArrayList<>(skupSets).subList(0,num); | ||
324 | + } | ||
325 | + log.info("in batch cancel req {} needCancelSkups {}", req, needCancelSkups); | ||
326 | + if(productProxyService.sellerBatchUpdateStatus(needCancelSkups, ProductProxyService.PrdShelvelStatus.off)){ | ||
318 | //1.1 商品下架成功后 | 327 | //1.1 商品下架成功后 |
319 | //2 划账(退还下架成功的skup对应的保证金) | 328 | //2 划账(退还下架成功的skup对应的保证金) |
320 | - List<SellerOrder> soList = sellerOrderMapper.selectBySkups(skupSet); | 329 | + List<SellerOrder> soList = sellerOrderMapper.selectBySkups(needCancelSkups); |
321 | BigDecimal totalRefundEM = new BigDecimal(0); | 330 | BigDecimal totalRefundEM = new BigDecimal(0); |
322 | for(SellerOrder so : soList ){ | 331 | for(SellerOrder so : soList ){ |
323 | totalRefundEM = totalRefundEM.add(so.getEarnestMoney()); | 332 | totalRefundEM = totalRefundEM.add(so.getEarnestMoney()); |
@@ -328,11 +337,16 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi | @@ -328,11 +337,16 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi | ||
328 | // 3 修改 seller_order(状态)sell_order_goods(状态) | 337 | // 3 修改 seller_order(状态)sell_order_goods(状态) |
329 | SellerOrder soc = new SellerOrder(); | 338 | SellerOrder soc = new SellerOrder(); |
330 | soc.setStatus(SellerOrderStatus.PLAY_SELF.getCode()); | 339 | soc.setStatus(SellerOrderStatus.PLAY_SELF.getCode()); |
331 | - sellerOrderMapper.updateBySkups(soc, skupSet); | 340 | + log.info("batch cancel sellerOrderMapper.updateBySkups req {} needCancelSkups {} soc {}", |
341 | + req, needCancelSkups, soc); | ||
342 | + sellerOrderMapper.updateBySkups(soc, needCancelSkups); | ||
332 | 343 | ||
333 | SellerOrderGoods sogc = new SellerOrderGoods(); | 344 | SellerOrderGoods sogc = new SellerOrderGoods(); |
334 | sogc.setStatus(SkupStatus.SELLER_CANCEL_SELL.getCode()); | 345 | sogc.setStatus(SkupStatus.SELLER_CANCEL_SELL.getCode()); |
335 | - sellerOrderGoodsMapper.updateByPrimaryKeys(sogc, skupSet); | 346 | + log.info("batch cancel sellerOrderGoodsMapper.updateByPrimaryKeys req {} needCancelSkups {} sogc {}", |
347 | + req, needCancelSkups, sogc); | ||
348 | + sellerOrderGoodsMapper.updateByPrimaryKeys(sogc, needCancelSkups); | ||
349 | + | ||
336 | //4 划账记录 | 350 | //4 划账记录 |
337 | List<OrderInfo> orderList = soList.parallelStream().map(so->OrderInfo.builder() | 351 | List<OrderInfo> orderList = soList.parallelStream().map(so->OrderInfo.builder() |
338 | .orderCode(so.getOrderCode()).amount(so.getEarnestMoney()).build()).collect(Collectors.toList());; | 352 | .orderCode(so.getOrderCode()).amount(so.getEarnestMoney()).build()).collect(Collectors.toList());; |
@@ -42,10 +42,15 @@ public class SellerBatchCancelPrepareProcessor { | @@ -42,10 +42,15 @@ public class SellerBatchCancelPrepareProcessor { | ||
42 | 42 | ||
43 | Map<Integer, SkupDto> tskupMap; | 43 | Map<Integer, SkupDto> tskupMap; |
44 | 44 | ||
45 | - public DataNode(Long batchNo, List<Integer> needOffShelveSkups, Map<Integer, SkupDto> tskupMap) { | 45 | + int num; |
46 | + | ||
47 | + | ||
48 | + | ||
49 | + public DataNode(Long batchNo, List<Integer> needOffShelveSkups, Map<Integer, SkupDto> tskupMap, int num) { | ||
46 | this.batchNo = batchNo; | 50 | this.batchNo = batchNo; |
47 | this.needOffShelveSkups = needOffShelveSkups; | 51 | this.needOffShelveSkups = needOffShelveSkups; |
48 | this.tskupMap = tskupMap; | 52 | this.tskupMap = tskupMap; |
53 | + this.num = num; | ||
49 | } | 54 | } |
50 | } | 55 | } |
51 | 56 | ||
@@ -55,6 +60,11 @@ public class SellerBatchCancelPrepareProcessor { | @@ -55,6 +60,11 @@ public class SellerBatchCancelPrepareProcessor { | ||
55 | logger.warn("batch off shelve checkAndAcquire uid illegal , req {}", req); | 60 | logger.warn("batch off shelve checkAndAcquire uid illegal , req {}", req); |
56 | throw new UfoServiceException(400, "参数[uid]错误"); | 61 | throw new UfoServiceException(400, "参数[uid]错误"); |
57 | } | 62 | } |
63 | + int num = req.getStorageNum(); | ||
64 | + if (num <= 0){ | ||
65 | + logger.warn("batch off shelve checkAndAcquire num is illegal, req {}", req); | ||
66 | + throw new UfoServiceException(400, "数量不合法"); | ||
67 | + } | ||
58 | 68 | ||
59 | if(!sellerOrderPrepareProcessor.checkIsEntry(uid)){ | 69 | if(!sellerOrderPrepareProcessor.checkIsEntry(uid)){ |
60 | logger.warn("batch off shelve checkAndAcquire uid is not entry shop , req {}", req); | 70 | logger.warn("batch off shelve checkAndAcquire uid is not entry shop , req {}", req); |
@@ -69,13 +79,18 @@ public class SellerBatchCancelPrepareProcessor { | @@ -69,13 +79,18 @@ public class SellerBatchCancelPrepareProcessor { | ||
69 | //考虑到并发,需要进行过滤,将不是出售中状态的skup排除掉; | 79 | //考虑到并发,需要进行过滤,将不是出售中状态的skup排除掉; |
70 | //不做过滤导致后面的数量 扣费检查都可能不对 | 80 | //不做过滤导致后面的数量 扣费检查都可能不对 |
71 | List<String> skupStrList = Splitter.on(',').trimResults().omitEmptyStrings().splitToList(skupList); | 81 | List<String> skupStrList = Splitter.on(',').trimResults().omitEmptyStrings().splitToList(skupList); |
82 | + if (skupStrList.size() < num){ | ||
83 | + logger.warn("batch off shelve checkAndAcquire num bigger than skups , req {}", req); | ||
84 | + throw new UfoServiceException(400, "数目大于实际商品数"); | ||
85 | + } | ||
86 | + | ||
72 | List<Integer> needOffShelveSkups = skupStrList.parallelStream().map(Integer::valueOf).collect(Collectors.toList()); | 87 | List<Integer> needOffShelveSkups = skupStrList.parallelStream().map(Integer::valueOf).collect(Collectors.toList()); |
73 | //check batch no | 88 | //check batch no |
74 | Long batchNo = checkNAcquireBatchNo(req.getBatchNo(), req); | 89 | Long batchNo = checkNAcquireBatchNo(req.getBatchNo(), req); |
75 | 90 | ||
76 | //检查 | 91 | //检查 |
77 | Map<Integer, SkupDto> skupMap = checkNeedProcessSkups(needOffShelveSkups,req); | 92 | Map<Integer, SkupDto> skupMap = checkNeedProcessSkups(needOffShelveSkups,req); |
78 | - DataNode node = new DataNode(batchNo, needOffShelveSkups, skupMap); | 93 | + DataNode node = new DataNode(batchNo, needOffShelveSkups, skupMap, num); |
79 | return node; | 94 | return node; |
80 | } | 95 | } |
81 | 96 |
-
Please register or login to post a comment