yanlong 8 ヶ月 前
コミット
37f66f8a10

+ 27 - 0
src/main/java/com/tuigai/tuigai_tongcheng_api/config/RabbitMqConfig.java

@@ -174,5 +174,32 @@ public class RabbitMqConfig {
         return BindingBuilder.bind(queue).to(exchange).with(ORDER_PRINT_QUEUE_ROUTING_KEY);
     }
 
+
+
+    /***************同程回调mq*********************/
+    public static final String TRAINTC_ORDER_EXCHANGE_NAME = "new.traintc.order.exchange";
+    //来单邮件回调更新报价队列
+    public static final String TRAINTC_ORDER_QUEUE_NAME = "new.traintc.order.queue";
+    //来单邮件回调更新报价路由key
+    public static final String TRAINTC_ORDER_QUEUE_ROUTING_KEY = "new.traintc.order.queue.routingkey";
+
+    // 声明 来单邮件回调更新报价 Exchange
+    @Bean("traintcOrderExchange")
+    public DirectExchange traintcOrderExchange() {
+        return new DirectExchange(TRAINTC_ORDER_EXCHANGE_NAME);
+    }
+
+    //申明 来单邮件回调更新报价队列
+    @Bean("traintcOrderQueue")
+    public Queue traintcOrderQueueName() {
+        return new Queue(TRAINTC_ORDER_QUEUE_NAME);
+    }
+
+    @Bean
+    public Binding traintcorderExchangeBingding(@Qualifier("traintcOrderQueue") Queue queue,
+                                                @Qualifier("traintcOrderExchange") DirectExchange exchange) {
+        return BindingBuilder.bind(queue).to(exchange).with(TRAINTC_ORDER_QUEUE_ROUTING_KEY);
+    }
+
 }
 

+ 47 - 0
src/main/java/com/tuigai/tuigai_tongcheng_api/consumer/MsgConsumer.java

@@ -0,0 +1,47 @@
+package com.tuigai.tuigai_tongcheng_api.consumer;
+
+import com.alibaba.fastjson.JSONObject;
+import com.rabbitmq.client.Channel;
+
+import com.tuigai.tuigai_tongcheng_api.config.RabbitMqConfig;
+import com.tuigai.tuigai_tongcheng_api.consumer.service.MsgConsumerService;
+import com.tuigai.tuigai_tongcheng_api.model.OrderOptLog;
+import com.tuigai.tuigai_tongcheng_api.service.OrderOptLogServiceImpl;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.amqp.core.Message;
+import org.springframework.amqp.rabbit.annotation.RabbitListener;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.io.IOException;
+import java.util.Date;
+
+@Component
+@Slf4j
+public class MsgConsumer {
+
+    @Autowired
+    private OrderOptLogServiceImpl orderOptLogService;
+
+    @Autowired
+    private MsgConsumerService msgConsumerService;
+
+    @RabbitListener(queues = RabbitMqConfig.TRAINTC_ORDER_QUEUE_NAME)
+    public void dealTrainSLOrder(Message message, Channel channel) throws IOException {
+        //解析得到对象
+        String mes = new String(message.getBody(), "utf-8");
+        log.info("接收差旅订单推送处理:{}", mes);
+        JSONObject jsonObject = JSONObject.parseObject(mes);
+        try {
+            msgConsumerService.callbackOrder(jsonObject);
+        } catch (Exception e) {
+            log.info("回调差旅出现了异常 {}", jsonObject, e);
+            OrderOptLog optLog = new OrderOptLog().init(new Date(), jsonObject.getString("outId"));
+            optLog.optDesc = "回填异常";
+            orderOptLogService.addOrderOptLog(optLog);
+        } finally {
+            //最终手动确认消费
+            channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
+        }
+    }
+}

+ 13 - 0
src/main/java/com/tuigai/tuigai_tongcheng_api/consumer/service/MsgConsumerService.java

@@ -0,0 +1,13 @@
+package com.tuigai.tuigai_tongcheng_api.consumer.service;
+
+import com.alibaba.fastjson.JSONObject;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+
+@Slf4j
+@Service
+public class MsgConsumerService {
+    public void callbackOrder(JSONObject jsonObject) {
+
+    }
+}

+ 26 - 20
src/main/java/com/tuigai/tuigai_tongcheng_api/service/OrderService.java

@@ -6,12 +6,14 @@ import com.tuigai.tuigai_tongcheng_api.model.RefoundTrainOrder;
 import com.tuigai.tuigai_tongcheng_api.msg.MessageSender;
 import com.tuigai.tuigai_tongcheng_api.redis.StringRedisService;
 import com.tuigai.tuigai_tongcheng_api.utils.RefundOrderUtils;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.io.IOException;
 
 @Service
