Authored by chenchao

fix publish support multiple

@@ -15,6 +15,7 @@ import com.yohoufo.order.annotation.BlackUserType; @@ -15,6 +15,7 @@ import com.yohoufo.order.annotation.BlackUserType;
15 import com.yohoufo.order.common.BlackTypeEnum; 15 import com.yohoufo.order.common.BlackTypeEnum;
16 import com.yohoufo.order.model.request.OrderListRequest; 16 import com.yohoufo.order.model.request.OrderListRequest;
17 import com.yohoufo.order.model.request.OrderRequest; 17 import com.yohoufo.order.model.request.OrderRequest;
  18 +import com.yohoufo.order.model.response.DepositPublishResp;
18 import com.yohoufo.order.model.response.OrderSubmitResp; 19 import com.yohoufo.order.model.response.OrderSubmitResp;
19 import com.yohoufo.order.service.impl.OrderDynamicConfig; 20 import com.yohoufo.order.service.impl.OrderDynamicConfig;
20 import com.yohoufo.order.service.impl.SellerOrderService; 21 import com.yohoufo.order.service.impl.SellerOrderService;
@@ -578,7 +579,7 @@ public class SellerOrderController { @@ -578,7 +579,7 @@ public class SellerOrderController {
578 .build(); 579 .build();
579 logger.info("in ufo.sellerOrder.publishQuickDeliverPrd, req {}", req); 580 logger.info("in ufo.sellerOrder.publishQuickDeliverPrd, req {}", req);
580 581
581 - OrderSubmitResp resp = quickDeliverGoodsService.publish(req); 582 + DepositPublishResp resp = quickDeliverGoodsService.publish(req);
582 return new ApiResponse.ApiResponseBuilder().data(resp).code(200).message("闪购商品发布成功").build(); 583 return new ApiResponse.ApiResponseBuilder().data(resp).code(200).message("闪购商品发布成功").build();
583 } 584 }
584 585
1 package com.yohoufo.order.model; 1 package com.yohoufo.order.model;
2 2
  3 +import com.yohobuy.ufo.model.order.vo.AddressInfo;
3 import lombok.Data; 4 import lombok.Data;
4 5
  6 +import java.util.List;
  7 +import java.util.Map;
  8 +
5 @Data 9 @Data
6 public class QuickDeliverOrderContext extends SellerOrderContext { 10 public class QuickDeliverOrderContext extends SellerOrderContext {
7 11
8 12
9 - private String depositCode; 13 + private List<String> depositCodes;
  14 +
  15 +
  16 + private Map<String, AddressInfo> hiddenBackAddressMap;
  17 + private Map<String, AddressInfo> noHiddenBackAddressMap;
10 } 18 }
  1 +package com.yohoufo.order.model.response;
  2 +
  3 +import lombok.AllArgsConstructor;
  4 +import lombok.Builder;
  5 +import lombok.Data;
  6 +import lombok.NoArgsConstructor;
  7 +
  8 +@Data
  9 +@Builder
  10 +@AllArgsConstructor
  11 +@NoArgsConstructor
  12 +public class DepositPublishResp {
  13 + int successNum;
  14 +
  15 + int failNum;
  16 +}
@@ -2,9 +2,10 @@ package com.yohoufo.order.service.seller.quickDeliver; @@ -2,9 +2,10 @@ package com.yohoufo.order.service.seller.quickDeliver;
2 2
3 import com.yoho.error.ServiceError; 3 import com.yoho.error.ServiceError;
4 import com.yoho.error.exception.ServiceException; 4 import com.yoho.error.exception.ServiceException;
5 -import com.yohobuy.ufo.model.order.bo.GoodsInfo;  
6 import com.yohobuy.ufo.model.order.bo.ProductInfo; 5 import com.yohobuy.ufo.model.order.bo.ProductInfo;
7 -import com.yohobuy.ufo.model.order.common.*; 6 +import com.yohobuy.ufo.model.order.common.OrderCodeType;
  7 +import com.yohobuy.ufo.model.order.common.SellerOrderListType;
  8 +import com.yohobuy.ufo.model.order.common.SkupStatus;
