...
|
...
|
@@ -22,9 +22,11 @@ import com.yohoufo.dal.order.SellerOrderMapper; |
|
|
import com.yohoufo.dal.order.model.BuyerOrder;
|
|
|
import com.yohoufo.dal.order.model.SellerOrder;
|
|
|
import com.yohoufo.dal.order.model.SellerOrderGoods;
|
|
|
import com.yohoufo.dal.order.model.SellerWallet;
|
|
|
import com.yohoufo.order.common.ActionStatusHold;
|
|
|
import com.yohoufo.order.common.DelStatus;
|
|
|
import com.yohoufo.order.convert.SellerOrderConvertor;
|
|
|
import com.yohoufo.order.event.BatchPublishTailEvent;
|
|
|
import com.yohoufo.order.event.ErpCancelSellerOrderEvent;
|
|
|
import com.yohoufo.order.event.EventHandlerContainer;
|
|
|
import com.yohoufo.order.event.OrderCancelEvent;
|
...
|
...
|
@@ -37,6 +39,7 @@ import com.yohoufo.order.model.response.OrderSubmitResp; |
|
|
import com.yohoufo.order.model.response.OrderSummaryResp;
|
|
|
import com.yohoufo.order.service.IOrderDetailService;
|
|
|
import com.yohoufo.order.service.IOrderListService;
|
|
|
import com.yohoufo.order.service.MerchantOrderPaymentService;
|
|
|
import com.yohoufo.order.service.cache.CacheCleaner;
|
|
|
import com.yohoufo.order.service.cache.OrderCacheService;
|
|
|
import com.yohoufo.order.service.concurrent.ThreadPoolFactory;
|
...
|
...
|
@@ -48,25 +51,30 @@ import com.yohoufo.order.service.impl.visitor.UserCancelCase; |
|
|
import com.yohoufo.order.service.proxy.ProductProxyService;
|
|
|
import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator;
|
|
|
import com.yohoufo.order.service.support.codegenerator.bean.CodeMeta;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
import java.util.concurrent.*;
|
|
|
import java.util.concurrent.Callable;
|
|
|
import java.util.concurrent.CountDownLatch;
|
|
|
import java.util.concurrent.ForkJoinTask;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* Created by chenchao on 2018/9/13.
|
|
|
*/
|
|
|
@Service
|
|
|
@Slf4j
|
|
|
public class SellerOrderService implements IOrderListService, IOrderDetailService {
|
|
|
|
|
|
private final Logger log = LoggerFactory.getLogger(getClass());
|
|
|
|
|
|
@Autowired
|
|
|
private SellerOrderMapper sellerOrderMapper;
|
|
|
|
...
|
...
|
@@ -109,6 +117,12 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi |
|
|
@Autowired
|
|
|
private SellerOrderPrepareProcessor sellerOrderPrepareProcessor;
|
|
|
|
|
|
@Autowired
|
|
|
private SkupBatchService skupBatchService;
|
|
|
|
|
|
@Autowired
|
|
|
private MerchantOrderPaymentService merchantOrderPaymentService;
|
|
|
|
|
|
|
|
|
public SoldPrdComputeBo computePublishPrd(SellerOrderComputeReq req) throws GatewayException {
|
|
|
log.info("in computePublishPrd, req {}", req);
|
...
|
...
|
@@ -220,63 +234,39 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi |
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 卖家支付完成后调用
|
|
|
* @param uid
|
|
|
* @param orderCode
|
|
|
*/
|
|
|
public void processAfterPay(int uid, long orderCode){
|
|
|
//todo update order info, set payment status
|
|
|
//todo update skup status
|
|
|
//todo sync skup to prd service by rpc
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 发货
|
|
|
* @param buyerOrderCode
|
|
|
* @param expressNum
|
|
|
*/
|
|
|
public void deliverGoods(int uid, long buyerOrderCode,String expressNum){
|
|
|
//
|
|
|
|
|
|
}
|
|
|
|
|
|
@Autowired
|
|
|
private SkupBatchService skupBatchService;
|
|
|
|
|
|
public OrderSubmitResp batchPublishPrds(SellerOrderContext ctx, SellerOrderSubmitReq req) throws GatewayException {
|
|
|
// 一串校验
|
|
|
//TODO 扣减保证金
|
|
|
//扣减保证金
|
|
|
final int num = req.getNum();
|
|
|
int uid = req.getUid();
|
|
|
SellerOrderComputeResult socr = ctx.getSellerOrderComputeResult();
|
|
|
BigDecimal singleEarestMoney = socr.getEarnestMoney().getEarnestMoney();
|
|
|
BigDecimal mEarestMoney = BigDecimalHelper.halfUp(new BigDecimal(num).multiply(singleEarestMoney));
|
|
|
boolean paySuccess = false;//TODO invoke pay by wallet
|
|
|
SellerWallet sellerWallet = merchantOrderPaymentService.useEarnest(uid, mEarestMoney);
|
|
|
// invoke pay by wallet
|
|
|
boolean paySuccess = Objects.nonNull(sellerWallet);
|
|
|
if (!paySuccess){
|
|
|
log.warn("batchPublishPrds pay fail, req {} mEarestMoney {}", req, mEarestMoney);
|
|
|
throw new ServiceException(ServiceError.WALLET_EARNESTMONEY_PAY_FAIL);
|
|
|
}
|
|
|
//TODO (异步实现)记录保证金流水
|
|
|
//TODO 生成批次号
|
|
|
|
|
|
// 生成批次号
|
|
|
long batchNo = skupBatchService.generateBatchNo(req.getUid(), req.getNum());
|
|
|
ctx.getSoldProduct().setBatchNo(batchNo);
|
|
|
int times = PageHelper.getPageTotal(num, MAX_DEAL);
|
|
|
CountDownLatch cdl = new CountDownLatch(times);
|
|
|
//TODO 批量生成订单(订单表,meta 地址,算费)--> 需要用到多线程并行处理
|
|
|
//TODO(异步实现)同步数据到prd,记录支付,
|
|
|
//批量生成订单(订单表,meta 地址,算费)--> 需要用到多线程并行处理
|
|
|
List<ForkJoinTask<SellerOrderSubmitHandler.ForkJoinResult>> taskList = new ArrayList<>(times);
|
|
|
for(int i = 1; i <= times; i++){
|
|
|
int forkNum = MAX_DEAL;
|
|
|
if (times == i){
|
|
|
forkNum = num - (i-1) * MAX_DEAL;
|
|
|
}
|
|
|
BatchProcessTask batchProcessTask = new BatchProcessTask(ctx, cdl, forkNum);
|
|
|
log.info("batch publish uid {} storageId {} forkNum {} num {}", uid, req.getStorageId(), forkNum, num);
|
|
|
BatchProcessTask batchProcessTask = new BatchProcessTask(ctx, cdl, forkNum, sellerWallet);
|
|
|
ForkJoinTask<SellerOrderSubmitHandler.ForkJoinResult> fjt = ThreadPoolFactory.getForkJoinPool().submit(batchProcessTask);
|
|
|
fjt.fork();
|
|
|
SellerOrderSubmitHandler.ForkJoinResult fjr = fjt.join();
|
|
|
log.info("in batch publish prd, ForkJoinResult {} " ,fjr);
|
|
|
taskList.add(fjt);
|
|
|
}
|
|
|
|
|
|
|
|
|
return OrderSubmitResp.builder().build();
|
|
|
}
|
|
|
|
...
|
...
|
@@ -292,6 +282,11 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi |
|
|
return true;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* todo
|
|
|
* @param req
|
|
|
* @return
|
|
|
*/
|
|
|
public boolean batchCancel(SellerOrderBatchCancelReq req){
|
|
|
|
|
|
|
...
|
...
|
@@ -391,20 +386,6 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi |
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查物流详情
|
|
|
* 只查卖家自己填的物流单
|
|
|
* @param uid
|
|
|
* @param buyerOrderCode
|
|
|
* @param expressNum
|
|
|
* @return
|
|
|
*/
|
|
|
public Object queryLogistics(int uid, long buyerOrderCode, String expressNum){
|
|
|
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
|
|
|
private SoldPrdComputeBo buildSoldPrdComputeBo(int uid, int num, BigDecimal prdPrice){
|
|
|
SellerOrderComputeResult computeResult = computeHandler.compute(prdPrice);
|
|
|
/**
|
...
|
...
|
@@ -476,7 +457,11 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi |
|
|
.actor(orderRequest.getTabType()).build();
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* todo
|
|
|
* @param req
|
|
|
* @return
|
|
|
*/
|
|
|
public BatchChangePriceResp batchChangePrice(BatchChangePriceReq req){
|
|
|
BatchChangePriceResp resp = BatchChangePriceResp.builder().successCnt(1).failCnt(1)
|
|
|
.tips("变价成功1个,失败1个").build();
|
...
|
...
|
@@ -485,8 +470,10 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi |
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static final int MAX_DEAL = 10;
|
|
|
|
|
|
|
|
|
private class BatchProcessTask implements Callable<SellerOrderSubmitHandler.ForkJoinResult>{
|
|
|
|
|
|
private SellerOrderContext ctx;
|
...
|
...
|
@@ -495,23 +482,29 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi |
|
|
|
|
|
private int num;
|
|
|
|
|
|
public BatchProcessTask(SellerOrderContext ctx, CountDownLatch countDownLatch, int num) {
|
|
|
private SellerWallet sellerWallet;
|
|
|
|
|
|
public BatchProcessTask(SellerOrderContext ctx, CountDownLatch countDownLatch, int num, SellerWallet sellerWallet) {
|
|
|
this.ctx = ctx;
|
|
|
this.countDownLatch = countDownLatch;
|
|
|
this.num = num;
|
|
|
this.sellerWallet = sellerWallet;
|
|
|
}
|
|
|
|
|
|
|
|
|
@Override
|
|
|
public SellerOrderSubmitHandler.ForkJoinResult call() throws Exception {
|
|
|
int uid = ctx.getUid();
|
|
|
int storageId = ctx.getStorageId();
|
|
|
log.info("{}.compute, countDownLatch count {} uid {} storageId {}",
|
|
|
getClass().getSimpleName(),countDownLatch.getCount(), uid, storageId);
|
|
|
//TODO 批量生成订单(订单表,meta 地址,算费)--> 需要用到多线程并行处理
|
|
|
//TODO(异步实现)同步数据到prd,记录支付,
|
|
|
// 批量生成订单(订单表,meta 地址,算费)--> 需要用到多线程并行处理
|
|
|
SellerOrderSubmitHandler.ForkJoinResult fjr = null;
|
|
|
try {
|
|
|
orderSubmitHandler.submitMultiple(ctx, num);
|
|
|
fjr = orderSubmitHandler.submitMultiple(ctx, num);
|
|
|
// (异步实现)记录保证金流水
|
|
|
//(异步实现)同步数据到prd,记录支付,
|
|
|
BatchPublishTailEvent bpte = BatchPublishTailEvent.builder().fjr(fjr).sellerWallet(sellerWallet).build();
|
|
|
EventBusPublisher.publishEvent(bpte);
|
|
|
countDownLatch.countDown();
|
|
|
}catch (Exception ex){
|
|
|
countDownLatch.countDown();
|
...
|
...
|
@@ -519,7 +512,7 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi |
|
|
}
|
|
|
log.info("{}.compute, countDownLatch count {} uid {} storageId {}",
|
|
|
getClass().getSimpleName(), countDownLatch.getCount(), uid, storageId);
|
|
|
return null;
|
|
|
return fjr;
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
|