+@Slf4j
 public class OrderService {
 
     @Autowired
@@ -30,29 +32,33 @@ public class OrderService {
     private MessageSender messageSender;
 
 
-    public void saveRefundOrder(String decodeStr) throws IOException {
+    public void saveRefundOrder(String decodeStr) {
         JSONArray jsonArray = JSONArray.parseArray(decodeStr);
         for (Object json : jsonArray) {
-            JSONObject jsonObject = (JSONObject) json;
-            JSONObject refundOrderJson = jsonObject.getJSONObject("refundOrderJson");
-            String outId = refundOrderJson.getString("refundSerialNo");
-            String key = StringRedisService.REFUND_HANDLE_ORDER + outId;
-            if (redisService.isExistKey(key)) {
-                continue;
+            try {
+                JSONObject jsonObject = (JSONObject) json;
+                JSONObject refundOrderJson = jsonObject.getJSONObject("refundOrder");
+                String outId = refundOrderJson.getString("refundSerialNo");
+                String key = StringRedisService.REFUND_HANDLE_ORDER + outId;
+                if (redisService.isExistKey(key)) {
+                    continue;
+                }
+                RefoundTrainOrder refoundTrainOrder = RefundOrderUtils.generateRefundOrder(jsonObject);
+                //保存退票行程信息
+                refoundSegmentService.addRefoundSegment(refoundTrainOrder.getRefoundSegmentList());
+                //保存退票乘客信息
+                refoundPassengerService.addRefoundPasengerBatch(refoundTrainOrder.getRefoundPasengerList());
+                //保存退票订单信息
+                refoundTrainOrderService.addRefoundTrainOrder(refoundTrainOrder);
+                redisService.setStringAndLive(key, "1", 24 * 60 * 60);
+
+                //发送派单消息
+                JSONObject msgJson = new JSONObject();
+                msgJson.put("outId", outId);
+                messageSender.newAllocateMag(msgJson.toJSONString());
+            } catch (Exception e) {
+                log.error("异常", e);
             }
-            RefoundTrainOrder refoundTrainOrder = RefundOrderUtils.generateRefundOrder(jsonObject);
-            //保存退票行程信息
-            refoundSegmentService.addRefoundSegment(refoundTrainOrder.getRefoundSegmentList());
-            //保存退票乘客信息
-            refoundPassengerService.addRefoundPasengerBatch(refoundTrainOrder.getRefoundPasengerList());
-            //保存退票订单信息
-            refoundTrainOrderService.addRefoundTrainOrder(refoundTrainOrder);
-            redisService.setStringAndLive(key, "1", 24 * 60 * 60);
-
-            //发送派单消息
-            JSONObject msgJson = new JSONObject();
-            msgJson.put("outId", outId);
-            messageSender.newAllocateMag(msgJson.toJSONString());
         }
     }
 

+ 18 - 8
src/main/java/com/tuigai/tuigai_tongcheng_api/utils/RefundOrderUtils.java

@@ -9,31 +9,41 @@ import com.tuigai.tuigai_tongcheng_api.enums.OrderSourceEnum;
 import com.tuigai.tuigai_tongcheng_api.model.RefoundPasenger;
 import com.tuigai.tuigai_tongcheng_api.model.RefoundSegment;
 import com.tuigai.tuigai_tongcheng_api.model.RefoundTrainOrder;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
 
 import java.io.IOException;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
 
+@Slf4j
 public class RefundOrderUtils {
 
-    public static String url = "https://console-docs.apipost.cn/preview/6b1028452d54a34a/5a0d52a660d075c6";
+    public static String url = "http://8.218.227.156:8010/post/refund/id";
 
     public static RefoundTrainOrder generateRefundOrder(JSONObject jsonObject) throws IOException {
         JSONObject refundPassengerJson = jsonObject.getJSONObject("refundPassenger");
-        JSONObject refundOrderJson = jsonObject.getJSONObject("refundOrderJson");
-        JSONObject refundSegmentJson = jsonObject.getJSONObject("refundSegmentJson");
+        JSONObject refundOrderJson = jsonObject.getJSONObject("refundOrder");
+        JSONObject refundSegmentJson = jsonObject.getJSONObject("refundSegment");
         String orderId = refundOrderJson.getString("orderSerialNo");
         Float ticketPrice = refundOrderJson.getFloat("ticketPrice");
         String ticketNo = refundOrderJson.getString("electronicTicketNo");
         String outId = refundOrderJson.getString("refundSerialNo");
         //请求身份证
         Map<String, Object> param = new HashMap<>();
-        param.put("refundserialNo", outId);
-        param.put("partitionKey", orderId);
+        param.put("refundSerialNo", outId);
+        param.put("partitionKey", refundOrderJson.getString("partitionKey"));
         param.put("ticketPrice", ticketPrice);
         String result = OkHttpUtil.doPostRequest(url, JSONObject.toJSONString(param));
-        JSONObject resultJson = JSONObject.parseObject(result);
+        log.info("result", result);
+        JSONObject resultJson = null;
+        try {
+            resultJson = Utils.isEmpty(result) || "null".equals(result) ? new JSONObject() : JSONObject.parseObject(result);
+        } catch (Exception e) {
+            log.error("订单id:{}", orderId, e);
+            resultJson = new JSONObject();
+        }
         String creditNo = resultJson.getString("creditNo");
 
         //乘客信息
@@ -67,8 +77,8 @@ public class RefundOrderUtils {
         RefoundSegment refoundSegment = new RefoundSegment();
         refoundSegment.outId = outId;
         refoundSegment.orderId = orderId;
-        refoundSegment.from_station = resultJson.getString("departureStation");
-        refoundSegment.to_station = resultJson.getString("arrivalStation");
+        refoundSegment.from_station = UnicodeUtil.toString(refundSegmentJson.getString("departureStation"));
+        refoundSegment.to_station = UnicodeUtil.toString(refundSegmentJson.getString("arrivalStation"));
         refoundSegment.from_time = DateUtil.formatDateTime(new Date(refundSegmentJson.getLong("gmtDeparture")));
         refoundSegment.to_time = DateUtil.formatDateTime(new Date(refundSegmentJson.getLong("gmtArrive")));
         refoundSegment.trainCode = refundSegmentJson.getString("trainCode");