yujian
2019-11-15 dbc8f0b2058d809e6dad0ada92d391109cbb4f57
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package com.yeshi.fanli.util.rocketmq.consumer.order;
 
import javax.annotation.Resource;
 
import org.springframework.stereotype.Component;
 
import com.aliyun.openservices.ons.api.Action;
import com.aliyun.openservices.ons.api.ConsumeContext;
import com.aliyun.openservices.ons.api.Message;
import com.aliyun.openservices.ons.api.MessageListener;
import com.google.gson.Gson;
import com.yeshi.fanli.dto.mq.BaseMQMsgBody;
import com.yeshi.fanli.dto.mq.order.OrderTopicTagEnum;
import com.yeshi.fanli.dto.mq.order.body.BanLiShopOrderMQMsg;
import com.yeshi.fanli.entity.shop.BanLiShopOrder;
import com.yeshi.fanli.exception.shop.BanLiShopOrderException;
import com.yeshi.fanli.log.LogHelper;
import com.yeshi.fanli.service.inter.shop.BanLiShopOrderPayService;
import com.yeshi.fanli.service.inter.shop.BanLiShopOrderService;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.rocketmq.MQTopicName;
 
/**
 * 邀请订单补贴消息消费
 * 
 * @author Administrator
 *
 */
@Component
public class BanLiShopOrderMessageListener implements MessageListener {
 
    @Resource
    private BanLiShopOrderService banLiShopOrderService;
 
    @Resource
    private BanLiShopOrderPayService banLiShopOrderPayService;
 
    public BanLiShopOrderMessageListener() {
 
    }
 
    @Override
    public Action consume(Message message, ConsumeContext context) {
        
        LogHelper.mqInfo("consumer:BanLiShopOrderMessageListener",message.getMsgID(), message.getTopic(), message.getTag(),
                new String(message.getBody()));
        String tag = message.getTag();
 
        if (MQTopicName.TOPIC_ORDER.name().equalsIgnoreCase(message.getTopic())) {
            if (OrderTopicTagEnum.banLiShopOrderDelay.name().equalsIgnoreCase(tag)) {
                BanLiShopOrderMQMsg banLiShopOrderMQMsg = new Gson().fromJson(new String(message.getBody()),
                        BanLiShopOrderMQMsg.class);
                if (banLiShopOrderMQMsg != null)
                    // 使订单失效
                    banLiShopOrderService.invalidOrderByOrderId(banLiShopOrderMQMsg.getOrderId(), "订单失效-长期未付款");
                return Action.CommitMessage;
            } else if (tag.equalsIgnoreCase(OrderTopicTagEnum.banLiShopOrderPaid.name()))// 商城订单付款成功
            {
                BanLiShopOrderMQMsg msg = new Gson().fromJson(new String(message.getBody()), BanLiShopOrderMQMsg.class);
                BanLiShopOrder banLiOrder = banLiShopOrderService.selectByPrimaryKey(msg.getOrderId());
                try {
                    banLiShopOrderPayService.payOrderByMoney(banLiOrder.getId(), banLiOrder.getMoneyPayment());
                } catch (BanLiShopOrderException e) {
                    e.printStackTrace();
                }
                return Action.CommitMessage;
            } else if (tag.equalsIgnoreCase(OrderTopicTagEnum.banLiShopOrderRefund.name()))// 商城退款订阅
            {
                BanLiShopOrderMQMsg msg = new Gson().fromJson(new String(message.getBody()), BanLiShopOrderMQMsg.class);
                try {
                    banLiShopOrderPayService.refund(msg.getOrderId());
                } catch (BanLiShopOrderException e) {
                }
                return Action.CommitMessage;
            }
            
        }
        return Action.CommitMessage;
    }
 
}