yujian
2020-03-18 47f034b4239ac0865560953e9f6edafa487b0fb9
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
package com.yeshi.fanli.util.rocketmq.consumer.user;
 
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.order.OrderTopicTagEnum;
import com.yeshi.fanli.dto.mq.order.body.OrderMoneyRecievedMQMsg;
import com.yeshi.fanli.dto.mq.user.UserTopicTagEnum;
import com.yeshi.fanli.dto.mq.user.body.UserInviteMQMsg;
import com.yeshi.fanli.log.LogHelper;
import com.yeshi.fanli.service.inter.user.vip.UserVIPPreInfoService;
import com.yeshi.fanli.util.rocketmq.MQTopicName;
 
/**
 * 用户超级会员
 * 
 * @author Administrator
 *
 */
@Component 
public class UserVIPMessageListener implements MessageListener {
 
    @Resource
    private UserVIPPreInfoService userVIPPreInfoService;
 
    @Override
    public Action consume(Message message, ConsumeContext context) {
        
        LogHelper.mqInfo("consumer-UserVIPMessageListener", message.getMsgID(), message.getTopic(),
                message.getTag(), new String(message.getBody()));
        String tag = message.getTag();
        if (tag == null)
            tag = "";
 
        // 邀请相关
        if (MQTopicName.TOPIC_USER.name().equalsIgnoreCase(message.getTopic())) {
            // 邀请成功
            if (tag.equalsIgnoreCase(UserTopicTagEnum.inviteSuccess.name())) {
                UserInviteMQMsg msg = new Gson().fromJson(new String(message.getBody()),UserInviteMQMsg.class);
                // 会员等级升级
                userVIPPreInfoService.verifyVipPreInfo(msg.getBossId(), true);
            }
        }
        
        // 订单到账相关
        if (tag.equalsIgnoreCase(OrderTopicTagEnum.orderFanLiActual.name())) {
            OrderMoneyRecievedMQMsg dto = new Gson().fromJson(new String(message.getBody()),
                    OrderMoneyRecievedMQMsg.class);
            if (dto != null) {
                if (dto.getType() == OrderMoneyRecievedMQMsg.TYPE_ZIGOU) {// 自购到账
                    // 会员等级升级
                    userVIPPreInfoService.verifyVipPreInfo(dto.getUid(), false);
                } else if (dto.getType() == OrderMoneyRecievedMQMsg.TYPE_SHARE) {// 分享到账
                    // 会员等级升级
                    userVIPPreInfoService.verifyVipPreInfo(dto.getUid(), false);
                }
            }
        }
        
        return Action.CommitMessage;
    }
}