admin
2025-02-25 30d8e227e8d823b6c38c3b9c90ac2df03b63befe
fanli/src/main/java/com/yeshi/fanli/util/rocketmq/consumer/user/TearcherMessageListener.java
@@ -1,107 +1,107 @@
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.dto.mq.user.body.UserActiveMQMsg;
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) {
               // 顶级为测试用户的全部分配官方导师微信
               initTearcher(inviteCodeActiveMQMsg.getUid());
            }
         } else if (tag.equalsIgnoreCase(UserTopicTagEnum.userActve.name())) {
            UserActiveMQMsg userActiveMQMsg = new Gson().fromJson(new String(message.getBody()),
                  UserActiveMQMsg.class);
            if (userActiveMQMsg != null) {
               initTearcher(userActiveMQMsg.getUid());
            }
         }
      }
      return Action.CommitMessage;
   }
   private void initTearcher(Long uid) {
      if (tearcherService.selectByUid(uid) != null)
         return;
      // 获取顶级boss
      Long bossId = threeSaleSerivce.getTopBoss(uid);
      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(), uid);
            }
         }
      }
   }
}
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.dto.mq.user.body.UserActiveMQMsg;
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) {
               // 顶级为测试用户的全部分配官方导师微信
               initTearcher(inviteCodeActiveMQMsg.getUid());
            }
         } else if (tag.equalsIgnoreCase(UserTopicTagEnum.userActve.name())) {
            UserActiveMQMsg userActiveMQMsg = new Gson().fromJson(new String(message.getBody()),
                  UserActiveMQMsg.class);
            if (userActiveMQMsg != null) {
               initTearcher(userActiveMQMsg.getUid());
            }
         }
      }
      return Action.CommitMessage;
   }
   private void initTearcher(Long uid) {
      if (tearcherService.selectByUid(uid) != null)
         return;
      // 获取顶级boss
      Long bossId = threeSaleSerivce.getTopBoss(uid);
      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(), uid);
            }
         }
      }
   }
}