Authored by chenchao

fix publish support multiple

... ... @@ -15,6 +15,7 @@ import com.yohoufo.order.annotation.BlackUserType;
import com.yohoufo.order.common.BlackTypeEnum;
import com.yohoufo.order.model.request.OrderListRequest;
import com.yohoufo.order.model.request.OrderRequest;
import com.yohoufo.order.model.response.DepositPublishResp;
import com.yohoufo.order.model.response.OrderSubmitResp;
import com.yohoufo.order.service.impl.OrderDynamicConfig;
import com.yohoufo.order.service.impl.SellerOrderService;
... ... @@ -578,7 +579,7 @@ public class SellerOrderController {
.build();
logger.info("in ufo.sellerOrder.publishQuickDeliverPrd, req {}", req);
OrderSubmitResp resp = quickDeliverGoodsService.publish(req);
DepositPublishResp resp = quickDeliverGoodsService.publish(req);
return new ApiResponse.ApiResponseBuilder().data(resp).code(200).message("闪购商品发布成功").build();
}
... ...
package com.yohoufo.order.model;
import com.yohobuy.ufo.model.order.vo.AddressInfo;
import lombok.Data;
import java.util.List;
import java.util.Map;
@Data
public class QuickDeliverOrderContext extends SellerOrderContext {
private String depositCode;
private List<String> depositCodes;
private Map<String, AddressInfo> hiddenBackAddressMap;
private Map<String, AddressInfo> noHiddenBackAddressMap;
}
... ...
package com.yohoufo.order.model.response;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class DepositPublishResp {
int successNum;
int failNum;
}
... ...
... ... @@ -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,18 +68,24 @@ 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();
//submit all as atomic operation, use transaction of DB
//all include : 1. skup, 2. order , 3. 寄回地址
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);
... ... @@ -89,54 +97,59 @@ public class QuickDeliverGoodsService {
//允许入驻商家后,对于个体户而言,也需要批次号(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{
//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(context.getDepositCode(), uid, skup);
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 + "失败";
} 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);
GoodsInfo goodsInfo = context.getSoldProduct();
OrderSubmitResp resp = OrderSubmitResp.builder()
.orderCode(orderCode)
.skup(skup)
.productId(goodsInfo.getProductId()).build();
syncPrd(context, depositCode);
}
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);
}
}
... ...
package com.yohoufo.order.service.seller.quickDeliver;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yohobuy.ufo.model.order.constants.SkupType;
import com.yohobuy.ufo.model.order.req.QuickDeliverOrderSubmitReq;
import com.yohobuy.ufo.model.order.req.SellerOrderComputeReq;
import com.yohobuy.ufo.model.order.vo.AddressInfo;
import com.yohoufo.common.exception.UfoServiceException;
import com.yohoufo.common.utils.AddressUtil;
import com.yohoufo.dal.order.model.StorageDeposit;
import com.yohoufo.order.model.QuickDeliverOrderContext;
import com.yohoufo.order.service.proxy.UserProxyService;
import com.yohoufo.order.service.DepositService;
import com.yohoufo.order.service.IBuyerOrderMetaService;
import com.yohoufo.order.service.seller.PublishProcessor;
import com.yohoufo.order.service.seller.processor.PriceComputePrepareProcessor;
import com.yohoufo.order.utils.AddressHelper;
import com.yohoufo.order.utils.LoggerUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class QuickDeliverPublishProcessor implements PublishProcessor<QuickDeliverOrderSubmitReq,QuickDeliverOrderContext> {
... ... @@ -29,54 +31,66 @@ public class QuickDeliverPublishProcessor implements PublishProcessor<QuickDeliv
private PriceComputePrepareProcessor priceComputePrepareProcessor;
@Autowired
private UserProxyService userProxyService;
private DepositService depositService;
@Autowired
private IBuyerOrderMetaService buyerOrderMetaService;
@Override
public QuickDeliverOrderContext buildPublishCtx(QuickDeliverOrderSubmitReq qdosr) {
int uid;
int storageId;
int num;
SellerOrderComputeReq socr = SellerOrderComputeReq.builder()
.uid(uid=qdosr.getUid()).storageId(storageId=qdosr.getStorageId())
.num(qdosr.getNum())
.num(num=qdosr.getNum())
.price(qdosr.getPrice()).skupType(qdosr.getSkupTypeCode()).build();
PriceComputePrepareProcessor.PriceComputeNode icpNode = priceComputePrepareProcessor.checkAndAcquire(socr);
/*
String depositCode;
if (StringUtils.isBlank(depositCode = qdosr.getDepositCode())){
// query deposit code is exist in system
List<StorageDeposit> depositPrds = depositService.getStorageDeposit4Publish(uid, storageId, num);
if (CollectionUtils.isEmpty(depositPrds)){
logger.warn("QuickDeliverPublishProcessor check depositCode illegal, req {} ", qdosr);
throw new UfoServiceException(400, "不是寄存商品");
}*/
//TODO query deposit code is exist in system
throw new UfoServiceException(400, "没有需要上架的寄存商品");
}
int depositPrdsize;
if ((depositPrdsize=depositPrds.size()) < num){
logger.warn("QuickDeliverPublishProcessor deposit prds reduce some , depositPrdsize {} req {} ",
depositPrdsize,qdosr);
throw new UfoServiceException(400, "待上架的寄存商品数量已经不足"+num + "个");
}
BigDecimal salePrice = icpNode.getSalePrice();
SkupType skupType = icpNode.getSkupType();
/*
int addressId = AddressUtil.getDecryptStr(qdosr.getAddressId());
if (addressId < 0){
logger.warn("QuickDeliverPublishProcessor seller submit order addressId invalidate, uid {}, storageId {}, addressId is {}",
uid, storageId, qdosr.getAddressId());
throw new ServiceException(ServiceError.ORDER_ADDRESSID_INVALIDATE);
List<String> depositCodes = new ArrayList<>(depositPrdsize);
Map<String, AddressInfo> hiddenBackAddressMap = new HashMap<>(depositPrdsize),
noHiddenBackAddressMap = new HashMap<>(depositPrdsize)
;
for(StorageDeposit sd : depositPrds){
String depositCode = sd.getDepositCode();
AddressInfo hiddenBackAddress = buyerOrderMetaService.getHiddenAddressInfo(uid, sd.getOrderCode());
AddressInfo noHiddenBackAddress = buyerOrderMetaService.getAddressInfo(uid, sd.getOrderCode());
depositCodes.add(depositCode);
hiddenBackAddressMap.put(depositCode, hiddenBackAddress);
noHiddenBackAddressMap.put(depositCode, noHiddenBackAddress);
}
//the address of send back 2 seller
AddressInfo hiddenBackAddress = userProxyService.getHiddenAddressInfo(uid, addressId);
AddressInfo noHiddenBackAddress = userProxyService.getAddressInfoNotHidden(uid, addressId);
if(AddressHelper.isNeedUpdate(noHiddenBackAddress)){
logger.warn("QuickDeliverPublishProcessor seller submit addressId need update, uid is {}, storageId is {}, addressId is {}",
uid, storageId, addressId);
throw new ServiceException(ServiceError.ORDER_ADDRESS_NEED_UPDATE);
}*/
QuickDeliverOrderContext context = new QuickDeliverOrderContext();
context.setUid(uid);
context.setStorageId(storageId);
context.setSalePrice(salePrice);
//
//context.setBackAddress(noHiddenBackAddress);
//context.setBackHiddenAddress(hiddenBackAddress);
context.setHiddenBackAddressMap(hiddenBackAddressMap);
context.setNoHiddenBackAddressMap(noHiddenBackAddressMap);
context.setDepositCodes(depositCodes);
//
context.setSkupType(skupType);
//context.setDepositCode(depositCode);
return context;
}
}
... ...