yujian
2020-04-27 d5c2554ebae75afbff31c3c2966cc3a747ba941c
fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserInfoExtraServiceImpl.java
@@ -54,6 +54,7 @@
import com.yeshi.fanli.service.inter.user.UserInviteRecordService;
import com.yeshi.fanli.service.inter.user.UserRankService;
import com.yeshi.fanli.service.inter.user.invite.ThreeSaleSerivce;
import com.yeshi.fanli.service.inter.user.msg.UserAccountMsgNotificationService;
import com.yeshi.fanli.service.inter.user.notify.UserActivedRecordService;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.FilePathEnum;
@@ -103,6 +104,9 @@
   @Resource
   @Lazy
   private UserActivedRecordService userActivedRecordService;
   @Resource
   private UserAccountMsgNotificationService userAccountMsgNotificationService;
   @Resource(name = "producer")
   private Producer producer;
@@ -354,48 +358,14 @@
         throw new UserInfoExtraException(1, "已经激活, 无需再次激活");
      inviteCode = inviteCode.toUpperCase();
      // 邀请码对应用户信息
      UserInfo inviter = userInfoService.getUserInfoByInviteCode(inviteCode);
      if (inviter == null)
      UserInfo boss = userInfoService.getUserInfoByInviteCode(inviteCode);
      if (boss == null || boss.getState() != UserInfo.STATE_NORMAL)
         throw new UserInfoExtraException(1, "上级邀请码不存在");
      // 绑定关系
      try {
         threeSaleSerivce.bindRelationshipByInviteCode(invitee, inviter);
      } catch (ThreeSaleException e) {
         try {
            LogHelper.errorDetailInfo(e);
         } catch (Exception e1) {
            e1.printStackTrace();
         }
         throw new UserInfoExtraException(1, "激活失败");
      }
      // 生成邀请码
      String mycode = createInviteCode(uid);
      if (StringUtil.isNullOrEmpty(mycode))
         throw new UserInfoExtraException(1, "激活码生成失败");
      UserInfoExtra userInfoExtra = new UserInfoExtra();
      userInfoExtra.setUserInfo(invitee);
      userInfoExtra.setInviteCode(mycode);
      userInfoExtra.setUpdateTime(new Date());
      if (extra != null) {
         userInfoExtra.setId(extra.getId());
         userInfoExtraMapper.updateByPrimaryKeySelective(userInfoExtra);
      } else {
         userInfoExtra.setCreateTime(new Date());
         userInfoExtraMapper.insertSelective(userInfoExtra);
      }
      userActivedRecordService.add(new UserActivedRecord(uid));
      if (!Constant.IS_TEST) { // 发送激活成功消息
         Message message = MQMsgBodyFactory.create(MQTopicName.TOPIC_USER, UserTopicTagEnum.inviteCodeActive,
               new Gson().toJson(new InviteCodeActiveMQMsg(uid, new Date())));
         producer.send(message);
      }
      return mycode;
      // 生成邀请关系
      return inviteCodeActive(uid, boss.getId());
   }
   @Override
@@ -479,43 +449,14 @@
      Long inviterId = userInviteRecordService.getNewestInviterId(wxUnionId);
      if (inviterId == null)
         throw new UserInfoExtraException(1, "没有对应的邀请关系");
      // 绑定关系
      try {
         threeSaleSerivce.bindRelationshipByWX(invitee, inviterId);
      } catch (ThreeSaleException e) {
         try {
            LogHelper.errorDetailInfo(e);
         } catch (Exception e1) {
            e1.printStackTrace();
         }
         throw new UserInfoExtraException(1, "关系绑定时失败");
      }
      // 生成邀请码
      String inviteCode = createInviteCode(uid);
      if (StringUtil.isNullOrEmpty(inviteCode))
         throw new UserInfoExtraException(1, "激活码生成失败");
      UserInfoExtra userInfoExtra = new UserInfoExtra();
      userInfoExtra.setUserInfo(invitee);
      userInfoExtra.setInviteCode(inviteCode);
      userInfoExtra.setUpdateTime(new Date());
      if (extra != null) {
         userInfoExtra.setId(extra.getId());
         userInfoExtraMapper.updateByPrimaryKeySelective(userInfoExtra);
      } else {
         userInfoExtra.setCreateTime(new Date());
         userInfoExtraMapper.insertSelective(userInfoExtra);
      }
      userActivedRecordService.add(new UserActivedRecord(uid));
      
      if (!Constant.IS_TEST) { // 发送激活成功消息
         Message message = MQMsgBodyFactory.create(MQTopicName.TOPIC_USER, UserTopicTagEnum.inviteCodeActive,
               new Gson().toJson(new InviteCodeActiveMQMsg(uid, new Date())));
         producer.send(message);
      UserInfo boss = userInfoService.selectByPKey(inviterId);
      if (boss == null || boss.getState() != UserInfo.STATE_NORMAL) {
         throw new UserInfoExtraException(1, "没有对应的邀请关系");
      }
      // 邀请码激活
      inviteCodeActive(uid, boss.getId());
   }
   @Override
