admin
2020-07-14 eec7e789a87863c25d92c10ad5dfc22ad80c448d
fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserInfoExtraServiceImpl.java
@@ -15,6 +15,8 @@
import javax.annotation.Resource;
import com.yeshi.fanli.entity.SystemEnum;
import com.yeshi.fanli.util.*;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -27,7 +29,6 @@
import com.aliyun.openservices.ons.api.Message;
import com.aliyun.openservices.ons.api.Producer;
import com.google.gson.Gson;
import com.yeshi.fanli.dao.mybatis.user.UserInfoExtraMapper;
import com.yeshi.fanli.dao.mybatis.user.UserRankRecordMapper;
import com.yeshi.fanli.dto.mq.user.UserTopicTagEnum;
@@ -54,11 +55,9 @@
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;
import com.yeshi.fanli.util.InviteCodeFilterUtil;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.service.manger.msg.RocketMQManager;
import com.yeshi.fanli.util.account.UserUtil;
import com.yeshi.fanli.util.rocketmq.MQMsgBodyFactory;
import com.yeshi.fanli.util.rocketmq.MQTopicName;
@@ -103,9 +102,12 @@
   @Resource
   @Lazy
   private UserActivedRecordService userActivedRecordService;
   @Resource
   private UserAccountMsgNotificationService userAccountMsgNotificationService;
   @Resource(name = "producer")
   private Producer producer;
   @Resource
   private RocketMQManager rocketMQManager;
   @Override
   public UserInfoExtraVO getRankInfo(Long uid) throws UserInfoExtraException, Exception {
@@ -115,11 +117,13 @@
         throw new UserInfoExtraException(1, "用户附加信息不存在");
      }
      SystemEnum system= userInfoService.getUserSystem(uid);
      // 等级对照表
      String contrast = configService.get(ConfigKeyEnum.userRankContrast.getKey());
      String contrast = configService.getValue(ConfigKeyEnum.userRankContrast.getKey(),system);
      extraVO.setRankContrast(contrast);
      // 特别提醒
      String rankTip = configService.get(ConfigKeyEnum.userRankTip.getKey());
      String rankTip = configService.getValue(ConfigKeyEnum.userRankTip.getKey(),system);
      extraVO.setRankTip(rankTip);
      Integer rankOrderNum = extraVO.getRankOrderNum();
@@ -354,48 +358,14 @@
         throw new UserInfoExtraException(1, "已经激活, 无需再次激活");
      inviteCode = inviteCode.toUpperCase();
      // 邀请码对应用户信息
      UserInfo inviter = userInfoService.getUserInfoByInviteCode(inviteCode);
      if (inviter == null || inviter.getState() != UserInfo.STATE_NORMAL)
      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
@@ -426,7 +396,7 @@
      // 验证数据
      String wxUnionIdExist = invitee.getWxUnionId();
      if (StringUtil.isNullOrEmpty(wxUnionIdExist)) {
         UserInfo newUser = userInfoService.getEffectiveUserInfoByWXUnionId(weiXinUser.getUnionid());
         UserInfo newUser = userInfoService.getEffectiveUserInfoByWXUnionId(weiXinUser.getUnionid(),invitee.getSystem());
         if (newUser != null) {
            throw new UserInfoExtraException(1, "此微信已被其他帐号绑定");
         }
@@ -485,42 +455,8 @@
         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);
      }
      // 邀请码激活
      inviteCodeActive(uid, boss.getId());
   }
   @Override
@@ -536,15 +472,6 @@
         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();
      if (wxUnionId == null || wxUnionId.trim().length() == 0) {
         throw new UserInfoExtraException(1, "微信授权失败");
@@ -553,7 +480,7 @@
      // 验证数据
      String wxUnionIdExist = invitee.getWxUnionId();
      if (StringUtil.isNullOrEmpty(wxUnionIdExist)) {
         UserInfo newUser = userInfoService.getEffectiveUserInfoByWXUnionId(weiXinUser.getUnionid());
         UserInfo newUser = userInfoService.getEffectiveUserInfoByWXUnionId(weiXinUser.getUnionid(),invitee.getSystem());
         if (newUser != null) {
            throw new UserInfoExtraException(1, "此微信已被其他帐号绑定");
         }
@@ -612,10 +539,28 @@
      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);
@@ -627,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) {
@@ -647,10 +591,14 @@
      if (!Constant.IS_TEST) { // 发送激活成功消息
         Message message = MQMsgBodyFactory.create(MQTopicName.TOPIC_USER, UserTopicTagEnum.inviteCodeActive,
               new Gson().toJson(new InviteCodeActiveMQMsg(uid, new Date())));
         producer.send(message);
               new InviteCodeActiveMQMsg(uid, new Date()));
         rocketMQManager.sendNormalMsg(message, null);
      }
      return inviteCode;
   }
   @Override
   public void updateActiveTime(Long uid, Date date) {
@@ -824,7 +772,7 @@
      // 验证数据
      String wxUnionIdExist = invitee.getWxUnionId();
      if (StringUtil.isNullOrEmpty(wxUnionIdExist)) {
         UserInfo newUser = userInfoService.getEffectiveUserInfoByWXUnionId(wxUnionId);
         UserInfo newUser = userInfoService.getEffectiveUserInfoByWXUnionId(wxUnionId,invitee.getSystem());
         if (newUser != null) {
            throw new UserInfoExtraException(1, "此微信已被其他帐号绑定");
         }
@@ -850,10 +798,6 @@
      return inviter;
   }
   @Override
   public void updateAutoExtract(Integer days) {
      userInfoExtraMapper.updateAutoExtract(days);
   }
   @Transactional(rollbackFor = Exception.class)
   @Override
@@ -893,10 +837,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())));
         producer.send(message);
               new UserInfoUpdateMQMsg(uid, UserInfoUpdateTypeEnum.inviteCode, inviteCodeVip,
                     new Date()));
         rocketMQManager.sendNormalMsg(message, null);
      }
      // 消息
      userAccountMsgNotificationService.createChangeInviteCode(uid, extra.getInviteCode(), inviteCodeVip);
   }
   @Override