1
|
package com.yohoufo.order.service.seller.quickDeliver;
|
1
|
package com.yohoufo.order.service.seller.quickDeliver;
|
2
|
|
2
|
|
|
|
3
|
+import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
|
3
|
import com.yoho.error.ServiceError;
|
4
|
import com.yoho.error.ServiceError;
|
4
|
import com.yoho.error.exception.ServiceException;
|
5
|
import com.yoho.error.exception.ServiceException;
|
5
|
import com.yohobuy.ufo.model.order.bo.GoodsInfo;
|
6
|
import com.yohobuy.ufo.model.order.bo.GoodsInfo;
|
|
@@ -15,6 +16,8 @@ import com.yohobuy.ufo.model.order.resp.PageResp; |
|
@@ -15,6 +16,8 @@ import com.yohobuy.ufo.model.order.resp.PageResp; |
15
|
import com.yohobuy.ufo.model.order.resp.SellerGoodsPageResp;
|
16
|
import com.yohobuy.ufo.model.order.resp.SellerGoodsPageResp;
|
16
|
import com.yohoufo.common.alarm.EventBusPublisher;
|
17
|
import com.yohoufo.common.alarm.EventBusPublisher;
|
17
|
import com.yohoufo.common.alarm.SmsAlarmEvent;
|
18
|
import com.yohoufo.common.alarm.SmsAlarmEvent;
|
|
|
19
|
+import com.yohoufo.common.cache.RedisLock;
|
|
|
20
|
+import com.yohoufo.common.exception.UfoServiceException;
|
18
|
import com.yohoufo.dal.order.SellerOrderGoodsViewMapper;
|
21
|
import com.yohoufo.dal.order.SellerOrderGoodsViewMapper;
|
19
|
import com.yohoufo.dal.order.model.SellerOrderGoods;
|
22
|
import com.yohoufo.dal.order.model.SellerOrderGoods;
|
20
|
import com.yohoufo.order.model.QuickDeliverOrderContext;
|
23
|
import com.yohoufo.order.model.QuickDeliverOrderContext;
|
|
@@ -37,6 +40,7 @@ import org.springframework.stereotype.Service; |
|
@@ -37,6 +40,7 @@ import org.springframework.stereotype.Service; |
37
|
import java.math.BigDecimal;
|
40
|
import java.math.BigDecimal;
|
38
|
import java.util.Arrays;
|
41
|
import java.util.Arrays;
|
39
|
import java.util.List;
|
42
|
import java.util.List;
|
|
|
43
|
+import java.util.concurrent.TimeUnit;
|
40
|
|
44
|
|
41
|
/**
|
45
|
/**
|
42
|
* @author chenchao
|
46
|
* @author chenchao
|
|
@@ -76,10 +80,23 @@ public class QuickDeliverGoodsService { |
|
@@ -76,10 +80,23 @@ public class QuickDeliverGoodsService { |
76
|
@Autowired
|
80
|
@Autowired
|
77
|
private SellerNoticeFacade sellerNoticeFacade;
|
81
|
private SellerNoticeFacade sellerNoticeFacade;
|
78
|
|
82
|
|
79
|
- public DepositPublishResp publish(QuickDeliverOrderSubmitReq req){
|
83
|
+ @Autowired
|
|
|
84
|
+ private RedisLock redisLock;
|
80
|
|
85
|
|
81
|
- QuickDeliverOrderContext qdoc = quickDeliverPublishProcessor.buildPublishCtx(req);
|
|
|
82
|
- return doPublish(qdoc);
|
86
|
+ public DepositPublishResp publish(QuickDeliverOrderSubmitReq req) {
|
|
|
87
|
+ RedisKeyBuilder redisLockKey = RedisKeyBuilder.newInstance()
|
|
|
88
|
+ .appendFixed("ufo:order:lock:publishQuickDeliverGoods:")
|
|
|
89
|
+ .appendVar(req.getUid() + "-" + req.getStorageId());
|
|
|
90
|
+ if (redisLock.acquire(redisLockKey, 1, TimeUnit.SECONDS)) {
|
|
|
91
|
+ try {
|
|
|
92
|
+ QuickDeliverOrderContext qdoc = quickDeliverPublishProcessor.buildPublishCtx(req);
|
|
|
93
|
+ return doPublish(qdoc);
|
|
|
94
|
+ } finally {
|
|
|
95
|
+ redisLock.release(redisLockKey);
|
|
|
96
|
+ }
|
|
|
97
|
+ } else {
|
|
|
98
|
+ throw new UfoServiceException(400, "寄存商品上架中,稍后再试");
|
|
|
99
|
+ }
|
83
|
}
|
100
|
}
|
84
|
|
101
|
|
85
|
|
102
|
|