@@ -529,15 +470,6 @@
      UserInfo invitee = userInfoService.selectByPKey(uid);
      if (invitee == null) {
         throw new UserInfoExtraException(1, "用户不存在");
      }
      // 用户额外信息
      UserInfoExtra extra = userInfoExtraMapper.getInfoExtraByUid(uid);
      if (extra != null) {
         String inviteCodeHas = extra.getInviteCode();
         if (inviteCodeHas != null && inviteCodeHas.trim().length() > 0) {
            throw new UserInfoExtraException(1, "已经激活, 无需再次激活");
         }
      }
      String wxUnionId = weiXinUser.getUnionid();
@@ -602,10 +534,33 @@
      if (inviterId == null) {
         throw new UserInfoExtraException(1, "没有对应的邀请关系");
      }
      UserInfo boss = userInfoService.selectByPKey(inviterId);
      if (boss == null || boss.getState() != UserInfo.STATE_NORMAL) {
         throw new UserInfoExtraException(1, "没有对应的邀请关系");
      }
      // 邀请码激活
      inviteCodeActive(uid, boss.getId());
   }
   /**
    * 邀请关系生成激活码
    * @param uid
    * @param bossId
    * @return
    * @throws UserInfoExtraException
    */
   private String inviteCodeActive(Long uid, Long bossId) throws UserInfoExtraException{
      UserInfoExtra extra = userInfoExtraMapper.getInfoExtraByUid(uid);
      if (extra != null && !StringUtil.isNullOrEmpty(extra.getInviteCode())) {
         throw new UserInfoExtraException(1, "已经激活, 无需再次激活");
      }
      // 绑定关系
      try {
         threeSaleSerivce.bindRelationshipByWX(invitee, inviterId);
         threeSaleSerivce.bindInviteRelationship(uid, bossId);
      } catch (ThreeSaleException e) {
         try {
            LogHelper.errorDetailInfo(e);
@@ -617,12 +572,11 @@
      // 生成邀请码
      String inviteCode = createInviteCode(uid);
      ;
      if (StringUtil.isNullOrEmpty(inviteCode))
         throw new UserInfoExtraException(1, "激活码生成失败");
      UserInfoExtra userInfoExtra = new UserInfoExtra();
      userInfoExtra.setUserInfo(invitee);
      userInfoExtra.setUserInfo(new UserInfo(uid));
      userInfoExtra.setInviteCode(inviteCode);
      userInfoExtra.setUpdateTime(new Date());
      if (extra != null) {
@@ -635,12 +589,16 @@
      
      userActivedRecordService.add(new UserActivedRecord(uid));
      if (!Constant.IS_TEST) { // 发送激活成功消息
//      if (!Constant.IS_TEST) { // 发送激活成功消息
         Message message = MQMsgBodyFactory.create(MQTopicName.TOPIC_USER, UserTopicTagEnum.inviteCodeActive,
               new Gson().toJson(new InviteCodeActiveMQMsg(uid, new Date())));
               new InviteCodeActiveMQMsg(uid, new Date()));
         producer.send(message);
      }
//      }
      return inviteCode;
   }
   @Override
   public void updateActiveTime(Long uid, Date date) {
@@ -782,6 +740,10 @@
      UserInfo inviter = userInfoService.getUserInfoByInviteCode(inviteCode);
      if (inviter == null)
         throw new UserInfoExtraException(1, "上级邀请码不存在");
      if (inviter.getState() != UserInfo.STATE_NORMAL) {
         throw new UserInfoExtraException(1, "上级邀请码不存在");
      }
      return inviter;
   }
@@ -828,6 +790,11 @@
      if (inviter == null) {
         throw new UserInfoExtraException(1, "对应的邀请关系不存在");
      }
      if (inviter.getState() != UserInfo.STATE_NORMAL) {
         throw new UserInfoExtraException(1, "对应的邀请关系不存在");
      }
      return inviter;
   }
@@ -874,10 +841,13 @@
      if (!Constant.IS_TEST) { // 发送邀请码更改成功的消息
         Message message = MQMsgBodyFactory.create(MQTopicName.TOPIC_USER, UserTopicTagEnum.userInfoUpdate,
               new Gson().toJson(new UserInfoUpdateMQMsg(uid, UserInfoUpdateTypeEnum.inviteCode, inviteCodeVip,
                     new Date())));
               new UserInfoUpdateMQMsg(uid, UserInfoUpdateTypeEnum.inviteCode, inviteCodeVip,
                     new Date()));
         producer.send(message);
      }
      // 消息
      userAccountMsgNotificationService.createChangeInviteCode(uid, extra.getInviteCode(), inviteCodeVip);
   }
   @Override