Authored by chenchao

Merge branch 'dev_order' into test6.8.2

... ... @@ -99,7 +99,7 @@ public class SellerOrderController {
@ResponseBody
public ApiResponse batchCancel(@RequestParam(name = "uid", required = true)int uid,
@RequestParam(name = "batchNo", required = true)String batchNo,
@RequestParam(name="num", defaultValue = "1", required = false)int num,
@RequestParam(name="num")int num,
@RequestParam(name = "skupList", required = true)String skupList
) throws GatewayException {
... ...
... ... @@ -8,15 +8,18 @@ import com.yohoufo.dal.order.BuyerOrderMapper;
import com.yohoufo.dal.order.OrderCouponMapper;
import com.yohoufo.dal.order.SellerOrderGoodsMapper;
import com.yohoufo.dal.order.SellerOrderMapper;
import com.yohoufo.dal.order.model.BuyerOrder;
import com.yohoufo.dal.order.model.OrderCoupon;
import com.yohoufo.dal.order.model.SellerOrder;
import com.yohoufo.dal.order.model.SellerOrderGoods;
import com.yohoufo.order.common.RefundCase;
import com.yohoufo.order.common.TransferCase;
import com.yohoufo.order.event.BeforeDepotReceiveEvent;
import com.yohoufo.order.event.BeforeSellerDeliverEvent;
import com.yohoufo.order.event.BillLogEvent;
import com.yohoufo.order.model.bo.CouponBo;
import com.yohoufo.order.model.request.PaymentRequest;
import com.yohoufo.order.model.request.TransferMoneyRequest;
import com.yohoufo.order.service.IPaymentService;
import com.yohoufo.order.service.concurrent.ThreadPoolFactory;
import com.yohoufo.order.service.proxy.CouponProxyService;
... ... @@ -85,23 +88,14 @@ public class BuyerOrderCancelService {
//TODO 整个过程异步去执行(考虑退费依赖订单状态)
//(退费)退保证金给卖家
SellerOrder sellerOrder = sellerOrderMapper.selectByOrderCode(orderCode);
int sellerUid = sellerOrder.getUid();
long sellerOrderCode = sellerOrder.getOrderCode();
BigDecimal earnestMoney = sellerOrder.getEarnestMoney();
PaymentRequest req = PaymentRequest.builder().uid(sellerUid)
.orderCode(sellerOrderCode).refundAmount(earnestMoney.doubleValue())
.build();
BillLogEvent.BillLogEventBuilder bleb = BillLogEvent.builder()
.buyerUid(buyerUid).sellerUid(sellerUid).orderCode(sellerOrder.getOrderCode())
.payType(sellerOrder.getPayment()).refundCase(RefundCase.SELLER_EARNEST_MONEY)
.skup(skup);
payRefundService.refund(req, bleb);
//(转账)瓜分指定赔偿款给卖家和平台
TransferCase transferCase = TransferCase.BUYER_CANCEL_BEFORE_SELLER_DELIVER;
//(退费)扣除赔偿款,计算剩余的货款,退给买家
BuyerCancelAfterProcessTask bcapt = new BuyerCancelAfterProcessTask();
BuyerCancelAfterProcessTask bcapt = new BuyerCancelAfterProcessTask(buyerUid, orderCode, skup,
compensate, transferCase);
ThreadPoolFactory.getBuyerCancelThreadPool().submit(bcapt);
logger.info("use one thread to execute buyer cancel BeforeSellerDeliver buyerUid {}, orderCode {}, skup {}, compensate {}, transferCase {}",
buyerUid, orderCode, skup, compensate, transferCase);
}
}
... ... @@ -124,18 +118,73 @@ public class BuyerOrderCancelService {
targetGoods.setExceptStatus(SkupStatus.SELL_OUT.getCode());
sellerOrderGoodsMapper.updateStatusBySkpu(targetGoods);
//TODO 整个过程异步去执行(考虑退费依赖订单状态)
//整个过程异步去执行(考虑退费依赖订单状态)
//(退费)退保证金给卖家
//(转账)瓜分指定赔偿款给卖家和平台
//(退费)扣除赔偿款,计算剩余的货款,退给买家
TransferCase transferCase = TransferCase.BUYER_CANCEL_BEFORE_DEPOT_RECEIVE;
BuyerCancelAfterProcessTask bcapt = new BuyerCancelAfterProcessTask(buyerUid, orderCode, skup,
compensate, transferCase);
ThreadPoolFactory.getBuyerCancelThreadPool().submit(bcapt);
logger.info("use one thread to execute buyer cancel BeforeDepotReceive buyerUid {}, orderCode {}, skup {}, compensate {}, transferCase {}",
buyerUid, orderCode, skup, compensate, transferCase);
}
}
class BuyerCancelAfterProcessTask implements Callable{
int buyerUid;
long orderCode;
int skup;
OrderDynamicConfig.BuyerCancelCompensateNode compensate;
TransferCase transferCase;
public BuyerCancelAfterProcessTask(int buyerUid, long orderCode, int skup, OrderDynamicConfig.
BuyerCancelCompensateNode compensate, TransferCase transferCase) {
this.buyerUid = buyerUid;
this.orderCode = orderCode;
this.skup = skup;
this.compensate = compensate;
this.transferCase = transferCase;
}
@Override
public Object call() throws Exception {
// 整个过程异步去执行(考虑退费依赖订单状态)
//(退费)退保证金给卖家
SellerOrder sellerOrder = sellerOrderMapper.selectByOrderCode(orderCode);
int sellerUid = sellerOrder.getUid();
long sellerOrderCode = sellerOrder.getOrderCode();
BigDecimal earnestMoney = sellerOrder.getEarnestMoney();
PaymentRequest req = PaymentRequest.builder().uid(sellerUid)
.orderCode(sellerOrderCode).refundAmount(earnestMoney.doubleValue())
.build();
BillLogEvent.BillLogEventBuilder bleb = BillLogEvent.builder()
.buyerUid(buyerUid).sellerUid(sellerUid).orderCode(sellerOrder.getOrderCode())
.payType(sellerOrder.getPayment()).refundCase(RefundCase.SELLER_EARNEST_MONEY)
.skup(skup);
payRefundService.refund(req, bleb);
//(转账)瓜分指定赔偿款给卖家和平台
TransferMoneyRequest tmReq = TransferMoneyRequest.builder().buyerOrderCode(orderCode)
.type(transferCase.getCode()).transferCase(transferCase).build();
paymentService.transferMon(tmReq);
//(退费)扣除赔偿款,计算剩余的货款,退给买家
BigDecimal compensateMoney = compensate.getBuyerCompensateMoney();
BuyerOrder buyerOrder = buyerOrderMapper.selectByOrderCode(orderCode);
BigDecimal leftBuyerMoney = buyerOrder.getAmount().subtract(compensateMoney);
PaymentRequest rprOfBuyer = PaymentRequest.builder().uid(buyerUid)
.orderCode(orderCode).refundAmount(leftBuyerMoney.doubleValue())
.build();
BillLogEvent.BillLogEventBuilder blebOfBuyer = BillLogEvent.builder()
.buyerUid(buyerUid).sellerUid(sellerUid).orderCode(orderCode)
.payType(buyerOrder.getPayment()).refundCase(RefundCase.BUYER_GOODS_MONEY)
.skup(skup);
payRefundService.refund(rprOfBuyer, blebOfBuyer);
return null;
}
}
... ...
package com.yohoufo.order.service.impl;
import com.google.common.collect.Sets;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yohobuy.ufo.model.order.bo.GoodsInfo;
... ... @@ -313,11 +314,19 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
Long batchNo = sbcppdn.getBatchNo();
List<Integer> needOffShelveSkups = sbcppdn.getNeedOffShelveSkups();
Map<Integer, SkupDto> tskupMap = sbcppdn.getTskupMap();
Set<Integer> skupSet = tskupMap.keySet();
if(productProxyService.sellerBatchUpdateStatus(new ArrayList<>(skupSet), ProductProxyService.PrdShelvelStatus.off)){
Set<Integer> skupSets = tskupMap.keySet();
List<Integer> needCancelSkups ;
int num = sbcppdn.getNum();
if (num >= skupSets.size()){
needCancelSkups = new ArrayList<>(skupSets);
}else{
needCancelSkups = new ArrayList<>(skupSets).subList(0,num);
}
log.info("in batch cancel req {} needCancelSkups {}", req, needCancelSkups);
if(productProxyService.sellerBatchUpdateStatus(needCancelSkups, ProductProxyService.PrdShelvelStatus.off)){
//1.1 商品下架成功后
//2 划账(退还下架成功的skup对应的保证金)
List<SellerOrder> soList = sellerOrderMapper.selectBySkups(skupSet);
List<SellerOrder> soList = sellerOrderMapper.selectBySkups(needCancelSkups);
BigDecimal totalRefundEM = new BigDecimal(0);
for(SellerOrder so : soList ){
totalRefundEM = totalRefundEM.add(so.getEarnestMoney());
... ... @@ -328,11 +337,16 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
// 3 修改 seller_order(状态)sell_order_goods(状态)
SellerOrder soc = new SellerOrder();
soc.setStatus(SellerOrderStatus.PLAY_SELF.getCode());
sellerOrderMapper.updateBySkups(soc, skupSet);
log.info("batch cancel sellerOrderMapper.updateBySkups req {} needCancelSkups {} soc {}",
req, needCancelSkups, soc);
sellerOrderMapper.updateBySkups(soc, needCancelSkups);
SellerOrderGoods sogc = new SellerOrderGoods();
sogc.setStatus(SkupStatus.SELLER_CANCEL_SELL.getCode());
sellerOrderGoodsMapper.updateByPrimaryKeys(sogc, skupSet);
log.info("batch cancel sellerOrderGoodsMapper.updateByPrimaryKeys req {} needCancelSkups {} sogc {}",
req, needCancelSkups, sogc);
sellerOrderGoodsMapper.updateByPrimaryKeys(sogc, needCancelSkups);
//4 划账记录
List<OrderInfo> orderList = soList.parallelStream().map(so->OrderInfo.builder()
.orderCode(so.getOrderCode()).amount(so.getEarnestMoney()).build()).collect(Collectors.toList());;
... ...
... ... @@ -42,10 +42,15 @@ public class SellerBatchCancelPrepareProcessor {
Map<Integer, SkupDto> tskupMap;
public DataNode(Long batchNo, List<Integer> needOffShelveSkups, Map<Integer, SkupDto> tskupMap) {
int num;
public DataNode(Long batchNo, List<Integer> needOffShelveSkups, Map<Integer, SkupDto> tskupMap, int num) {
this.batchNo = batchNo;
this.needOffShelveSkups = needOffShelveSkups;
this.tskupMap = tskupMap;
this.num = num;
}
}
... ... @@ -55,6 +60,11 @@ public class SellerBatchCancelPrepareProcessor {
logger.warn("batch off shelve checkAndAcquire uid illegal , req {}", req);
throw new UfoServiceException(400, "参数[uid]错误");
}
int num = req.getStorageNum();
if (num <= 0){
logger.warn("batch off shelve checkAndAcquire num is illegal, req {}", req);
throw new UfoServiceException(400, "数量不合法");
}
if(!sellerOrderPrepareProcessor.checkIsEntry(uid)){
logger.warn("batch off shelve checkAndAcquire uid is not entry shop , req {}", req);
... ... @@ -69,13 +79,18 @@ public class SellerBatchCancelPrepareProcessor {
//考虑到并发,需要进行过滤,将不是出售中状态的skup排除掉;
//不做过滤导致后面的数量 扣费检查都可能不对
List<String> skupStrList = Splitter.on(',').trimResults().omitEmptyStrings().splitToList(skupList);
if (skupStrList.size() < num){
logger.warn("batch off shelve checkAndAcquire num bigger than skups , req {}", req);
throw new UfoServiceException(400, "数目大于实际商品数");
}
List<Integer> needOffShelveSkups = skupStrList.parallelStream().map(Integer::valueOf).collect(Collectors.toList());
//check batch no
Long batchNo = checkNAcquireBatchNo(req.getBatchNo(), req);
//检查
Map<Integer, SkupDto> skupMap = checkNeedProcessSkups(needOffShelveSkups,req);
DataNode node = new DataNode(batchNo, needOffShelveSkups, skupMap);
DataNode node = new DataNode(batchNo, needOffShelveSkups, skupMap, num);
return node;
}
... ...