admin
2020-04-27 ea0bfe5df22fe982fb75843b34fcf6d8ab456728
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package com.yeshi.fanli.util.rocketmq.consumer.user;
 
import java.util.HashSet;
import java.util.List;
import java.util.Set;
 
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.user.UserTopicTagEnum;
import com.yeshi.fanli.dto.mq.user.body.InviteCodeActiveMQMsg;
import com.yeshi.fanli.entity.bus.user.UserInfo;
import com.yeshi.fanli.entity.bus.user.vip.TearcherInfo;
import com.yeshi.fanli.log.LogHelper;
import com.yeshi.fanli.service.inter.user.UserInfoService;
import com.yeshi.fanli.service.inter.user.invite.ThreeSaleSerivce;
import com.yeshi.fanli.service.inter.user.vip.TearcherService;
import com.yeshi.fanli.util.rocketmq.MQTopicName;
 
import net.sf.json.JSONObject;
 
/**
 * 用户超级会员
 * 
 * @author Administrator
 *
 */
@Component
public class TearcherMessageListener implements MessageListener {
 
    @Resource
    private ThreeSaleSerivce threeSaleSerivce;
 
    @Resource
    private TearcherService tearcherService;
 
    @Resource
    private UserInfoService userInfoService;
 
    private static Set<Long> officialUids = null;
 
    @Override
    public Action consume(Message message, ConsumeContext context) {
        LogHelper.mqInfo("consumer-TearcherMessageListener", message.getMsgID(), message.getTopic(), message.getTag(),
                new String(message.getBody()));
        String tag = message.getTag();
        if (tag == null)
            tag = "";
        String topic = message.getTopic();
 
        if (MQTopicName.TOPIC_USER.name().equalsIgnoreCase(topic)) {
 
            // 邀请激活
            if (tag.equalsIgnoreCase(UserTopicTagEnum.inviteCodeActive.name())) {
 
                JSONObject json = JSONObject.fromObject(new String(message.getBody()));
 
                InviteCodeActiveMQMsg inviteCodeActiveMQMsg = new Gson().fromJson(json.toString(),
                        InviteCodeActiveMQMsg.class);
                if (inviteCodeActiveMQMsg != null) {
                    // 顶级为测试用户的全部分配官方导师微信
 
                    // 获取顶级boss
                    Long bossId = threeSaleSerivce.getTopBoss(inviteCodeActiveMQMsg.getUid());
                    if (bossId != null) {
 
                        if (officialUids == null) {
                            officialUids = new HashSet<>();
                            List<UserInfo> userList = userInfoService.listByType(1, 1, 10000);
 
                            for (UserInfo user : userList)
                                officialUids.add(user.getId());
                        }
 
                        if (officialUids.contains(bossId)) {
                            List<TearcherInfo> tearcherList = tearcherService.listByType(TearcherInfo.TYPE_OFFICIAL, 1,
                                    1);
                            if (tearcherList != null && tearcherList.size() > 0) {
                                tearcherService.addUserTearcherMap(tearcherList.get(0).getId(),
                                        inviteCodeActiveMQMsg.getUid());
                            }
                        }
                    }
                }
            }
        }
 
        return Action.CommitMessage;
    }
}