|
@@ -0,0 +1,82 @@
|
|
|
+package com.fdkankan.ucenter.mq.consumer;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.fdkankan.rabbitmq.util.RabbitMqProducer;
|
|
|
+import com.fdkankan.ucenter.entity.DownloadOrder;
|
|
|
+import com.fdkankan.ucenter.httpClient.vo.PayOrderVo;
|
|
|
+import com.fdkankan.ucenter.pay.strategy.impl.DownloadOrderImpl;
|
|
|
+import com.fdkankan.ucenter.pay.strategy.impl.EntityOrderImpl;
|
|
|
+import com.fdkankan.ucenter.pay.strategy.impl.IncrementOrderImpl;
|
|
|
+import com.fdkankan.ucenter.service.IIncrementOrderService;
|
|
|
+import com.rabbitmq.client.Channel;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang.StringEscapeUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.amqp.core.ExchangeTypes;
|
|
|
+import org.springframework.amqp.core.Message;
|
|
|
+import org.springframework.amqp.rabbit.annotation.Exchange;
|
|
|
+import org.springframework.amqp.rabbit.annotation.Queue;
|
|
|
+import org.springframework.amqp.rabbit.annotation.QueueBinding;
|
|
|
+import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+import sun.rmi.runtime.Log;
|
|
|
+
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Component
|
|
|
+public class OrderDownConsumer {
|
|
|
+
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ RabbitMqProducer rabbitMqProducer;
|
|
|
+ @Autowired
|
|
|
+ IncrementOrderImpl incrementOrder;
|
|
|
+ @Autowired
|
|
|
+ DownloadOrderImpl downloadOrder;
|
|
|
+ @Autowired
|
|
|
+ EntityOrderImpl entityOrder;
|
|
|
+
|
|
|
+
|
|
|
+ @RabbitListener(
|
|
|
+ queuesToDeclare = @Queue("${queue.orderPay.down-payResult:down-payResult}")
|
|
|
+ )
|
|
|
+ public void consumerQueue(Channel channel, Message message) {
|
|
|
+ try {
|
|
|
+ String messageId = message.getMessageProperties().getMessageId();
|
|
|
+ String msg = new String(message.getBody(), StandardCharsets.UTF_8);
|
|
|
+ log.info("接受下单结果mq--messageId:{},msg:{}",messageId,msg);
|
|
|
+
|
|
|
+ channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
|
|
|
+ msg = StringEscapeUtils.unescapeJava(msg);
|
|
|
+ PayOrderVo order = JSONObject.parseObject(msg, PayOrderVo.class);
|
|
|
+ if(order == null){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //更新订单状态
|
|
|
+ Integer payType = 3;
|
|
|
+ //付款方式,0表示微信,1表示支付宝,2表示paypal,3表示其他
|
|
|
+ switch (order.getPayType()){
|
|
|
+ case 0 : case 1: case 2: payType = 0;break;
|
|
|
+ case 3 : case 4: payType = 1;break;
|
|
|
+ case 5 : payType = 2;break;
|
|
|
+ }
|
|
|
+ if("incrementOrder".equals(order.getOrderType())){
|
|
|
+ incrementOrder.handleOrder(order.getOrderSn(),order.getTradeNo(),order.getOpenId(),payType,null);
|
|
|
+ }
|
|
|
+ if("downOrder".equals(order.getOrderType())){
|
|
|
+ downloadOrder.handleOrder(order.getOrderSn(),order.getTradeNo(),order.getOpenId(),payType,null);
|
|
|
+ }
|
|
|
+ if("partOrder".equals(order.getOrderType())){
|
|
|
+ entityOrder.handleOrder(order.getOrderSn(),order.getTradeNo(),order.getOpenId(),payType,null);
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+}
|