|
|
package com.yohoufo.order.service.seller;
|
|
|
|
|
|
import com.yoho.error.ServiceError;
|
|
|
import com.yoho.error.exception.ServiceException;
|
|
|
import com.yohobuy.ufo.model.order.bo.MerchantOrderAttachInfo;
|
|
|
import com.yohobuy.ufo.model.order.req.BatchImportPrdReq;
|
|
|
import com.yohobuy.ufo.model.order.vo.AddressInfo;
|
|
|
import com.yohobuy.ufo.model.request.product.ProductImportTranItemBo;
|
|
|
import com.yohoufo.common.alarm.EventBusPublisher;
|
|
|
import com.yohoufo.dal.order.model.SellerWallet;
|
|
|
import com.yohoufo.dal.order.model.SellerWalletDetail;
|
|
|
import com.yohoufo.order.event.BatchPublishTailEvent;
|
|
|
import com.yohoufo.order.model.SellerOrderContext;
|
|
|
import com.yohoufo.order.model.dto.SellerOrderComputeResult;
|
|
|
import com.yohoufo.order.service.MerchantOrderPaymentService;
|
|
|
import com.yohoufo.order.service.handler.SellerOrderSubmitHandler;
|
|
|
import com.yohoufo.order.service.impl.SellerService;
|
|
|
import com.yohoufo.order.service.impl.SkupBatchService;
|
|
|
import com.yohoufo.order.service.impl.processor.SellerOrderPrepareProcessor;
|
|
|
import com.yohoufo.order.service.proxy.ProductProxyService;
|
|
|
import lombok.Data;
|
|
|
import lombok.experimental.Builder;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
...
|
...
|
@@ -21,7 +33,18 @@ import java.util.Objects; |
|
|
*/
|
|
|
@Service
|
|
|
public class ImportPublishExcutor implements PublishExcutor<BatchImportPrdReq, SellerOrderSubmitHandler.ForkJoinResult>{
|
|
|
|
|
|
@Builder
|
|
|
@Data
|
|
|
private static class ImPrdNode{
|
|
|
Integer uid;
|
|
|
boolean isSuper;
|
|
|
SellerWallet sellerWallet;
|
|
|
Integer storageId;
|
|
|
BigDecimal salePrice;
|
|
|
int storageNum;
|
|
|
AddressInfo hiddenBackAddress;
|
|
|
AddressInfo noHiddenBackAddress;
|
|
|
}
|
|
|
@Autowired
|
|
|
private SellerOrderSubmitHandler orderSubmitHandler;
|
|
|
|
...
|
...
|
@@ -34,20 +57,43 @@ public class ImportPublishExcutor implements PublishExcutor<BatchImportPrdReq, S |
|
|
@Autowired
|
|
|
private SkupBatchService skupBatchService;
|
|
|
|
|
|
@Autowired
|
|
|
private MerchantOrderPaymentService merchantOrderPaymentService;
|
|
|
|
|
|
@Autowired
|
|
|
private SellerService sellerService;
|
|
|
|
|
|
@Override
|
|
|
public SellerOrderSubmitHandler.ForkJoinResult publish(BatchImportPrdReq req) {
|
|
|
List<ProductImportTranItemBo> importPrds ;
|
|
|
if (CollectionUtils.isNotEmpty(importPrds = req.getProductList())){
|
|
|
Integer uid = importPrds.get(0).getUid();
|
|
|
boolean isSuper = sellerService.checkIsNormalSuper(uid);
|
|
|
if (!isSuper){
|
|
|
logger.warn("in ImportPublishExcutor.publish not super, uid {} ", uid);
|
|
|
return null;
|
|
|
}
|
|
|
for(ProductImportTranItemBo importPrd : importPrds){
|
|
|
Integer uid = importPrd.getUid();
|
|
|
Integer storageId = importPrd.getStorageId();
|
|
|
BigDecimal salePrice = importPrd.getPrice();
|
|
|
int storageNum = importPrd.getNum();
|
|
|
SellerOrderSubmitHandler.ForkJoinResult fjr = publishOne(uid, storageId, salePrice, storageNum,
|
|
|
req.getHiddenBackAddress(), req.getNoHiddenBackAddress());
|
|
|
int successNum = Objects.isNull(fjr) || Objects.isNull(fjr.getSkupIds()) ? 0 : fjr.getSkupIds().size();
|
|
|
ImPrdNode node = ImPrdNode.builder().uid(uid)
|
|
|
.isSuper(isSuper)
|
|
|
.storageId(storageId).salePrice(salePrice).storageNum(storageNum)
|
|
|
.noHiddenBackAddress(req.getNoHiddenBackAddress())
|
|
|
.hiddenBackAddress(req.getHiddenBackAddress()).build();
|
|
|
int successNum=0;
|
|
|
try{
|
|
|
SellerOrderSubmitHandler.ForkJoinResult fjr = publishOne(node);
|
|
|
successNum = Objects.isNull(fjr) || Objects.isNull(fjr.getSkupIds()) ? 0 : fjr.getSkupIds().size();
|
|
|
|
|
|
}catch(Exception ex){
|
|
|
logger.warn("in ImportPublishExcutor.publishOne orderSubmitHandler.submitMultiple fail, uid {} storageId {} salePrice {} storageNum {}",
|
|
|
uid, storageId, salePrice, storageNum);
|
|
|
}
|
|
|
importPrd.setSuccessdNum(successNum);
|
|
|
}
|
|
|
|
|
|
//修改批量计划表状态
|
|
|
productProxyService.batchAdd(importPrds);
|
|
|
}
|
...
|
...
|
@@ -56,25 +102,45 @@ public class ImportPublishExcutor implements PublishExcutor<BatchImportPrdReq, S |
|
|
|
|
|
|
|
|
|
|
|
public SellerOrderSubmitHandler.ForkJoinResult publishOne(Integer uid, Integer storageId,
|
|
|
BigDecimal salePrice, int storageNum,
|
|
|
AddressInfo hiddenBackAddress,
|
|
|
AddressInfo noHiddenBackAddress){
|
|
|
public SellerOrderSubmitHandler.ForkJoinResult publishOne(ImPrdNode node){
|
|
|
Integer uid = node.uid;
|
|
|
boolean isSuper = node.isSuper;
|
|
|
|
|
|
Integer storageId = node.storageId;
|
|
|
BigDecimal salePrice = node.salePrice;
|
|
|
int storageNum = node.storageNum;
|
|
|
AddressInfo hiddenBackAddress = node.hiddenBackAddress;
|
|
|
AddressInfo noHiddenBackAddress = node.noHiddenBackAddress;
|
|
|
SellerOrderContext ctx = sellerOrderPrepareProcessor.buildImportPrdCxt(uid, storageId, salePrice, storageNum);
|
|
|
ctx.setBackAddress(noHiddenBackAddress);
|
|
|
ctx.setBackHiddenAddress(hiddenBackAddress);
|
|
|
long batchNo = skupBatchService.generateBatchNo(uid, storageNum);
|
|
|
ctx.getSoldProduct().setBatchNo(batchNo);
|
|
|
SellerOrderSubmitHandler.ForkJoinResult fjr = null;
|
|
|
try {
|
|
|
fjr = orderSubmitHandler.submitMultiple(ctx, storageNum);
|
|
|
}catch (Exception ex){
|
|
|
logger.warn("in ImportPublishExcutor.publishOne orderSubmitHandler.submitMultiple fail, uid {} storageId {} salePrice {} storageNum {}",
|
|
|
uid, storageId, salePrice, storageNum);
|
|
|
}finally {
|
|
|
return fjr;
|
|
|
|
|
|
SellerOrderComputeResult socr = ctx.getSellerOrderComputeResult();
|
|
|
BigDecimal singleEarestMoney = socr.getEarnestMoney().getEarnestMoney();
|
|
|
BigDecimal mEarestMoney = sellerOrderPrepareProcessor.checkNGetMergeEarnestMoney(uid, singleEarestMoney,
|
|
|
storageNum, ctx.getSalePrice(), isSuper);
|
|
|
SellerWalletDetail.Type swdType = SellerWalletDetail.Type.PUBLISH;
|
|
|
MerchantOrderAttachInfo moai = MerchantOrderAttachInfo.builder().uid(uid)
|
|
|
.storageId(ctx.getStorageId()).earnestMoney(mEarestMoney)
|
|
|
.type(swdType.getValue()).build();
|
|
|
SellerWallet sellerWallet = merchantOrderPaymentService.useEarnest(uid, mEarestMoney, moai);
|
|
|
// invoke pay by wallet
|
|
|
boolean paySuccess = Objects.nonNull(sellerWallet);
|
|
|
if (!paySuccess){
|
|
|
logger.warn("batch publishOne pay fail, req {} mEarestMoney {}", node, mEarestMoney);
|
|
|
throw new ServiceException(ServiceError.WALLET_EARNESTMONEY_PAY_FAIL);
|
|
|
}
|
|
|
SellerOrderSubmitHandler.ForkJoinResult fjr = null;
|
|
|
|
|
|
fjr = orderSubmitHandler.submitMultiple(ctx, storageNum);
|
|
|
// (异步实现)记录保证金流水
|
|
|
//(异步实现)同步数据到prd,记录支付,
|
|
|
BatchPublishTailEvent bpte = BatchPublishTailEvent.builder().isSurper(isSuper)
|
|
|
.fjr(fjr).sellerWallet(sellerWallet).build();
|
|
|
EventBusPublisher.publishEvent(bpte);
|
|
|
return fjr;
|
|
|
}
|
|
|
|
|
|
|
...
|
...
|
|