Authored by chenchao

adjust seller entry type by policy

package com.yohoufo.order.controller;
import com.yoho.core.rest.annotation.ServiceDesc;
import com.yohobuy.ufo.model.order.bo.SellerBo;
import com.yohobuy.ufo.model.order.req.SellerReq;
import com.yohoufo.common.annotation.IgnoreSession;
import com.yohoufo.common.annotation.IgnoreSignature;
import com.yohoufo.order.service.impl.SellerService;
import com.yohoufo.order.service.impl.SellerWrapper;
import com.yohoufo.order.utils.LoggerUtils;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -37,4 +39,16 @@ public class ErpSellerController {
}
return sellerService.checkIsNormalSuper(sellerReq.getUid());
}
@IgnoreSignature
@IgnoreSession
@RequestMapping("/getSellerWithAuth")
public SellerBo getSellerWithAuth(@RequestBody SellerReq sellerReq){
Integer uid;
if (sellerReq == null || (uid =sellerReq.getUid()) == null){
return null;
}
SellerWrapper sellerWrapper = sellerService.getFullDimensionSeller(uid);
return sellerWrapper.buildSellerBo();
}
}
... ...
... ... @@ -4,6 +4,7 @@ import com.yohobuy.ufo.model.order.bo.GoodsInfo;
import com.yohobuy.ufo.model.order.constants.SkupType;
import com.yohoufo.common.helper.ImageUrlAssist;
import com.yohoufo.dal.order.model.SellerOrderGoods;
import com.yohoufo.order.service.seller.support.SkupTypeCodeSupport;
import java.util.Optional;
... ... @@ -50,8 +51,9 @@ public class GoodsInfoConvertor {
sellerOrderGoods.setSizeName(goodsInfo.getSizeName());
sellerOrderGoods.setImageUrl(goodsInfo.getImageUrl());
sellerOrderGoods.setBatchNo(goodsInfo.getBatchNo());
SkupType skupType = Optional.ofNullable(goodsInfo.getSkupType()).orElse(SkupType.IN_STOCK);
//default is in-stock
sellerOrderGoods.setAttributes(Optional.ofNullable(goodsInfo.getSkupType()).orElse(SkupType.IN_STOCK).prdAttributes().getCode());
sellerOrderGoods.setAttributes(skupType.prdAttributes().getCode());
sellerOrderGoods.setRegion(goodsInfo.getRegion());
return sellerOrderGoods;
}
... ...
package com.yohoufo.order.event;
import com.yohobuy.ufo.model.order.bo.SellerBo;
import com.yohobuy.ufo.model.order.constants.SkupType;
import com.yohoufo.common.alarm.Event;
import com.yohoufo.dal.order.model.SellerWallet;
import com.yohoufo.order.service.handler.SellerOrderSubmitHandler;
import com.yohoufo.order.service.impl.SellerWrapper;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
... ... @@ -19,5 +22,6 @@ public class BatchPublishTailEvent extends Event {
private int sellerUid;
private SellerOrderSubmitHandler.ForkJoinResult fjr;
private SellerWallet sellerWallet;
private boolean isSuper;
private SellerBo sellerBo;
private SkupType skupType;
}
... ...
... ... @@ -2,6 +2,7 @@ package com.yohoufo.order.model.dto;
import com.yohobuy.ufo.model.order.vo.AddressInfo;
import com.yohoufo.dal.order.model.SellerWallet;
import com.yohoufo.order.service.impl.SellerWrapper;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
... ... @@ -18,7 +19,7 @@ import java.math.BigDecimal;
@NoArgsConstructor
public class ImPrdNode{
Integer uid;
boolean isSuper;
SellerWrapper sellerWrapper;
SellerWallet sellerWallet;
Integer storageId;
BigDecimal salePrice;
... ...
... ... @@ -2,13 +2,20 @@ package com.yohoufo.order.service.handler;
import com.google.common.eventbus.Subscribe;
import com.yohobuy.ufo.model.order.bo.OrderInfo;
import com.yohobuy.ufo.model.order.bo.SellerAssetPolicy;
import com.yohobuy.ufo.model.order.bo.SellerBo;
import com.yohobuy.ufo.model.order.common.Payment;
import com.yohobuy.ufo.model.order.constants.RegionEnum;
import com.yohobuy.ufo.model.order.constants.SkupType;
import com.yohoufo.common.alarm.EventBusPublisher;
import com.yohoufo.common.alarm.IEventHandler;
import com.yohoufo.dal.order.model.SellerWallet;
import com.yohoufo.order.event.BatchPublishTailEvent;
import com.yohoufo.order.event.SellerOrderPriceChangeEvent;
import com.yohoufo.order.service.MerchantOrderPaymentService;
import com.yohoufo.order.service.impl.SellerWrapper;
import com.yohoufo.order.service.proxy.ProductProxyService;
import com.yohoufo.order.service.seller.support.SkupTypeCodeSupport;
import com.yohoufo.order.utils.LoggerUtils;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -33,28 +40,36 @@ public class BatchPublishTailHandler implements IEventHandler<BatchPublishTailEv
@Subscribe
public void handle(BatchPublishTailEvent event) {
logger.info("in handle BatchPublishTailEvent event {}", event);
batchPublishTailProcess(event.getFjr(), event.getSellerWallet(), event.isSuper(), event.getSellerUid());
batchPublishTailProcess(event.getFjr(), event.getSellerWallet(),
event.getSellerBo(), event.getSellerUid(), event.getSkupType());
}
private void batchPublishTailProcess(SellerOrderSubmitHandler.ForkJoinResult fjr,
SellerWallet sellerWallet, boolean isSuper,
int sellerUid){
private void batchPublishTailProcess(SellerOrderSubmitHandler.ForkJoinResult fjr,
SellerWallet sellerWallet, SellerBo sellerBo,
int sellerUid, SkupType skupType){
SellerAssetPolicy sellerAssetPolicy = sellerBo.getSellerAssetPolicy();
SellerAssetPolicy.EarnestMoneyPolicy emp = sellerAssetPolicy.getEarnestMoneyPolicy();
// (异步实现)记录保证金流水
if(!isSuper) {
if(emp.getPayment().equals(Payment.WALLET) && !emp.isFree()) {
List<OrderInfo> orderList = fjr.getSellerOrderList().parallelStream().map(sellerOrder ->
OrderInfo.builder().orderCode(sellerOrder.getOrderCode())
.amount(sellerOrder.getEarnestMoney()).build()
).collect(Collectors.toList());
merchantOrderPaymentService.useEarnestAddWalletDetail(sellerWallet, orderList);
}
//(异步实现)同步数据到prd,记录支付,
productProxyService.batchCreateSkup(fjr.getSellerOrderGoodsList());
List<Integer> skups;
productProxyService.sellerBatchUpdateStatus(skups=fjr.getSkupIds(), ProductProxyService.PrdShelvelStatus.on);
//通知其他卖家价格
SellerOrderPriceChangeEvent sopcEvent = SellerOrderPriceChangeEvent.builder()
.sellerUid(sellerUid).skup(skups.get(0)).build();
EventBusPublisher.publishEvent(sopcEvent);
SkupTypeCodeSupport.CodeNode codeNode = SkupTypeCodeSupport.explain(skupType.getCode());
if (codeNode.getRegion() == RegionEnum.MAINLAND.getCode()) {
//通知其他卖家价格
SellerOrderPriceChangeEvent sopcEvent = SellerOrderPriceChangeEvent.builder()
.sellerUid(sellerUid).skup(skups.get(0)).build();
EventBusPublisher.publishEvent(sopcEvent);
}
}
}
... ...
... ... @@ -183,8 +183,6 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServic
break;
case FLAW:
case SECOND_HAND:
spc = SellerOrderConvertor.computeResult2SoldPrdComputeBo4Imperfect(computeResult, buildServiceFeeTips());
break;
}
... ... @@ -335,7 +333,7 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServic
forkNum = num - (i-1) * MAX_DEAL;
}
log.info("batch publish uid {} storageId {} forkNum {} num {}", uid, req.getStorageId(), forkNum, num);
BatchProcessTask batchProcessTask = new BatchProcessTask(ctx, cdl, forkNum, sellerWallet, isSuper);
BatchProcessTask batchProcessTask = new BatchProcessTask(ctx, cdl, forkNum, sellerWallet, sellerBo);
ForkJoinTask<SellerOrderSubmitHandler.ForkJoinResult> fjt = ThreadPoolFactory.getForkJoinPool().submit(batchProcessTask);
taskList.add(fjt);
}
... ... @@ -726,15 +724,15 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServic
private SellerWallet sellerWallet;
private boolean isSuper;
private SellerBo sellerBo;
public BatchProcessTask(SellerOrderContext ctx, CountDownLatch countDownLatch,
int num, SellerWallet sellerWallet, boolean isSuper) {
int num, SellerWallet sellerWallet, SellerBo sellerBo) {
this.ctx = ctx;
this.countDownLatch = countDownLatch;
this.num = num;
this.sellerWallet = sellerWallet;
this.isSuper = isSuper;
this.sellerBo = sellerBo;
}
@Override
... ... @@ -752,11 +750,9 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServic
//(异步实现)同步数据到prd,记录支付,
BatchPublishTailEvent bpte = BatchPublishTailEvent.builder()
.sellerUid(uid)
.isSuper(isSuper)
.sellerBo(sellerBo)
.fjr(fjr).sellerWallet(sellerWallet).build();
EventBusPublisher.publishEvent(bpte);
countDownLatch.countDown();
}catch (Exception ex){
countDownLatch.countDown();
log.warn("batch publish prd fork uid {} storageId {}", uid, storageId, ex);
... ... @@ -764,6 +760,8 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServic
SmsAlarmEvent smsAlarmEvent = new SmsAlarmEvent("entrySellerOrder.create", "create", content);
EventBusPublisher.publishEvent(smsAlarmEvent);
log.warn("batch publishPrd create order fail , uid {}, storageId {}", uid, storageId);
}finally {
countDownLatch.countDown();
}
log.info("{}.compute, countDownLatch count {} uid {} storageId {}",
getClass().getSimpleName(), countDownLatch.getCount(), uid, storageId);
... ...
... ... @@ -121,7 +121,8 @@ public class SellerService {
public SellerBo getSellerWithAuth(Integer uid){
logger.info("getSellerWithAuth uid {}", uid);
SellerWrapper sellerWrapper = getBaseSellerWrapper(uid);
SellerWrapper sellerWrapper = getBaseSellerWrapper(uid).attachAssetPolicy();
SellerLevelFuncBo slfb = sellerFuncService.getSellerLevelFunc(sellerWrapper);
SellerBo sellerBo = sellerWrapper.buildSellerBo();
sellerBo.setSellerLevelFunc(slfb);
... ... @@ -292,7 +293,8 @@ public class SellerService {
new SellerWrapper(uid,logger)
.addSpecialSuperFunc(this::isSpecialSuper)
.storedSellerDataSource(storedSellerMapper::selectByUid)
.buildSellerWrapper().attatchAssetPolicy();
.buildSellerWrapper().attachAssetPolicy()
.attachWallet(merchantOrderPaymentService::getWalletLeftAmount);
return sellerWrapper;
}
... ...
... ... @@ -126,7 +126,7 @@ public class SellerWrapper {
return this;
}
SellerWrapper attatchAssetPolicy(){
SellerWrapper attachAssetPolicy(){
if (sellerBo!=null){
SellerAssetPolicy sellerAssetPolicy = null;
if (sellerBo.isSuper()){
... ... @@ -171,6 +171,11 @@ public class SellerWrapper {
return this;
}
SellerWrapper attachWallet(Function<Integer, BigDecimal> getWalletByUidFunc){
BigDecimal left = getWalletByUidFunc.apply(this.uid);
this.leftInWallet = left;
return this;
}
public SellerBo buildSellerBo(){
... ...
... ... @@ -105,9 +105,10 @@ public class SkupService {
goodsInfo.setImageUrl(prdResp.getImageUrl());
goodsInfo.setPrice(salePrice);
goodsInfo.setStorageId(storageId);
goodsInfo.setSkupType(skupType);
SkupTypeCodeSupport.CodeNode codeNode = SkupTypeCodeSupport.explain(skupType.getCode());
goodsInfo.setRegion(codeNode.getRegion());
goodsInfo.setSkupType(skupType);
return goodsInfo;
}catch (Exception ex){
logger.warn("in getProductDetail occur error, uid {}, storageId {}", uid, storageId);
... ...
package com.yohoufo.order.service.seller;
import com.yohobuy.ufo.model.order.bo.SellerBo;
import com.yohobuy.ufo.model.order.req.BatchImportPrdReq;
import com.yohobuy.ufo.model.request.product.ProductImportTranItemBo;
import com.yohoufo.common.alarm.EventBusPublisher;
... ... @@ -8,6 +9,7 @@ import com.yohoufo.order.model.SellerOrderContext;
import com.yohoufo.order.model.dto.ImPrdNode;
import com.yohoufo.order.service.handler.SellerOrderSubmitHandler;
import com.yohoufo.order.service.impl.SellerService;
import com.yohoufo.order.service.impl.SellerWrapper;
import com.yohoufo.order.service.impl.SkupBatchService;
import com.yohoufo.order.service.proxy.ProductProxyService;
import com.yohoufo.order.service.seller.processor.ImportPublishProcessor;
... ... @@ -42,22 +44,29 @@ public class ImportPublishExcutor implements PublishExcutor<BatchImportPrdReq, S
@Autowired
private SellerService sellerService;
private boolean checkSellerEntryType(SellerBo sellerBo){
return sellerBo.isNormalSuper() || sellerBo.isLargeSettlementSuper();
}
@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);
SellerWrapper sellerWrapper = sellerService.getFullDimensionSeller(uid);
SellerBo sellerBo = sellerWrapper.buildSellerBo();
//check seller entry type
if (!checkSellerEntryType(sellerBo)){
logger.warn("in ImportPublishExcutor.publish not legal super, uid {} ", uid);
return null;
}
//TODO check left in wallet
for(ProductImportTranItemBo importPrd : importPrds){
Integer storageId = importPrd.getStorageId();
BigDecimal salePrice = importPrd.getPrice();
int storageNum = importPrd.getNum();
ImPrdNode node = ImPrdNode.builder().uid(uid)
.isSuper(isSuper)
.sellerWrapper(sellerWrapper)
.goodsPaymentRate(importPrd.getGoodsPaymentRate())
.storageId(storageId).salePrice(salePrice).storageNum(storageNum)
.noHiddenBackAddress(req.getNoHiddenBackAddress())
... ... @@ -96,10 +105,10 @@ public class ImportPublishExcutor implements PublishExcutor<BatchImportPrdReq, S
fjr = orderSubmitHandler.submitMultiple(ctx, storageNum);
// (异步实现)记录保证金流水
//(异步实现)同步数据到prd,记录支付,
boolean isSuper = node.isSuper();
SellerWrapper sellerWrapper = node.getSellerWrapper();
BatchPublishTailEvent bpte = BatchPublishTailEvent.builder()
.sellerUid(uid)
.isSuper(isSuper)
.sellerBo(sellerWrapper.buildSellerBo())
.fjr(fjr).sellerWallet(null).build();
EventBusPublisher.publishEvent(bpte);
return fjr;
... ...