...
|
...
|
@@ -16,16 +16,18 @@ import com.yohobuy.ufo.model.order.resp.PageResp; |
|
|
import com.yohobuy.ufo.model.order.resp.SellerGoodsPageResp;
|
|
|
import com.yohoufo.common.alarm.EventBusPublisher;
|
|
|
import com.yohoufo.common.alarm.SmsAlarmEvent;
|
|
|
import com.yohoufo.common.exception.UfoServiceException;
|
|
|
import com.yohoufo.common.lock.RedisLock;
|
|
|
import com.yohoufo.common.lock.RedisLockFactory;
|
|
|
import com.yohoufo.common.exception.UfoServiceException;
|
|
|
import com.yohoufo.dal.order.SellerOrderGoodsViewMapper;
|
|
|
import com.yohoufo.dal.order.model.SellerOrderGoods;
|
|
|
import com.yohoufo.dal.order.model.StorageDeposit;
|
|
|
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.DepositPublishResp;
|
|
|
import com.yohoufo.order.service.DepositService;
|
|
|
import com.yohoufo.order.service.deposit.StorageDepositSupport;
|
|
|
import com.yohoufo.order.service.handler.SellerOrderSubmitHandler;
|
|
|
import com.yohoufo.order.service.impl.SkupListService;
|
|
|
import com.yohoufo.order.service.proxy.ProductProxyService;
|
...
|
...
|
@@ -41,7 +43,7 @@ import org.springframework.stereotype.Service; |
|
|
import java.math.BigDecimal;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
import java.util.UUID;
|
|
|
import java.util.Map;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -85,6 +87,9 @@ public class QuickDeliverGoodsService { |
|
|
@Autowired
|
|
|
private RedisLockFactory redisLockFactory;
|
|
|
|
|
|
@Autowired
|
|
|
private StorageDepositSupport storageDepositSupport;
|
|
|
|
|
|
public DepositPublishResp publish(QuickDeliverOrderSubmitReq req) {
|
|
|
RedisKeyBuilder redisLockKey = RedisKeyBuilder.newInstance()
|
|
|
.appendFixed("ufo:order:lock:publishQuickDeliverGoods:")
|
...
|
...
|
@@ -94,7 +99,8 @@ public class QuickDeliverGoodsService { |
|
|
try {
|
|
|
QuickDeliverOrderContext qdoc = quickDeliverPublishProcessor.buildPublishCtx(req);
|
|
|
return doPublish(qdoc);
|
|
|
} finally {
|
|
|
}finally {
|
|
|
//redis unlock
|
|
|
lock.unlock();
|
|
|
}
|
|
|
} else {
|
...
|
...
|
@@ -111,7 +117,9 @@ public class QuickDeliverGoodsService { |
|
|
int successNum = 0;
|
|
|
//submit all as atomic operation, use transaction of DB
|
|
|
//all include : 1. skup, 2. order , 3. 寄回地址
|
|
|
for(String depositCode : context.getDepositCodes()) {
|
|
|
for(Map.Entry<String, StorageDeposit> codeSDEntry: context.getDepositCodeSDMap().entrySet()) {
|
|
|
String depositCode = codeSDEntry.getKey();
|
|
|
StorageDeposit sd = codeSDEntry.getValue();
|
|
|
// step 2: create order, set status(not pay)
|
|
|
// generate a new real code
|
|
|
long orderCode = orderCodeGenerator.generate(OrderCodeType.SELLER_TYPE);
|
...
|
...
|
@@ -129,23 +137,30 @@ public class QuickDeliverGoodsService { |
|
|
//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);
|
|
|
if(storageDepositSupport.lock(uid, depositCode, sd.getId())) {
|
|
|
orderSubmitHandler.submit(context);
|
|
|
SellerOrderGoods psog = context.getSellerOrderGoods();
|
|
|
skup = psog.getId();
|
|
|
//record deposit code 4 deposit prd -> quick deliver
|
|
|
sellerOrderMetaService.saveDepositCode(depositCode, uid, skup);
|
|
|
syncPrd(context, depositCode);
|
|
|
successNum++;
|
|
|
logger.info("in QuickDeliverGoodsService.publish finish main local persistent, uid {} storageId {} salePrice {} depositCode {} orderCode {}",
|
|
|
uid, storageId, salePrice,depositCode, orderCode);
|
|
|
}else{
|
|
|
logger.warn("storageDepositSupport do updateStorageShelveStatusByCAS fail , {}", sd);
|
|
|
}
|
|
|
} 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, ex);
|
|
|
throw new ServiceException(ServiceError.EARNESTMONEY_ORDER_CREATE_FAIL);
|
|
|
}finally {
|
|
|
//unlock
|
|
|
storageDepositSupport.unlock(uid, depositCode, sd.getId());
|
|
|
}
|
|
|
|
|
|
syncPrd(context, depositCode);
|
|
|
successNum++;
|
|
|
}
|
|
|
//在for循环中被用作值传递,部分数据会有变化,使用时需要注意动态变化的属性
|
|
|
GoodsInfo goodsInfo = context.getSoldProduct();
|
...
|
...
|
|