1
|
package com.yohoufo.order.service.seller;
|
1
|
package com.yohoufo.order.service.seller;
|
2
|
|
2
|
|
|
|
3
|
+import com.yoho.error.ServiceError;
|
|
|
4
|
+import com.yoho.error.exception.ServiceException;
|
|
|
5
|
+import com.yohobuy.ufo.model.order.bo.MerchantOrderAttachInfo;
|
3
|
import com.yohobuy.ufo.model.order.req.BatchImportPrdReq;
|
6
|
import com.yohobuy.ufo.model.order.req.BatchImportPrdReq;
|
4
|
import com.yohobuy.ufo.model.order.vo.AddressInfo;
|
7
|
import com.yohobuy.ufo.model.order.vo.AddressInfo;
|
5
|
import com.yohobuy.ufo.model.request.product.ProductImportTranItemBo;
|
8
|
import com.yohobuy.ufo.model.request.product.ProductImportTranItemBo;
|
|
|
9
|
+import com.yohoufo.common.alarm.EventBusPublisher;
|
|
|
10
|
+import com.yohoufo.dal.order.model.SellerWallet;
|
|
|
11
|
+import com.yohoufo.dal.order.model.SellerWalletDetail;
|
|
|
12
|
+import com.yohoufo.order.event.BatchPublishTailEvent;
|
6
|
import com.yohoufo.order.model.SellerOrderContext;
|
13
|
import com.yohoufo.order.model.SellerOrderContext;
|
|
|
14
|
+import com.yohoufo.order.model.dto.SellerOrderComputeResult;
|
|
|
15
|
+import com.yohoufo.order.service.MerchantOrderPaymentService;
|
7
|
import com.yohoufo.order.service.handler.SellerOrderSubmitHandler;
|
16
|
import com.yohoufo.order.service.handler.SellerOrderSubmitHandler;
|
|
|
17
|
+import com.yohoufo.order.service.impl.SellerService;
|
8
|
import com.yohoufo.order.service.impl.SkupBatchService;
|
18
|
import com.yohoufo.order.service.impl.SkupBatchService;
|
9
|
import com.yohoufo.order.service.impl.processor.SellerOrderPrepareProcessor;
|
19
|
import com.yohoufo.order.service.impl.processor.SellerOrderPrepareProcessor;
|
10
|
import com.yohoufo.order.service.proxy.ProductProxyService;
|
20
|
import com.yohoufo.order.service.proxy.ProductProxyService;
|
|
|
21
|
+import lombok.Data;
|
|
|
22
|
+import lombok.experimental.Builder;
|
11
|
import org.apache.commons.collections.CollectionUtils;
|
23
|
import org.apache.commons.collections.CollectionUtils;
|
12
|
import org.springframework.beans.factory.annotation.Autowired;
|
24
|
import org.springframework.beans.factory.annotation.Autowired;
|
13
|
import org.springframework.stereotype.Service;
|
25
|
import org.springframework.stereotype.Service;
|
|
@@ -21,7 +33,18 @@ import java.util.Objects; |
|
@@ -21,7 +33,18 @@ import java.util.Objects; |
21
|
*/
|
33
|
*/
|
22
|
@Service
|
34
|
@Service
|
23
|
public class ImportPublishExcutor implements PublishExcutor<BatchImportPrdReq, SellerOrderSubmitHandler.ForkJoinResult>{
|
35
|
public class ImportPublishExcutor implements PublishExcutor<BatchImportPrdReq, SellerOrderSubmitHandler.ForkJoinResult>{
|
24
|
-
|
36
|
+ @Builder
|
|
|
37
|
+ @Data
|
|
|
38
|
+ private static class ImPrdNode{
|
|
|
39
|
+ Integer uid;
|
|
|
40
|
+ boolean isSuper;
|
|
|
41
|
+ SellerWallet sellerWallet;
|
|
|
42
|
+ Integer storageId;
|
|
|
43
|
+ BigDecimal salePrice;
|
|
|
44
|
+ int storageNum;
|
|
|
45
|
+ AddressInfo hiddenBackAddress;
|
|
|
46
|
+ AddressInfo noHiddenBackAddress;
|
|
|
47
|
+ }
|
25
|
@Autowired
|
48
|
@Autowired
|
26
|
private SellerOrderSubmitHandler orderSubmitHandler;
|
49
|
private SellerOrderSubmitHandler orderSubmitHandler;
|
27
|
|
50
|
|
|
@@ -34,20 +57,43 @@ public class ImportPublishExcutor implements PublishExcutor<BatchImportPrdReq, S |
|
@@ -34,20 +57,43 @@ public class ImportPublishExcutor implements PublishExcutor<BatchImportPrdReq, S |
34
|
@Autowired
|
57
|
@Autowired
|
35
|
private SkupBatchService skupBatchService;
|
58
|
private SkupBatchService skupBatchService;
|
36
|
|
59
|
|
|
|
60
|
+ @Autowired
|
|
|
61
|
+ private MerchantOrderPaymentService merchantOrderPaymentService;
|
|
|
62
|
+
|
|
|
63
|
+ @Autowired
|
|
|
64
|
+ private SellerService sellerService;
|
|
|
65
|
+
|
37
|
@Override
|
66
|
@Override
|
38
|
public SellerOrderSubmitHandler.ForkJoinResult publish(BatchImportPrdReq req) {
|
67
|
public SellerOrderSubmitHandler.ForkJoinResult publish(BatchImportPrdReq req) {
|
39
|
List<ProductImportTranItemBo> importPrds ;
|
68
|
List<ProductImportTranItemBo> importPrds ;
|
40
|
if (CollectionUtils.isNotEmpty(importPrds = req.getProductList())){
|
69
|
if (CollectionUtils.isNotEmpty(importPrds = req.getProductList())){
|
|
|
70
|
+ Integer uid = importPrds.get(0).getUid();
|
|
|
71
|
+ boolean isSuper = sellerService.checkIsNormalSuper(uid);
|
|
|
72
|
+ if (!isSuper){
|
|
|
73
|
+ logger.warn("in ImportPublishExcutor.publish not super, uid {} ", uid);
|
|
|
74
|
+ return null;
|
|
|
75
|
+ }
|
41
|
for(ProductImportTranItemBo importPrd : importPrds){
|
76
|
for(ProductImportTranItemBo importPrd : importPrds){
|
42
|
- Integer uid = importPrd.getUid();
|
|
|
43
|
Integer storageId = importPrd.getStorageId();
|
77
|
Integer storageId = importPrd.getStorageId();
|
44
|
BigDecimal salePrice = importPrd.getPrice();
|
78
|
BigDecimal salePrice = importPrd.getPrice();
|
45
|
int storageNum = importPrd.getNum();
|
79
|
int storageNum = importPrd.getNum();
|
46
|
- SellerOrderSubmitHandler.ForkJoinResult fjr = publishOne(uid, storageId, salePrice, storageNum,
|
|
|
47
|
- req.getHiddenBackAddress(), req.getNoHiddenBackAddress());
|
|
|
48
|
- int successNum = Objects.isNull(fjr) || Objects.isNull(fjr.getSkupIds()) ? 0 : fjr.getSkupIds().size();
|
80
|
+ ImPrdNode node = ImPrdNode.builder().uid(uid)
|
|
|
81
|
+ .isSuper(isSuper)
|
|
|
82
|
+ .storageId(storageId).salePrice(salePrice).storageNum(storageNum)
|
|
|
83
|
+ .noHiddenBackAddress(req.getNoHiddenBackAddress())
|
|
|
84
|
+ .hiddenBackAddress(req.getHiddenBackAddress()).build();
|
|
|
85
|
+ int successNum=0;
|
|
|
86
|
+ try{
|
|
|
87
|
+ SellerOrderSubmitHandler.ForkJoinResult fjr = publishOne(node);
|
|
|
88
|
+ successNum = Objects.isNull(fjr) || Objects.isNull(fjr.getSkupIds()) ? 0 : fjr.getSkupIds().size();
|
|
|
89
|
+
|
|
|
90
|
+ }catch(Exception ex){
|
|
|
91
|
+ logger.warn("in ImportPublishExcutor.publishOne orderSubmitHandler.submitMultiple fail, uid {} storageId {} salePrice {} storageNum {}",
|
|
|
92
|
+ uid, storageId, salePrice, storageNum);
|
|
|
93
|
+ }
|
49
|
importPrd.setSuccessdNum(successNum);
|
94
|
importPrd.setSuccessdNum(successNum);
|
50
|
}
|
95
|
}
|
|
|
96
|
+
|
51
|
//修改批量计划表状态
|
97
|
//修改批量计划表状态
|
52
|
productProxyService.batchAdd(importPrds);
|
98
|
productProxyService.batchAdd(importPrds);
|
53
|
}
|
99
|
}
|
|
@@ -56,27 +102,47 @@ public class ImportPublishExcutor implements PublishExcutor<BatchImportPrdReq, S |
|
@@ -56,27 +102,47 @@ public class ImportPublishExcutor implements PublishExcutor<BatchImportPrdReq, S |
56
|
|
102
|
|
57
|
|
103
|
|
58
|
|
104
|
|
59
|
- public SellerOrderSubmitHandler.ForkJoinResult publishOne(Integer uid, Integer storageId,
|
|
|
60
|
- BigDecimal salePrice, int storageNum,
|
|
|
61
|
- AddressInfo hiddenBackAddress,
|
|
|
62
|
- AddressInfo noHiddenBackAddress){
|
105
|
+ public SellerOrderSubmitHandler.ForkJoinResult publishOne(ImPrdNode node){
|
|
|
106
|
+ Integer uid = node.uid;
|
|
|
107
|
+ boolean isSuper = node.isSuper;
|
|
|
108
|
+
|
|
|
109
|
+ Integer storageId = node.storageId;
|
|
|
110
|
+ BigDecimal salePrice = node.salePrice;
|
|
|
111
|
+ int storageNum = node.storageNum;
|
|
|
112
|
+ AddressInfo hiddenBackAddress = node.hiddenBackAddress;
|
|
|
113
|
+ AddressInfo noHiddenBackAddress = node.noHiddenBackAddress;
|
63
|
SellerOrderContext ctx = sellerOrderPrepareProcessor.buildImportPrdCxt(uid, storageId, salePrice, storageNum);
|
114
|
SellerOrderContext ctx = sellerOrderPrepareProcessor.buildImportPrdCxt(uid, storageId, salePrice, storageNum);
|
64
|
ctx.setBackAddress(noHiddenBackAddress);
|
115
|
ctx.setBackAddress(noHiddenBackAddress);
|
65
|
ctx.setBackHiddenAddress(hiddenBackAddress);
|
116
|
ctx.setBackHiddenAddress(hiddenBackAddress);
|
66
|
long batchNo = skupBatchService.generateBatchNo(uid, storageNum);
|
117
|
long batchNo = skupBatchService.generateBatchNo(uid, storageNum);
|
67
|
ctx.getSoldProduct().setBatchNo(batchNo);
|
118
|
ctx.getSoldProduct().setBatchNo(batchNo);
|
|
|
119
|
+
|
|
|
120
|
+ SellerOrderComputeResult socr = ctx.getSellerOrderComputeResult();
|
|
|
121
|
+ BigDecimal singleEarestMoney = socr.getEarnestMoney().getEarnestMoney();
|
|
|
122
|
+ BigDecimal mEarestMoney = sellerOrderPrepareProcessor.checkNGetMergeEarnestMoney(uid, singleEarestMoney,
|
|
|
123
|
+ storageNum, ctx.getSalePrice(), isSuper);
|
|
|
124
|
+ SellerWalletDetail.Type swdType = SellerWalletDetail.Type.PUBLISH;
|
|
|
125
|
+ MerchantOrderAttachInfo moai = MerchantOrderAttachInfo.builder().uid(uid)
|
|
|
126
|
+ .storageId(ctx.getStorageId()).earnestMoney(mEarestMoney)
|
|
|
127
|
+ .type(swdType.getValue()).build();
|
|
|
128
|
+ SellerWallet sellerWallet = merchantOrderPaymentService.useEarnest(uid, mEarestMoney, moai);
|
|
|
129
|
+ // invoke pay by wallet
|
|
|
130
|
+ boolean paySuccess = Objects.nonNull(sellerWallet);
|
|
|
131
|
+ if (!paySuccess){
|
|
|
132
|
+ logger.warn("batch publishOne pay fail, req {} mEarestMoney {}", node, mEarestMoney);
|
|
|
133
|
+ throw new ServiceException(ServiceError.WALLET_EARNESTMONEY_PAY_FAIL);
|
|
|
134
|
+ }
|
68
|
SellerOrderSubmitHandler.ForkJoinResult fjr = null;
|
135
|
SellerOrderSubmitHandler.ForkJoinResult fjr = null;
|
69
|
- try {
|
136
|
+
|
70
|
fjr = orderSubmitHandler.submitMultiple(ctx, storageNum);
|
137
|
fjr = orderSubmitHandler.submitMultiple(ctx, storageNum);
|
71
|
- }catch (Exception ex){
|
|
|
72
|
- logger.warn("in ImportPublishExcutor.publishOne orderSubmitHandler.submitMultiple fail, uid {} storageId {} salePrice {} storageNum {}",
|
|
|
73
|
- uid, storageId, salePrice, storageNum);
|
|
|
74
|
- }finally {
|
138
|
+ // (异步实现)记录保证金流水
|
|
|
139
|
+ //(异步实现)同步数据到prd,记录支付,
|
|
|
140
|
+ BatchPublishTailEvent bpte = BatchPublishTailEvent.builder().isSurper(isSuper)
|
|
|
141
|
+ .fjr(fjr).sellerWallet(sellerWallet).build();
|
|
|
142
|
+ EventBusPublisher.publishEvent(bpte);
|
75
|
return fjr;
|
143
|
return fjr;
|
76
|
}
|
144
|
}
|
77
|
|
145
|
|
78
|
- }
|
|
|
79
|
-
|
|
|
80
|
|
146
|
|
81
|
|
147
|
|
82
|
|
148
|
|