Authored by tanling

提交订单归还库存

@@ -6,6 +6,7 @@ import com.yoho.core.dal.datasource.annotation.Database; @@ -6,6 +6,7 @@ import com.yoho.core.dal.datasource.annotation.Database;
6 import com.yoho.core.transaction.annoation.YHTransaction; 6 import com.yoho.core.transaction.annoation.YHTransaction;
7 import com.yoho.error.ServiceError; 7 import com.yoho.error.ServiceError;
8 import com.yoho.error.exception.ServiceException; 8 import com.yoho.error.exception.ServiceException;
  9 +import com.yohoufo.common.alarm.CommonAlarmEventPublisher;
9 import com.yohoufo.dal.order.*; 10 import com.yohoufo.dal.order.*;
10 import com.yohoufo.dal.order.model.*; 11 import com.yohoufo.dal.order.model.*;
11 import com.yohoufo.order.common.ClientType; 12 import com.yohoufo.order.common.ClientType;
@@ -45,41 +46,45 @@ public class SubmitOrderServiceImpl implements ISubmitOrderService { @@ -45,41 +46,45 @@ public class SubmitOrderServiceImpl implements ISubmitOrderService {
45 BuyerOrderSubmitResult result = null; 46 BuyerOrderSubmitResult result = null;
46 try { 47 try {
47 // 减库存 48 // 减库存
48 - if(productProxyService.subtractStorage(orderBuilder.getProductId(), orderBuilder.getSkup())) { 49 + productProxyService.subtractStorage(orderBuilder.getProductId(), orderBuilder.getSkup());
49 50
  51 + try{
50 //使用优惠券 52 //使用优惠券
51 if (orderBuilder.getCouponBo().getCouponAmount().doubleValue() > 0) { 53 if (orderBuilder.getCouponBo().getCouponAmount().doubleValue() > 0) {
52 couponProxyService.orderUseCoupon(orderBuilder.getUid(), orderBuilder.getOrderCode(), orderBuilder.getCouponBo()); 54 couponProxyService.orderUseCoupon(orderBuilder.getUid(), orderBuilder.getOrderCode(), orderBuilder.getCouponBo());
53 } 55 }
54 // 创建订单 56 // 创建订单
55 return orderCreateService.createOrder(orderBuilder); 57 return orderCreateService.createOrder(orderBuilder);
  58 + }catch (Exception e){
  59 + returnStrorageEx(orderBuilder);
  60 + throw e;
56 } 61 }
  62 +
57 }catch (Exception ex){ 63 }catch (Exception ex){
58 64
59 - try{  
60 - boolean returnStorageFlag = productProxyService.returnStorage(orderBuilder.getSkup()); 65 + logger.warn("in buyer createOrder fail, need return storage SaleSkup, uid {},ordercode {},Skup {} ",
  66 + orderBuilder.getUid(), orderBuilder.getOrderCode(), orderBuilder.getSkup(), ex);
  67 + if (!(ex instanceof ServiceException)) {
  68 + //上报告警事件
  69 + //EventBusPublisher.publishEvent(new SmsAlarmEvent(OrderHanders.submit, "submit", "订单(" + order.getOrderCode() + ")创建失败"));
  70 + throw new ServiceException(ServiceError.SHOPPING_SUBMIT_ORDER_FAIL, ex);
  71 + }
  72 + throw ex;
  73 + }
  74 + }
61 75
62 - // 补库存失败,需要报警手动补库存 TODO  
63 - if (!returnStorageFlag){  
64 - logger.warn("in buyer createOrder fail, need return storage SaleSkup, uid {},ordercode {},Skup {} ",  
65 - orderBuilder.getUid(), orderBuilder.getOrderCode(), orderBuilder.getSkup());  
66 - } 76 + private void returnStrorageEx(OrderBuilder orderBuilder) {
  77 + try{
  78 + productProxyService.returnStorage(orderBuilder.getSkup());
  79 +
  80 + }catch (Exception ex0){
  81 +
  82 + CommonAlarmEventPublisher.publish("还库存失败", "ufo.product.cancelSaleSkup", "sku:["+orderBuilder.getSkup()+"]");
  83 + // 还库存失败,上报到influxdb
  84 + logger.warn("in buyer createOrder fail, return storage fail, uid {},ordercode {},Skup {}",
  85 + orderBuilder.getUid(), orderBuilder.getOrderCode(), orderBuilder.getSkup(), ex0);
67 86
68 - }catch (Exception ex0){  
69 - logger.warn("in buyer createOrder fail, return storage fail, uid {},ordercode {},Skup {}",  
70 - orderBuilder.getUid(), orderBuilder.getOrderCode(), orderBuilder.getSkup(), ex0);  
71 - }finally {  
72 - logger.warn("in buyer createOrder fail, need return storage SaleSkup, uid {},ordercode {},Skup {} ",  
73 - orderBuilder.getUid(), orderBuilder.getOrderCode(), orderBuilder.getSkup(), ex);  
74 - if (!(ex instanceof ServiceException)) {  
75 - //上报告警事件  
76 - //EventBusPublisher.publishEvent(new SmsAlarmEvent(OrderHanders.submit, "submit", "订单(" + order.getOrderCode() + ")创建失败"));  
77 - throw new ServiceException(ServiceError.SHOPPING_SUBMIT_ORDER_FAIL, ex);  
78 - }  
79 - throw ex;  
80 - }  
81 } 87 }
82 - return result;  
83 } 88 }
84 89
85 90