Bladeren bron

新增rabbitmq 订单延时队列

赵冬冬 4 jaren geleden
bovenliggende
commit
34fd0c394d

+ 9 - 6
carbon-h5/carbon-h5-service/src/main/java/com/hcloud/microserver/h5/config/mq/listener/ReceiverMessage.java

@@ -1,5 +1,6 @@
 package com.hcloud.microserver.h5.config.mq.listener;
 
+import com.hcloud.microserver.h5.facade.carbon.entity.GoodsOrderInfo;
 import com.hcloud.microserver.h5.facade.carbon.forms.GoodsOrderInfoForm;
 import com.hcloud.microserver.h5.config.mq.MQConstant;
 import com.hcloud.microserver.h5.service.OrderDetailInfoService;
@@ -8,6 +9,7 @@ import org.springframework.amqp.rabbit.annotation.RabbitHandler;
 import org.springframework.amqp.rabbit.annotation.RabbitListener;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
+import org.springframework.util.StringUtils;
 
 //监听hello队列,有消息时进行消费
 @Component
@@ -26,12 +28,13 @@ public class ReceiverMessage {
         String[] split = content.split("-");
         if(split.length>1){
             String orderId = split[1];
-            GoodsOrderInfoForm orderInfoBO = orderDetailInfoService.info(orderId);
-
-            Integer orderStatus = orderInfoBO.getOrderStatus();
-            if(orderStatus.intValue() ==1){
-                orderInfoService.rollbackOrderInfo(orderId);
-                System.out.println("取消订单:" + content);
+            GoodsOrderInfo goodsOrderInfo = orderInfoService.selectByPrimaryKey(orderId);
+            if(!StringUtils.isEmpty(goodsOrderInfo)){
+                Integer orderStatus = goodsOrderInfo.getOrderStatus();
+                if(orderStatus.intValue() ==1){
+                    orderInfoService.rollbackOrderInfo(orderId);
+                    System.out.println("取消订单:" + content);
+                }
             }
 
         }

+ 12 - 9
carbon-h5/carbon-h5-service/src/main/java/com/hcloud/microserver/h5/service/impl/OrderInfoServiceImpl.java

@@ -358,15 +358,18 @@ public class OrderInfoServiceImpl implements OrderInfoService {
                 BigDecimal saleCarbon = bean.getSaleNum();
                 String goodsGuid = bean.getFkGoodsGuid();
                 GoodsSaleInfoForm goodsSaleInfoForm = orderSaleInfoService.getGoodsSaleInfoByGoodsId(goodsGuid);
-                BigDecimal saledCarbonSkin = goodsSaleInfoForm.getSaledCarbonSkin().subtract(saleCarbon);
-                BigDecimal unSaleCarbonSkin = goodsSaleInfoForm.getUnsaledCarbonSkin().add(saleCarbon);
-                goodsSaleInfoForm.setSaledCarbonSkin(saledCarbonSkin);
-                goodsSaleInfoForm.setUnsaledCarbonSkin(unSaleCarbonSkin);
-                goodsSaleInfoForm.setModifiedTime(new Date());
-                int h = orderSaleInfoService.modifiedOrderSaleInfo(goodsSaleInfoForm);
-                if (h == 0) {
-                    throw new RuntimeException();
+                if(!StringUtils.isEmpty(goodsSaleInfoForm)){
+                    BigDecimal saledCarbonSkin = goodsSaleInfoForm.getSaledCarbonSkin().subtract(saleCarbon);
+                    BigDecimal unSaleCarbonSkin = goodsSaleInfoForm.getUnsaledCarbonSkin().add(saleCarbon);
+                    goodsSaleInfoForm.setSaledCarbonSkin(saledCarbonSkin);
+                    goodsSaleInfoForm.setUnsaledCarbonSkin(unSaleCarbonSkin);
+                    goodsSaleInfoForm.setModifiedTime(new Date());
+                    int h = orderSaleInfoService.modifiedOrderSaleInfo(goodsSaleInfoForm);
+                    if (h == 0) {
+                        throw new RuntimeException();
+                    }
                 }
+
             }
         }
         //取消离线支付订单
@@ -572,7 +575,7 @@ public class OrderInfoServiceImpl implements OrderInfoService {
         //新增小定单
         goodsOrderDetailMapper.batchSaveOrderDetailList(dataList);
 
-        String message = "order-" + goodsOrderInfo.getGuid();
+        String message = "order-" +orderId;
         //延时消息队列
         messageService.send(MQConstant.HELLO_QUEUE_NAME, message, 60000);
         return goodsOrderInfo;