|
|
package com.yohoufo.order.service.impl.processor;
|
|
|
package com.yohoufo.order.service.seller.processor;
|
|
|
|
|
|
import com.yoho.error.ServiceError;
|
|
|
import com.yoho.error.exception.ServiceException;
|
...
|
...
|
@@ -19,6 +19,7 @@ import com.yohoufo.order.service.proxy.ProductProxyService; |
|
|
import com.yohoufo.order.service.proxy.UserProxyService;
|
|
|
import com.yohoufo.order.service.seller.OrderComputeHandler;
|
|
|
import com.yohoufo.order.service.seller.OrderComputeProvider;
|
|
|
import com.yohoufo.order.service.seller.PublishPrepareProcessor;
|
|
|
import com.yohoufo.order.utils.AddressHelper;
|
|
|
import com.yohoufo.order.utils.LoggerUtils;
|
|
|
import com.yohoufo.order.utils.OrderAssist;
|
...
|
...
|
@@ -33,23 +34,21 @@ import java.util.Objects; |
|
|
* Created by chao.chen on 2018/11/19.
|
|
|
*/
|
|
|
@Service
|
|
|
public class SellerOrderPrepareProcessor {
|
|
|
public class SellerOrderPrepareProcessor extends AbsPublishPrepareProcessor<SellerOrderSubmitReq, SellerOrderContext>
|
|
|
implements PublishPrepareProcessor<SellerOrderSubmitReq, SellerOrderContext> {
|
|
|
|
|
|
private final Logger log = LoggerUtils.getSellerOrderLogger();
|
|
|
|
|
|
@Autowired
|
|
|
private UserProxyService userProxyService;
|
|
|
|
|
|
@Autowired
|
|
|
private ProductProxyService productProxyService;
|
|
|
|
|
|
@Autowired
|
|
|
private OrderComputeProvider orderComputeProvider;
|
|
|
//@Autowired
|
|
|
//private OrderComputeProvider orderComputeProvider;
|
|
|
|
|
|
@Autowired
|
|
|
private PriceComputePrepareProcessor priceComputePrepareProcessor;
|
|
|
//@Autowired
|
|
|
//private PriceComputePrepareProcessor priceComputePrepareProcessor;
|
|
|
|
|
|
public SellerOrderContext buildPublishPrdCtx(SellerOrderSubmitReq req) throws GatewayException {
|
|
|
public SellerOrderContext buildPublishPrdCtx(SellerOrderSubmitReq req) {
|
|
|
SellerOrderContext ctx = buildSellerOrderContext(req);
|
|
|
int uid = ctx.getUid();
|
|
|
boolean isEntryShop = userProxyService.isEntryShop(uid);
|
...
|
...
|
@@ -60,7 +59,7 @@ public class SellerOrderPrepareProcessor { |
|
|
return ctx;
|
|
|
}
|
|
|
|
|
|
public void buildBatchSellerOrderContext(SellerOrderSubmitReq req, SellerOrderContext ctx) throws GatewayException {
|
|
|
private void buildBatchSellerOrderContext(SellerOrderSubmitReq req, SellerOrderContext ctx) {
|
|
|
int storageId = ctx.getStorageId();
|
|
|
int uid = ctx.getUid();
|
|
|
int storageNum = req.getNum();
|
...
|
...
|
@@ -80,7 +79,7 @@ public class SellerOrderPrepareProcessor { |
|
|
}
|
|
|
|
|
|
|
|
|
public SellerOrderContext buildSellerOrderContext(SellerOrderSubmitReq req) {
|
|
|
private SellerOrderContext buildSellerOrderContext(SellerOrderSubmitReq req) {
|
|
|
int uid = req.getUid();
|
|
|
if (uid <= 0){
|
|
|
log.warn("uid illegal , uid {}", uid);
|
...
|
...
|
@@ -152,102 +151,21 @@ public class SellerOrderPrepareProcessor { |
|
|
return context;
|
|
|
}
|
|
|
|
|
|
public GoodsInfo getProductDetail(SellerOrderContext context){
|
|
|
int uid = context.getUid();
|
|
|
int storageId = context.getStorageId();
|
|
|
BigDecimal salePrice = context.getSalePrice();
|
|
|
try {
|
|
|
StorageDataResp prdResp = productProxyService.getStorageData(storageId);
|
|
|
if (!Integer.valueOf(1).equals(prdResp.getStatus())) {
|
|
|
log.info("in getProductDetail occur product out shelve, uid {}, storageId {}", uid, storageId);
|
|
|
return null;
|
|
|
}
|
|
|
GoodsInfo goodsInfo = new GoodsInfo();
|
|
|
goodsInfo.setUid(uid);
|
|
|
goodsInfo.setProductId(prdResp.getProductId());
|
|
|
goodsInfo.setProductName(prdResp.getProductName());
|
|
|
goodsInfo.setColorId(Objects.isNull(prdResp.getColorId()) ? null : Integer.valueOf(prdResp.getColorId()));
|
|
|
goodsInfo.setColorName(prdResp.getColorName());
|
|
|
GoodsSize size;
|
|
|
if (Objects.nonNull(size = prdResp.getSize())){
|
|
|
goodsInfo.setSizeName(size.getSizeName());
|
|
|
goodsInfo.setSizeId(size.getSizeId());
|
|
|
}
|
|
|
goodsInfo.setImageUrl(prdResp.getImageUrl());
|
|
|
goodsInfo.setPrice(salePrice);
|
|
|
goodsInfo.setStorageId(context.getStorageId());
|
|
|
goodsInfo.setSkupType(context.getSkupType());
|
|
|
return goodsInfo;
|
|
|
}catch (Exception ex){
|
|
|
log.warn("in getProductDetail occur error, uid {}, storageId {}", uid, storageId);
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
public boolean checkIsEntry(int uid){
|
|
|
return userProxyService.isEntryShop(uid);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 批量导入时 构建单个skup使用
|
|
|
* @param uid
|
|
|
* @param storageId
|
|
|
* @param salePrice
|
|
|
* @param storageNum
|
|
|
* @return
|
|
|
*/
|
|
|
public SellerOrderContext buildImportPrdCxt(Integer uid, Integer storageId, BigDecimal salePrice, int storageNum,
|
|
|
BigDecimal goodsPaymentRate){
|
|
|
if (uid <= 0){
|
|
|
log.warn("buildImportPrdCxt uid illegal , uid {}", uid);
|
|
|
throw new UfoServiceException(400, "Uid 错误");
|
|
|
}
|
|
|
if (storageId <=0 ){
|
|
|
log.warn("buildImportPrdCxt storageId illegal , uid {}", uid);
|
|
|
throw new UfoServiceException(400, "storageId 错误");
|
|
|
}
|
|
|
|
|
|
//
|
|
|
SellerOrderContext context = new SellerOrderContext();
|
|
|
context.setUid(uid);
|
|
|
context.setStorageId(storageId);
|
|
|
context.setSalePrice(salePrice);
|
|
|
SkupType skupType = SkupType.IN_STOCK;
|
|
|
context.setSkupType(skupType);
|
|
|
//TODO set noHiddenBackAddress & hiddenBackAddress
|
|
|
//context.setBackAddress(noHiddenBackAddress);
|
|
|
//context.setBackHiddenAddress(hiddenBackAddress);
|
|
|
//step 1: rpc get product detail by storage id
|
|
|
//ufo.product.storage.data
|
|
|
GoodsInfo goodsInfo = getProductDetail(context);
|
|
|
//step 2: generate skup ,action :set price status(unsaleable)
|
|
|
if (Objects.isNull(goodsInfo)){
|
|
|
log.warn("in buildImportPrdCxt storageId not exist in prd service , uid {}, storageId {}", uid, storageId);
|
|
|
throw new ServiceException(ServiceError.ORDER_ORDERS_GOODS_IS_EMPTY);
|
|
|
}
|
|
|
context.setSoldProduct(goodsInfo);
|
|
|
if (storageNum <=0){
|
|
|
log.warn("in buildBatchSellerOrderContext storageNum illegal , uid {}, storageId {} storageNum {}",
|
|
|
uid, storageId, storageNum);
|
|
|
throw new ServiceException(ServiceError.SELLER_PUBLISH_PRD_NUM_ILLEGAL);
|
|
|
}
|
|
|
//step 1: rpc get product detail by storage id
|
|
|
//ufo.product.storage.data
|
|
|
goodsInfo.setStorageNum(storageNum);
|
|
|
|
|
|
// compute every fee from price
|
|
|
PrdPrice prdPrice = new PrdPrice();
|
|
|
prdPrice.setCanPublish(true);
|
|
|
prdPrice.setGoodsPaymentRate(goodsPaymentRate);
|
|
|
SellerOrderComputeResult pcc = OrderAssist.buildPersonalComputeConfig(prdPrice);
|
|
|
OrderComputeHandler computeHandler = orderComputeProvider.findBySkupType(skupType);
|
|
|
SellerOrderComputeResult computeResult = computeHandler.compute(goodsInfo.getPrice(), pcc);
|
|
|
log.info("in buildImportPrdCxt , uid {}, storageId {}, price {}, computeResult {}", uid, storageId,
|
|
|
goodsInfo.getPrice(), computeResult);
|
|
|
context.setSellerOrderComputeResult(computeResult);
|
|
|
return context;
|
|
|
@Override
|
|
|
public SellerOrderContext buildPublishCtx(SellerOrderSubmitReq req) {
|
|
|
return buildPublishPrdCtx(req);
|
|
|
}
|
|
|
|
|
|
|
|
|
@Override
|
|
|
protected Logger getLogger() {
|
|
|
return this.log;
|
|
|
}
|
|
|
} |
...
|
...
|
|