yujian
2019-08-27 d8359ddb48dab5cc797a9d552e11fde571f4920c
fanli/src/main/java/com/yeshi/fanli/service/impl/hongbao/ThreeSaleSerivceImpl.java
@@ -8,6 +8,7 @@
import javax.annotation.Resource;
import org.springframework.context.annotation.Lazy;
import org.springframework.core.task.TaskExecutor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -58,30 +59,29 @@
   @Resource
   private MsgInviteDetailService msgInviteDetailService;
   @Resource
   private UserTaoLiJinOriginService userTaoLiJinOriginService;
   @Resource
   private UserActiveLogService userActiveLogService;
   @Resource
   private UserInfoExtraService userInfoExtraService;
   @Resource
   private ThreeSaleExtraInfoSerivce threeSaleExtraInfoSerivce;
   
   @Lazy
   @Resource
   private IntegralGetService  integralGetService;
   private IntegralGetService integralGetService;
   @Resource(name = "taskExecutor")
   private TaskExecutor executor;
   public UserInfo getBoss(final long uid) {
      //TODO 有bug
      return threeSaleMapper.selectBoss(uid);
   }
@@ -328,12 +328,10 @@
      return threeSaleMapper.countSuperiorQuery(state, uid);
   }
   @Override
   public long countFirstTeam(Long uid, Integer state) {
      return threeSaleMapper.countFirstTeam(uid, state);
   }
   @Override
   public long countSecondTeam(Long uid, Integer state) {
@@ -354,7 +352,7 @@
   public List<ThreeSale> listbyIdAndBossId(Long id, Long uid, Integer expire) {
      return threeSaleMapper.listbyIdAndBossId(id, uid, expire);
   }
   @Override
   public JSONObject getMyFirstTeam(long start, int count, Long uid, Integer state) {
@@ -494,8 +492,7 @@
      return result;
   }
   @Override
   public List<ThreeSale> listByWorkerId(Long workerId) {
      return threeSaleMapper.listByWorkerId(workerId);
@@ -510,9 +507,9 @@
   @Transactional
   public void bindRelationshipByInviteCode(UserInfo invitee, UserInfo inviter) throws ThreeSaleException {
      if (invitee == null || inviter == null)
      if (invitee == null || inviter == null)
         throw new ThreeSaleException(1, "用户信息为空");
      // 获取有效的邀请关系
      ThreeSale threeSale = threeSaleMapper.getRelationshipByBossIdAndWorkerId(inviter.getId(), invitee.getId());
@@ -553,17 +550,17 @@
      // 邀请消息
      userInviteMsgNotificationService.inviteSuccess(inviter.getId(), threeSale);
      executor.execute(new Runnable() {
         @Override
         public void run() {
            UserActiveLog activeLog  = userActiveLogService.getUserLatestActiveInfo(inviter.getId());
            UserActiveLog activeLog = userActiveLogService.getUserLatestActiveInfo(inviter.getId());
            try {
               if (activeLog != null  && !StringUtil.isNullOrEmpty(activeLog.getVersionCode()) ) {
               if (activeLog != null && !StringUtil.isNullOrEmpty(activeLog.getVersionCode())) {
                  String versionCode = activeLog.getVersionCode();
                  String channel = activeLog.getChannel();
                  boolean result = false;
                  // 渠道是appstore 判断为IOS
                  if (!StringUtil.isNullOrEmpty(channel) && "appstore".equalsIgnoreCase(channel)) {
@@ -571,14 +568,14 @@
                  } else {
                     result = VersionUtil.greaterThan_1_5_60("android", versionCode);
                  }
                  if (result) {
                     // 被邀请名称
                     String inviteName= invitee.getNickName();
                     String inviteName = invitee.getNickName();
                     if (StringUtil.isNullOrEmpty(inviteName)) {
                        UserInfo userInfo = userInfoService.selectByPKey(invitee.getId());
                        if (userInfo != null) {
                           inviteName= userInfo.getNickName();
                           inviteName = userInfo.getNickName();
                        }
                     }
                     // 奖励邀请红包(淘礼金)
@@ -588,26 +585,26 @@
            } catch (Exception e) {
               LogHelper.errorDetailInfo(e);
            }
            // 邀请金币
            integralGetService.addInviteLevelOne(inviter.getId(), invitee.getId());
         }
      });
   }
   @Override
   @Transactional
   public void bindRelationshipByWX(UserInfo invitee, Long inviterId, ThreeSale threeSaleOld) throws ThreeSaleException {
   public void bindRelationshipByWX(UserInfo invitee, Long inviterId, ThreeSale threeSaleOld)
         throws ThreeSaleException {
      if (invitee == null || (inviterId == null && threeSaleOld == null))
         throw new ThreeSaleException(1, "用户信息为空");
      ThreeSale threeSale = null;
      if (inviterId != null ) {
      if (inviterId != null) {
         // 新建立确定关系
         threeSale  = new ThreeSale();
         threeSale = new ThreeSale();
         threeSale.setBoss(new UserInfo(inviterId));
         threeSale.setWorker(invitee);
         threeSale.setState(true);
@@ -616,10 +613,10 @@
         threeSale.setCreateTime(java.lang.System.currentTimeMillis());
         threeSale.setUpdateTime(java.lang.System.currentTimeMillis());
         threeSaleMapper.insertSelective(threeSale);
         // 邀请关系失效  1.5.3 之前失效
         // 邀请关系失效 1.5.3 之前失效
         if (threeSaleOld != null) {
            ThreeSale three  = new ThreeSale();
            ThreeSale three = new ThreeSale();
            three.setId(threeSaleOld.getId());
            three.setExpire(ThreeSale.EXPIRE_OUTOFDATE);
            three.setUpdateTime(java.lang.System.currentTimeMillis());
@@ -632,49 +629,48 @@
         threeSaleOld.setSucceedTime(java.lang.System.currentTimeMillis());
         threeSaleOld.setUpdateTime(java.lang.System.currentTimeMillis());
         threeSaleMapper.updateByPrimaryKeySelective(threeSaleOld);
         threeSale = threeSaleOld;
      }
      if (threeSale == null) {
         throw new ThreeSaleException(1, "关系绑定失败");
      }
      UserInfo boss = userInfoService.selectByPKey(threeSale.getBoss().getId());
      threeSale.setBoss(boss);
      threeSale.setWorker(invitee);
      // 添加到队列
      ThreeSaleCMQManager.getInstance().addThreeSaleMsg(threeSale);
      // 邀请消息
      userInviteMsgNotificationService.inviteSuccess(threeSale.getBoss().getId(), threeSale);
      executor.execute(new Runnable() {
         @Override
         public void run() {
            try {
               UserActiveLog activeLog  = userActiveLogService.getUserLatestActiveInfo(inviterId);
               if (activeLog != null  && !StringUtil.isNullOrEmpty(activeLog.getVersionCode()) ) {
               UserActiveLog activeLog = userActiveLogService.getUserLatestActiveInfo(inviterId);
               if (activeLog != null && !StringUtil.isNullOrEmpty(activeLog.getVersionCode())) {
                  boolean result = false;
                  String versionCode = activeLog.getVersionCode();
                  String channel = activeLog.getChannel();
                  // 渠道是appstore 判断为IOS
                  if (!StringUtil.isNullOrEmpty(channel) && "appstore".equalsIgnoreCase(channel)) {
                     result = VersionUtil.greaterThan_1_5_60("ios", versionCode);
                  } else {
                     result = VersionUtil.greaterThan_1_5_60("android", versionCode);
                  }
                  if (result) {
                     // 被邀请名称
                     String inviteName= invitee.getNickName();
                     String inviteName = invitee.getNickName();
                     if (StringUtil.isNullOrEmpty(inviteName)) {
                        UserInfo userInfo = userInfoService.selectByPKey(invitee.getId());
                        if (userInfo != null) {
                           inviteName= userInfo.getNickName();
                           inviteName = userInfo.getNickName();
                        }
                     }
                     // 奖励邀请红包(淘礼金)
@@ -687,7 +683,7 @@
         }
      });
   }
   /**
    * 根据邀请者查询关系
    * 
@@ -698,8 +694,7 @@
   public ThreeSale getByWorkerId(Long workerId) {
      return threeSaleMapper.getByWorkerId(workerId);
   }
   @Override
   public long countSuccessFirstTeam(Long uid) {
      return threeSaleMapper.countFirstTeam(uid, 1);
@@ -709,19 +704,17 @@
   public ThreeSale selectByWorkerId(Long workerId) {
      return threeSaleMapper.selectSuccessByWorkerId(workerId);
   }
   @Override
   public List<ThreeSale> getSuccessByDate(Long bossId, Long minTime, Long maxTime){
   public List<ThreeSale> getSuccessByDate(Long bossId, Long minTime, Long maxTime) {
      return threeSaleMapper.getSuccessByDate(bossId, minTime, maxTime);
   }
   @Override
   public List<ThreeSale> listFirstTeam(long start, int count, Long uid, Integer state) {
      return threeSaleMapper.listFirstTeam(start, count, uid, state);
   }
   @Override
   public List<ThreeSale> listSecondTeam(long start, int count, Long uid, Integer state) {
      return threeSaleMapper.listSecondTeam(start, count, uid, state);