...
|
...
|
@@ -2,9 +2,10 @@ package com.yohoufo.order.service.seller.quickDeliver; |
|
|
|
|
|
import com.yoho.error.ServiceError;
|
|
|
import com.yoho.error.exception.ServiceException;
|
|
|
import com.yohobuy.ufo.model.order.bo.GoodsInfo;
|
|
|
import com.yohobuy.ufo.model.order.bo.ProductInfo;
|
|
|
import com.yohobuy.ufo.model.order.common.*;
|
|
|
import com.yohobuy.ufo.model.order.common.OrderCodeType;
|
|
|
import com.yohobuy.ufo.model.order.common.SellerOrderListType;
|
|
|
import com.yohobuy.ufo.model.order.common.SkupStatus;
|
|
|
import com.yohobuy.ufo.model.order.constants.SkupType;
|
|
|
import com.yohobuy.ufo.model.order.req.QuickDeliverOrderSubmitReq;
|
|
|
import com.yohobuy.ufo.model.order.resp.OrderListInfo;
|
...
|
...
|
@@ -17,7 +18,8 @@ import com.yohoufo.dal.order.model.SellerOrderGoods; |
|
|
import com.yohoufo.order.model.QuickDeliverOrderContext;
|
|
|
import com.yohoufo.order.model.request.OrderListRequest;
|
|
|
import com.yohoufo.order.model.request.SellerGoodsListRequest;
|
|
|
import com.yohoufo.order.model.response.OrderSubmitResp;
|
|
|
import com.yohoufo.order.model.response.DepositPublishResp;
|
|
|
import com.yohoufo.order.service.DepositService;
|
|
|
import com.yohoufo.order.service.handler.SellerOrderSubmitHandler;
|
|
|
import com.yohoufo.order.service.impl.SkupListService;
|
|
|
import com.yohoufo.order.service.proxy.ProductProxyService;
|
...
|
...
|
@@ -66,77 +68,88 @@ public class QuickDeliverGoodsService { |
|
|
@Autowired
|
|
|
private SkupListService skupListService;
|
|
|
|
|
|
public OrderSubmitResp publish(QuickDeliverOrderSubmitReq req){
|
|
|
@Autowired
|
|
|
private DepositService depositService;
|
|
|
|
|
|
public DepositPublishResp publish(QuickDeliverOrderSubmitReq req){
|
|
|
|
|
|
QuickDeliverOrderContext qdoc = quickDeliverPublishProcessor.buildPublishCtx(req);
|
|
|
return doPublish(qdoc);
|
|
|
}
|
|
|
|
|
|
|
|
|
private OrderSubmitResp doPublish(QuickDeliverOrderContext context){
|
|
|
final String depositCode = context.getDepositCode();
|
|
|
private DepositPublishResp doPublish(QuickDeliverOrderContext context){
|
|
|
int storageId = context.getStorageId();
|
|
|
int uid = context.getUid();
|
|
|
BigDecimal salePrice = context.getSalePrice();
|
|
|
// step 2: create order, set status(not pay)
|
|
|
// generate a new real code
|
|
|
long orderCode = orderCodeGenerator.generate(OrderCodeType.SELLER_TYPE);
|
|
|
if (orderCode <= 0L){
|
|
|
logger.warn("in publish quick deliver Prd generate fail , uid {},depositCode {} storageId {} salePrice {}",
|
|
|
uid, depositCode, storageId, salePrice);
|
|
|
throw new ServiceException(ServiceError.EARNESTMONEY_ORDER_CREATE_FAIL);
|
|
|
}
|
|
|
//允许入驻商家后,对于个体户而言,也需要批次号(1:1这种,直接使用订单号,若以后有变化 用skup_batch表自增)
|
|
|
context.getSoldProduct().setBatchNo(orderCode);
|
|
|
context.setOrderCode(orderCode);
|
|
|
|
|
|
//submit all as atomic operation, use transaction of DB
|
|
|
//all include : 1. skup, 2. order , 3. 寄回地址
|
|
|
int skup ;
|
|
|
try{
|
|
|
orderSubmitHandler.submit(context);
|
|
|
SellerOrderGoods psog = context.getSellerOrderGoods();
|
|
|
skup = psog.getId();
|
|
|
//record deposit code 4 deposit prd -> quick deliver
|
|
|
sellerOrderMetaService.saveDepositCode(context.getDepositCode(), uid, skup);
|
|
|
logger.info("in QuickDeliverGoodsService.publish finish main local persistent, uid {} storageId {} salePrice {} orderCode {}",
|
|
|
uid, storageId, salePrice, orderCode);
|
|
|
}catch (Exception ex){
|
|
|
String content = "用户"+ uid + "发布闪购商品"+depositCode + "失败";
|
|
|
SmsAlarmEvent smsAlarmEvent = new SmsAlarmEvent("sellerOrder.create", "create", content);
|
|
|
EventBusPublisher.publishEvent(smsAlarmEvent);
|
|
|
logger.warn("in publish quick deliver Prd create order fail , uid {}, depositCode {}", uid, depositCode);
|
|
|
throw new ServiceException(ServiceError.EARNESTMONEY_ORDER_CREATE_FAIL);
|
|
|
for(String depositCode : context.getDepositCodes()) {
|
|
|
// step 2: create order, set status(not pay)
|
|
|
// generate a new real code
|
|
|
long orderCode = orderCodeGenerator.generate(OrderCodeType.SELLER_TYPE);
|
|
|
if (orderCode <= 0L){
|
|
|
logger.warn("in publish quick deliver Prd generate fail , uid {},depositCode {} storageId {} salePrice {}",
|
|
|
uid, depositCode, storageId, salePrice);
|
|
|
throw new ServiceException(ServiceError.EARNESTMONEY_ORDER_CREATE_FAIL);
|
|
|
}
|
|
|
//允许入驻商家后,对于个体户而言,也需要批次号(1:1这种,直接使用订单号,若以后有变化 用skup_batch表自增)
|
|
|
context.getSoldProduct().setBatchNo(orderCode);
|
|
|
context.setOrderCode(orderCode);
|
|
|
//fetch matched address
|
|
|
context.setBackAddress(context.getNoHiddenBackAddressMap().get(depositCode));
|
|
|
context.setBackHiddenAddress(context.getHiddenBackAddressMap().get(depositCode));
|
|
|
//do submit
|
|
|
int skup;
|
|
|
try {
|
|
|
orderSubmitHandler.submit(context);
|
|
|
SellerOrderGoods psog = context.getSellerOrderGoods();
|
|
|
skup = psog.getId();
|
|
|
//record deposit code 4 deposit prd -> quick deliver
|
|
|
sellerOrderMetaService.saveDepositCode(depositCode, uid, skup);
|
|
|
logger.info("in QuickDeliverGoodsService.publish finish main local persistent, uid {} storageId {} salePrice {} orderCode {}",
|
|
|
uid, storageId, salePrice, orderCode);
|
|
|
} catch (Exception ex) {
|
|
|
String content = "用户" + uid + "发布闪购商品" + depositCode + "失败";
|
|
|
SmsAlarmEvent smsAlarmEvent = new SmsAlarmEvent("sellerOrder.create", "create", content);
|
|
|
EventBusPublisher.publishEvent(smsAlarmEvent);
|
|
|
logger.warn("in publish quick deliver Prd create order fail , uid {}, depositCode {}", uid, depositCode);
|
|
|
throw new ServiceException(ServiceError.EARNESTMONEY_ORDER_CREATE_FAIL);
|
|
|
}
|
|
|
|
|
|
syncPrd(context, depositCode);
|
|
|
|
|
|
}
|
|
|
|
|
|
syncPrd(context);
|
|
|
GoodsInfo goodsInfo = context.getSoldProduct();
|
|
|
OrderSubmitResp resp = OrderSubmitResp.builder()
|
|
|
.orderCode(orderCode)
|
|
|
.skup(skup)
|
|
|
.productId(goodsInfo.getProductId()).build();
|
|
|
DepositPublishResp resp = DepositPublishResp.builder()
|
|
|
.build();
|
|
|
return resp;
|
|
|
}
|
|
|
|
|
|
private void syncPrd(QuickDeliverOrderContext context){
|
|
|
long orderCode = context.getOrderCode();
|
|
|
/**
|
|
|
* TODO in the further, we try 2 keep BASE
|
|
|
* @param context
|
|
|
* @param depositCode
|
|
|
*/
|
|
|
private void syncPrd(QuickDeliverOrderContext context, String depositCode){
|
|
|
int uid = context.getUid();
|
|
|
SellerOrderGoods psog = context.getSellerOrderGoods();
|
|
|
int skup = psog.getId();
|
|
|
|
|
|
//TODO
|
|
|
SkupType skupType = context.getSkupType();
|
|
|
switch (skupType){
|
|
|
case IN_STOCK:
|
|
|
//TODO 上架成功,需要仓储管理 修改寄存状态
|
|
|
break;
|
|
|
case QUICK_DELIVER:
|
|
|
//TODO 闪购商品 物权转移
|
|
|
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
try{
|
|
|
boolean syncPrdFlag = productProxyService.syncFullSkup(psog=context.getSellerOrderGoods(), SkupStatus.CAN_SELL);
|
|
|
logger.info("publish quick deliver Prd finish, createGoods {}, skup {}, orderCode {}",
|
|
|
syncPrdFlag, skup, orderCode);
|
|
|
logger.info("publish quick deliver Prd finish, createGoods {}, skup {}, depositCode {}",
|
|
|
syncPrdFlag, skup, depositCode);
|
|
|
}catch (Exception ex){
|
|
|
logger.warn("in publish quick deliver prd, sync full skup fail, uid {} depositCode {} skup {}",
|
|
|
uid, depositCode, skup, ex);
|
|
|
}
|
|
|
try {
|
|
|
depositService.changeSaleStatusOn(uid, depositCode, skup);
|
|
|
}catch (Exception ex){
|
|
|
logger.warn("in publish quick deliver prd , change deposit storage fail, uid {} depositCode {} skup {}",
|
|
|
uid, depositCode, skup, ex);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
...
|
...
|
|