8 import com.yohobuy.ufo.model.order.constants.SkupType; 9 import com.yohobuy.ufo.model.order.constants.SkupType;
9 import com.yohobuy.ufo.model.order.req.QuickDeliverOrderSubmitReq; 10 import com.yohobuy.ufo.model.order.req.QuickDeliverOrderSubmitReq;
10 import com.yohobuy.ufo.model.order.resp.OrderListInfo; 11 import com.yohobuy.ufo.model.order.resp.OrderListInfo;
@@ -17,7 +18,8 @@ import com.yohoufo.dal.order.model.SellerOrderGoods; @@ -17,7 +18,8 @@ import com.yohoufo.dal.order.model.SellerOrderGoods;
17 import com.yohoufo.order.model.QuickDeliverOrderContext; 18 import com.yohoufo.order.model.QuickDeliverOrderContext;
18 import com.yohoufo.order.model.request.OrderListRequest; 19 import com.yohoufo.order.model.request.OrderListRequest;
19 import com.yohoufo.order.model.request.SellerGoodsListRequest; 20 import com.yohoufo.order.model.request.SellerGoodsListRequest;
20 -import com.yohoufo.order.model.response.OrderSubmitResp; 21 +import com.yohoufo.order.model.response.DepositPublishResp;
  22 +import com.yohoufo.order.service.DepositService;
