Sfoglia il codice sorgente

bug修改 更新订单回调状态和回调时间

张均强 4 anni fa
parent
commit
5c0bdeeff2

+ 4 - 0
common/fire-common/src/main/java/com/fire/common/constants/RocketTags.java

@@ -30,6 +30,10 @@ public class RocketTags {
      * 失败订单 修改 order状态 失败
      */
     public static final String FAIL_TAG = "fail";
+    /**
+     * 订单回调 修改 order回调状态 失败
+     */
+    public static final String CALLBACK_TAG = "callback";
     /**
      * 成功订单 修改 order状态 成功
      */

+ 19 - 0
modules/callback-customer/src/main/java/com/fire/customer/callback/service/OrderUpdateService.java

@@ -0,0 +1,19 @@
+package com.fire.customer.callback.service;
+
+
+import com.fire.dto.FlowOrderInfo;
+import com.fire.dto.MobileFlowDispatchRec;
+
+/**
+ * 客户服务层
+ *
+ * @author ZJQ 2021年6月17日15:51:14
+ */
+public interface OrderUpdateService {
+
+    /**
+     * 订单更新redis 和发送更新消息
+     */
+    void updateOrder(FlowOrderInfo orderInfo, String tag);
+
+}

+ 21 - 1
modules/callback-customer/src/main/java/com/fire/customer/callback/service/impl/CallbackCustomerServiceImpl.java

@@ -1,11 +1,13 @@
 package com.fire.customer.callback.service.impl;
 
 
+import com.fire.common.exception.BaseException;
 import com.fire.customer.callback.data.DataPool;
 import com.fire.customer.callback.dto.CallbackRequestContent;
 import com.fire.customer.callback.dto.CallbackRequestMsgBody;
 import com.fire.customer.callback.dto.CallbackRequestParam;
 import com.fire.customer.callback.service.CallbackCustomerService;
+import com.fire.customer.callback.service.OrderUpdateService;
 import com.fire.dto.FlowAppInfo;
 import com.fire.dto.FlowOrderInfo;
 import com.fire.param.HeaderDto;
@@ -17,6 +19,11 @@ import org.springframework.web.client.RestTemplate;
 
 import javax.annotation.Resource;
 import java.nio.charset.StandardCharsets;
+import java.util.Date;
+
+import static com.fire.common.constants.RocketTags.CALLBACK_TAG;
+import static com.fire.dto.enums.OrderStatus.ORDER_FAIL;
+import static com.fire.dto.enums.OrderStatus.ORDER_SUCCESS;
 
 /**
  * 向客户回调
@@ -29,6 +36,8 @@ public class CallbackCustomerServiceImpl implements CallbackCustomerService {
 
     @Resource
     private RestTemplate restTemplate;
+    @Resource
+    private OrderUpdateService orderUpdateService;
 
     @Override
     public void callbackCustomer(FlowOrderInfo orderInfo) {
@@ -65,7 +74,18 @@ public class CallbackCustomerServiceImpl implements CallbackCustomerService {
         String secretKey = DigestUtils.md5DigestAsHex(secretStr.getBytes(StandardCharsets.UTF_8));
         header.setSecretKey(secretKey);
 
-        restTemplate.postForObject(flowAppInfo.getCallbackUrl(), requestParam, String.class);
+        orderInfo.setCallbackTime(new Date());
+        try {
+            restTemplate.postForObject(flowAppInfo.getCallbackUrl(), requestParam, String.class);
+            orderInfo.setCallbackStatus(ORDER_SUCCESS.status());
+            orderUpdateService.updateOrder(orderInfo,CALLBACK_TAG);
+        } catch (Exception e) {
+            orderInfo.setCallbackStatus(ORDER_FAIL.status());
+            orderUpdateService.updateOrder(orderInfo,CALLBACK_TAG);
+            log.error("回调客户失败:", e);
+            throw new BaseException("回调失败");
+        }
+
 
     }
 }

+ 62 - 0
modules/callback-customer/src/main/java/com/fire/customer/callback/service/impl/OrderUpdateServiceImpl.java

@@ -0,0 +1,62 @@
+package com.fire.customer.callback.service.impl;
+
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fire.customer.callback.service.OrderUpdateService;
+import com.fire.dto.FlowOrderInfo;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.rocketmq.spring.core.RocketMQTemplate;
+import org.springframework.messaging.MessagingException;
+import org.springframework.messaging.support.MessageBuilder;
+import org.springframework.stereotype.Service;
+import redis.clients.jedis.JedisCluster;
+
+import javax.annotation.Resource;
+
+import static com.fire.common.constants.RocketTopic.ORDER_TOPIC;
+import static com.fire.dto.enums.RedisKey.ORDER_INFO;
+
+/**
+ * 订单更新实现层
+ *
+ * @author ZJQ 2021年6月16日17:13:54
+ */
+@Service
+@Slf4j
+public class OrderUpdateServiceImpl implements OrderUpdateService {
+
+    @Resource
+    private JedisCluster jedisCluster;
+    @Resource
+    private RocketMQTemplate rocketMQTemplate;
+
+    /**
+     * 订单更新
+     *
+     * @param orderInfo 订单详情
+     * @param tag       mq的tag
+     */
+    @Override
+    public void updateOrder(FlowOrderInfo orderInfo, String tag) {
+        Long orderId = orderInfo.getOrderId();
+        //如果订单失败 客户退款
+
+        String orderStr;
+        ObjectMapper om = new ObjectMapper();
+        try {
+            orderStr = om.writeValueAsString(orderInfo);
+            //订单转换为json更新入redis
+            long hKey = orderId / 10000000;
+            jedisCluster.hset(ORDER_INFO.key() + hKey, String.valueOf(orderId), orderStr);
+            //订单入队列
+            rocketMQTemplate.syncSendOrderly(ORDER_TOPIC + ":" + tag, MessageBuilder.withPayload(orderStr).build(), String.valueOf(orderId));
+        } catch (JsonProcessingException e) {
+            //订单转换的其他异常 如果执行到这里说明系统有bug
+            log.error("订单在更新回调状态的时候转换成json失败:", e);
+        } catch (MessagingException e1) {
+            log.error("订单在更新回调的时候发送失败:", e1);
+        }
+    }
+
+}