21 import com.yohoufo.order.service.handler.SellerOrderSubmitHandler; 23 import com.yohoufo.order.service.handler.SellerOrderSubmitHandler;
22 import com.yohoufo.order.service.impl.SkupListService; 24 import com.yohoufo.order.service.impl.SkupListService;
23 import com.yohoufo.order.service.proxy.ProductProxyService; 25 import com.yohoufo.order.service.proxy.ProductProxyService;
@@ -66,18 +68,24 @@ public class QuickDeliverGoodsService { @@ -66,18 +68,24 @@ public class QuickDeliverGoodsService {
66 @Autowired 68 @Autowired
67 private SkupListService skupListService; 69 private SkupListService skupListService;
68 70
69 - public OrderSubmitResp publish(QuickDeliverOrderSubmitReq req){ 71 + @Autowired
  72 + private DepositService depositService;
  73 +
  74 + public DepositPublishResp publish(QuickDeliverOrderSubmitReq req){
70 75
71 QuickDeliverOrderContext qdoc = quickDeliverPublishProcessor.buildPublishCtx(req); 76 QuickDeliverOrderContext qdoc = quickDeliverPublishProcessor.buildPublishCtx(req);
72 return doPublish(qdoc); 77 return doPublish(qdoc);
73 } 78 }
74 79
75 80
76 - private OrderSubmitResp doPublish(QuickDeliverOrderContext context){  
77 - final String depositCode = context.getDepositCode(); 81 + private DepositPublishResp doPublish(QuickDeliverOrderContext context){
78 int storageId = context.getStorageId(); 82 int storageId = context.getStorageId();
79 int uid = context.getUid(); 83 int uid = context.getUid();
80 BigDecimal salePrice = context.getSalePrice(); 84 BigDecimal salePrice = context.getSalePrice();
  85 +
  86 + //submit all as atomic operation, use transaction of DB
  87 + //all include : 1. skup, 2. order , 3. 寄回地址
  88 + for(String depositCode : context.getDepositCodes()) {
81 // step 2: create order, set status(not pay) 89 // step 2: create order, set status(not pay)
82 // generate a new real code 90 // generate a new real code
83 long orderCode = orderCodeGenerator.generate(OrderCodeType.SELLER_TYPE); 91 long orderCode = orderCodeGenerator.generate(OrderCodeType.SELLER_TYPE);
@@ -89,54 +97,59 @@ public class QuickDeliverGoodsService { @@ -89,54 +97,59 @@ public class QuickDeliverGoodsService {
89 //允许入驻商家后,对于个体户而言,也需要批次号(1:1这种,直接使用订单号,若以后有变化 用skup_batch表自增) 97 //允许入驻商家后,对于个体户而言,也需要批次号(1:1这种,直接使用订单号,若以后有变化 用skup_batch表自增)
90 context.getSoldProduct().setBatchNo(orderCode); 98 context.getSoldProduct().setBatchNo(orderCode);
91 context.setOrderCode(orderCode); 99 context.setOrderCode(orderCode);
92 - //submit all as atomic operation, use transaction of DB  
93 - //all include : 1. skup, 2. order , 3. 寄回地址  
94 - int skup ;  
95 - try{ 100 + //fetch matched address
  101 + context.setBackAddress(context.getNoHiddenBackAddressMap().get(depositCode));
  102 + context.setBackHiddenAddress(context.getHiddenBackAddressMap().get(depositCode));
  103 + //do submit
  104 + int skup;
  105 + try {
96 orderSubmitHandler.submit(context); 106 orderSubmitHandler.submit(context);
97 SellerOrderGoods psog = context.getSellerOrderGoods(); 107 SellerOrderGoods psog = context.getSellerOrderGoods();
98 skup = psog.getId(); 108 skup = psog.getId();
99 //record deposit code 4 deposit prd -> quick deliver 109 //record deposit code 4 deposit prd -> quick deliver
100 - sellerOrderMetaService.saveDepositCode(context.getDepositCode(), uid, skup); 110 + sellerOrderMetaService.saveDepositCode(depositCode, uid, skup);
101 logger.info("in QuickDeliverGoodsService.publish finish main local persistent, uid {} storageId {} salePrice {} orderCode {}", 111 logger.info("in QuickDeliverGoodsService.publish finish main local persistent, uid {} storageId {} salePrice {} orderCode {}",
102 uid, storageId, salePrice, orderCode); 112 uid, storageId, salePrice, orderCode);
103 - }catch (Exception ex){  
104 - String content = "用户"+ uid + "发布闪购商品"+depositCode + "失败"; 113 + } catch (Exception ex) {
  114 + String content = "用户" + uid + "发布闪购商品" + depositCode + "失败";
105 SmsAlarmEvent smsAlarmEvent = new SmsAlarmEvent("sellerOrder.create", "create", content); 115 SmsAlarmEvent smsAlarmEvent = new SmsAlarmEvent("sellerOrder.create", "create", content);
106 EventBusPublisher.publishEvent(smsAlarmEvent); 116 EventBusPublisher.publishEvent(smsAlarmEvent);
107 logger.warn("in publish quick deliver Prd create order fail , uid {}, depositCode {}", uid, depositCode); 117 logger.warn("in publish quick deliver Prd create order fail , uid {}, depositCode {}", uid, depositCode);
108 throw new ServiceException(ServiceError.EARNESTMONEY_ORDER_CREATE_FAIL); 118 throw new ServiceException(ServiceError.EARNESTMONEY_ORDER_CREATE_FAIL);
109 } 119 }
110 120
111 - syncPrd(context);  
112 - GoodsInfo goodsInfo = context.getSoldProduct();  
113 - OrderSubmitResp resp = OrderSubmitResp.builder()  
114 - .orderCode(orderCode)  
115 - .skup(skup)  
116 - .productId(goodsInfo.getProductId()).build(); 121 + syncPrd(context, depositCode);
  122 +
  123 + }
  124 +
  125 + DepositPublishResp resp = DepositPublishResp.builder()
  126 + .build();
117 return resp; 127 return resp;
118 } 128 }
119 129
120 - private void syncPrd(QuickDeliverOrderContext context){  
121 - long orderCode = context.getOrderCode(); 130 + /**
  131 + * TODO in the further, we try 2 keep BASE
  132 + * @param context
  133 + * @param depositCode
  134 + */
  135 + private void syncPrd(QuickDeliverOrderContext context, String depositCode){
  136 + int uid = context.getUid();
122 SellerOrderGoods psog = context.getSellerOrderGoods(); 137 SellerOrderGoods psog = context.getSellerOrderGoods();
123 int skup = psog.getId(); 138 int skup = psog.getId();
124 -  
125 - //TODO  
126 - SkupType skupType = context.getSkupType();  
127 - switch (skupType){  
128 - case IN_STOCK:  
129 - //TODO 上架成功,需要仓储管理 修改寄存状态  
130 - break;  
131 - case QUICK_DELIVER:  
132 - //TODO 闪购商品 物权转移  
133 -  
134 - break;  
135 - }  
136 - 139 + try{
137 boolean syncPrdFlag = productProxyService.syncFullSkup(psog=context.getSellerOrderGoods(), SkupStatus.CAN_SELL); 140 boolean syncPrdFlag = productProxyService.syncFullSkup(psog=context.getSellerOrderGoods(), SkupStatus.CAN_SELL);
138 - logger.info("publish quick deliver Prd finish, createGoods {}, skup {}, orderCode {}",  
139 - syncPrdFlag, skup, orderCode); 141 + logger.info("publish quick deliver Prd finish, createGoods {}, skup {}, depositCode {}",
  142 + syncPrdFlag, skup, depositCode);
  143 + }catch (Exception ex){
  144 + logger.warn("in publish quick deliver prd, sync full skup fail, uid {} depositCode {} skup {}",
  145 + uid, depositCode, skup, ex);
  146 + }
  147 + try {
  148 + depositService.changeSaleStatusOn(uid, depositCode, skup);
  149 + }catch (Exception ex){
  150 + logger.warn("in publish quick deliver prd , change deposit storage fail, uid {} depositCode {} skup {}",
  151 + uid, depositCode, skup, ex);
  152 + }
140 153
141 } 154 }
142 155
1 package com.yohoufo.order.service.seller.quickDeliver; 1 package com.yohoufo.order.service.seller.quickDeliver;
2 2
3 -import com.yoho.error.ServiceError;  
4 -import com.yoho.error.exception.ServiceException;  
5 import com.yohobuy.ufo.model.order.constants.SkupType; 3 import com.yohobuy.ufo.model.order.constants.SkupType;
6 import com.yohobuy.ufo.model.order.req.QuickDeliverOrderSubmitReq; 4 import com.yohobuy.ufo.model.order.req.QuickDeliverOrderSubmitReq;
7 import com.yohobuy.ufo.model.order.req.SellerOrderComputeReq; 5 import com.yohobuy.ufo.model.order.req.SellerOrderComputeReq;
8 import com.yohobuy.ufo.model.order.vo.AddressInfo; 6 import com.yohobuy.ufo.model.order.vo.AddressInfo;
9 import com.yohoufo.common.exception.UfoServiceException; 7 import com.yohoufo.common.exception.UfoServiceException;
10 -import com.yohoufo.common.utils.AddressUtil; 8 +import com.yohoufo.dal.order.model.StorageDeposit;
11 import com.yohoufo.order.model.QuickDeliverOrderContext; 9 import com.yohoufo.order.model.QuickDeliverOrderContext;
12 -import com.yohoufo.order.service.proxy.UserProxyService; 10 +import com.yohoufo.order.service.DepositService;
  11 +import com.yohoufo.order.service.IBuyerOrderMetaService;
13 import com.yohoufo.order.service.seller.PublishProcessor; 12 import com.yohoufo.order.service.seller.PublishProcessor;
14 import com.yohoufo.order.service.seller.processor.PriceComputePrepareProcessor; 13 import com.yohoufo.order.service.seller.processor.PriceComputePrepareProcessor;
15 -import com.yohoufo.order.utils.AddressHelper;  
16 import com.yohoufo.order.utils.LoggerUtils; 14 import com.yohoufo.order.utils.LoggerUtils;
17 -import org.apache.commons.lang3.StringUtils; 15 +import org.apache.commons.collections.CollectionUtils;
18 import org.slf4j.Logger; 16 import org.slf4j.Logger;
19 import org.springframework.beans.factory.annotation.Autowired; 17 import org.springframework.beans.factory.annotation.Autowired;
20 import org.springframework.stereotype.Service; 18 import org.springframework.stereotype.Service;
21 19
22 import java.math.BigDecimal; 20 import java.math.BigDecimal;
  21 +import java.util.ArrayList;
  22 +import java.util.HashMap;
  23 +import java.util.List;
  24 +import java.util.Map;
23 25
24 @Service 26 @Service
25 public class QuickDeliverPublishProcessor implements PublishProcessor<QuickDeliverOrderSubmitReq,QuickDeliverOrderContext> { 27 public class QuickDeliverPublishProcessor implements PublishProcessor<QuickDeliverOrderSubmitReq,QuickDeliverOrderContext> {
@@ -29,54 +31,66 @@ public class QuickDeliverPublishProcessor implements PublishProcessor<QuickDeliv @@ -29,54 +31,66 @@ public class QuickDeliverPublishProcessor implements PublishProcessor<QuickDeliv
29 private PriceComputePrepareProcessor priceComputePrepareProcessor; 31 private PriceComputePrepareProcessor priceComputePrepareProcessor;
30 32
31 @Autowired 33 @Autowired
32 - private UserProxyService userProxyService; 34 + private DepositService depositService;
  35 +
  36 + @Autowired
  37 + private IBuyerOrderMetaService buyerOrderMetaService;
33 38
34 @Override 39 @Override
35 public QuickDeliverOrderContext buildPublishCtx(QuickDeliverOrderSubmitReq qdosr) { 40 public QuickDeliverOrderContext buildPublishCtx(QuickDeliverOrderSubmitReq qdosr) {
36 41
37 int uid; 42 int uid;
38 int storageId; 43 int storageId;
  44 + int num;
39 SellerOrderComputeReq socr = SellerOrderComputeReq.builder() 45 SellerOrderComputeReq socr = SellerOrderComputeReq.builder()
40 .uid(uid=qdosr.getUid()).storageId(storageId=qdosr.getStorageId()) 46 .uid(uid=qdosr.getUid()).storageId(storageId=qdosr.getStorageId())
41 - .num(qdosr.getNum()) 47 + .num(num=qdosr.getNum())
42 .price(qdosr.getPrice()).skupType(qdosr.getSkupTypeCode()).build(); 48 .price(qdosr.getPrice()).skupType(qdosr.getSkupTypeCode()).build();
43 PriceComputePrepareProcessor.PriceComputeNode icpNode = priceComputePrepareProcessor.checkAndAcquire(socr); 49 PriceComputePrepareProcessor.PriceComputeNode icpNode = priceComputePrepareProcessor.checkAndAcquire(socr);
44 - /*  
45 - String depositCode;  
46 - if (StringUtils.isBlank(depositCode = qdosr.getDepositCode())){ 50 +
  51 + // query deposit code is exist in system
  52 + List<StorageDeposit> depositPrds = depositService.getStorageDeposit4Publish(uid, storageId, num);
  53 + if (CollectionUtils.isEmpty(depositPrds)){
47 logger.warn("QuickDeliverPublishProcessor check depositCode illegal, req {} ", qdosr); 54 logger.warn("QuickDeliverPublishProcessor check depositCode illegal, req {} ", qdosr);
48 - throw new UfoServiceException(400, "不是寄存商品");  
49 - }*/  
50 - //TODO query deposit code is exist in system 55 + throw new UfoServiceException(400, "没有需要上架的寄存商品");
  56 + }
  57 + int depositPrdsize;
  58 + if ((depositPrdsize=depositPrds.size()) < num){
  59 + logger.warn("QuickDeliverPublishProcessor deposit prds reduce some , depositPrdsize {} req {} ",
  60 + depositPrdsize,qdosr);
  61 + throw new UfoServiceException(400, "待上架的寄存商品数量已经不足"+num + "个");
  62 + }
  63 +
  64 +
51 65
52 BigDecimal salePrice = icpNode.getSalePrice(); 66 BigDecimal salePrice = icpNode.getSalePrice();
53 SkupType skupType = icpNode.getSkupType(); 67 SkupType skupType = icpNode.getSkupType();
54 - /*  
55 - int addressId = AddressUtil.getDecryptStr(qdosr.getAddressId());  
56 - if (addressId < 0){  
57 - logger.warn("QuickDeliverPublishProcessor seller submit order addressId invalidate, uid {}, storageId {}, addressId is {}",  
58 - uid, storageId, qdosr.getAddressId());  
59 - throw new ServiceException(ServiceError.ORDER_ADDRESSID_INVALIDATE); 68 +
  69 + List<String> depositCodes = new ArrayList<>(depositPrdsize);
  70 + Map<String, AddressInfo> hiddenBackAddressMap = new HashMap<>(depositPrdsize),
  71 + noHiddenBackAddressMap = new HashMap<>(depositPrdsize)
  72 + ;
  73 +
  74 + for(StorageDeposit sd : depositPrds){
  75 + String depositCode = sd.getDepositCode();
  76 + AddressInfo hiddenBackAddress = buyerOrderMetaService.getHiddenAddressInfo(uid, sd.getOrderCode());
  77 + AddressInfo noHiddenBackAddress = buyerOrderMetaService.getAddressInfo(uid, sd.getOrderCode());
  78 + depositCodes.add(depositCode);
  79 + hiddenBackAddressMap.put(depositCode, hiddenBackAddress);
  80 + noHiddenBackAddressMap.put(depositCode, noHiddenBackAddress);
60 } 81 }
61 82
62 - //the address of send back 2 seller  
63 - AddressInfo hiddenBackAddress = userProxyService.getHiddenAddressInfo(uid, addressId);  
64 - AddressInfo noHiddenBackAddress = userProxyService.getAddressInfoNotHidden(uid, addressId);  
65 - if(AddressHelper.isNeedUpdate(noHiddenBackAddress)){  
66 - logger.warn("QuickDeliverPublishProcessor seller submit addressId need update, uid is {}, storageId is {}, addressId is {}",  
67 - uid, storageId, addressId);  
68 - throw new ServiceException(ServiceError.ORDER_ADDRESS_NEED_UPDATE);  
69 - }*/ 83 +
70 QuickDeliverOrderContext context = new QuickDeliverOrderContext(); 84 QuickDeliverOrderContext context = new QuickDeliverOrderContext();
71 context.setUid(uid); 85 context.setUid(uid);
72 context.setStorageId(storageId); 86 context.setStorageId(storageId);
73 context.setSalePrice(salePrice); 87 context.setSalePrice(salePrice);
74 // 88 //
75 - //context.setBackAddress(noHiddenBackAddress);  
76 - //context.setBackHiddenAddress(hiddenBackAddress); 89 + context.setHiddenBackAddressMap(hiddenBackAddressMap);
  90 + context.setNoHiddenBackAddressMap(noHiddenBackAddressMap);
  91 + context.setDepositCodes(depositCodes);
77 // 92 //
78 context.setSkupType(skupType); 93 context.setSkupType(skupType);
79 - //context.setDepositCode(depositCode);  
80 return context; 94 return context;
81 } 95 }
82 } 96 }