yujian
2019-02-28 70c9043f312a52a922cb15490d90a172b3515060
fanli/src/main/java/com/yeshi/fanli/service/impl/hongbao/ThreeSaleSerivceImpl.java
@@ -10,9 +10,6 @@
import javax.annotation.Resource;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.SQLQuery;
@@ -32,10 +29,15 @@
import com.yeshi.fanli.service.inter.config.InviteGetMoneyService;
import com.yeshi.fanli.service.inter.hongbao.HongBaoManageService;
import com.yeshi.fanli.service.inter.hongbao.ThreeSaleSerivce;
import com.yeshi.fanli.service.inter.msg.MsgInviteDetailService;
import com.yeshi.fanli.service.inter.msg.UserInviteMsgNotificationService;
import com.yeshi.fanli.service.inter.user.UserInfoService;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.ThreeSaleCMQManager;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
@Service
public class ThreeSaleSerivceImpl implements ThreeSaleSerivce {
@@ -57,9 +59,12 @@
   @Resource
   private ThreeSaleMapper threeSaleMapper;
   @Resource
   private UserInviteMsgNotificationService userInviteMsgNotificationService;
   @Resource
   private MsgInviteDetailService msgInviteDetailService;
   public UserInfo getBoss(final long uid) {
      return (UserInfo) dao.excute(new HibernateCallback<UserInfo>() {
@@ -112,14 +117,20 @@
         threeSale.setUpdateTime(java.lang.System.currentTimeMillis());
         threeSale.setWorker(inviteeUser);
         threeSaleMapper.insertSelective(threeSale);
         // 删除已失效关系
         threeSaleMapper.deleteExpireRecord(inviter.getId(), inviteeUser.getId());
         //创建通知
         List<ThreeSale> listExpire = threeSaleMapper.getExpireRecord(inviter.getId(), inviteeUser.getId());
         if (listExpire != null && listExpire.size() > 0) {
            // 删除失效
            for (ThreeSale saleExpire : listExpire) {
               msgInviteDetailService.deleteByThreeSale(saleExpire);
            }
            // 删除已失效关系
            threeSaleMapper.deleteExpireRecord(inviter.getId(), inviteeUser.getId());
         }
         // 创建通知
         userInviteMsgNotificationService.inviteScan(inviter.getId(), threeSale);
      } else {// 是已经存在的用户
         // 用户已经存在我们的用户库中
@@ -145,6 +156,20 @@
                  threeSale.setUpdateTime(java.lang.System.currentTimeMillis());
                  threeSale.setWorker(invitee);
                  threeSaleMapper.insertSelective(threeSale);
                  // 删除已失效关系
                  threeSaleMapper.deleteExpireRecord(inviter.getId(), invitee.getId());
                  List<ThreeSale> listExpire = threeSaleMapper.getExpireRecord(inviter.getId(), invitee.getId());
                  if (listExpire != null && listExpire.size() > 0) {
                     // 删除历史通知
                     for (ThreeSale saleExpire : listExpire) {
                        msgInviteDetailService.deleteByThreeSale(saleExpire);
                     }
                     // 删除已失效关系
                     threeSaleMapper.deleteExpireRecord(inviter.getId(), invitee.getId());
                  }
                  userInviteMsgNotificationService.inviteScan(inviter.getId(), threeSale);
                  // threeSaleSerivce.bind(invitee, inviter);
@@ -172,7 +197,9 @@
         dao.update(threeSale);
         if (inviter != null)
            reComputeUserRank(inviter.getId());
         //通知
         //添加到队列
         ThreeSaleCMQManager.getInstance().addThreeSaleMsg(threeSale);
         // 通知
         userInviteMsgNotificationService.inviteSuccess(inviter.getId(), threeSale);
         // }
         // });
@@ -591,8 +618,7 @@
   public List<ThreeSale> listByWorkerId(Long workerId) {
      return threeSaleMapper.listByWorkerId(workerId);
   }
   @Override
   public int getSuccessRelationshipNum(Long uid) {
      return threeSaleMapper.getSuccessRelationshipNum(uid);
@@ -601,14 +627,13 @@
   @Override
   @Transactional
   public void bindRelationshipByInviteCode(UserInfo invitee, UserInfo inviter) throws ThreeSaleException {
      if (invitee == null || inviter == null)
         throw new ThreeSaleException(1, "用户信息为空");
      // 获取有效的邀请关系
      ThreeSale threeSale =
            threeSaleMapper.getRelationshipByBossIdAndWorkerId(inviter.getId(), invitee.getId());
      ThreeSale threeSale = threeSaleMapper.getRelationshipByBossIdAndWorkerId(inviter.getId(), invitee.getId());
      if (threeSale != null) {
         // 有效关系--生效
         threeSale.setState(true);
@@ -627,11 +652,26 @@
         threeSale.setCreateTime(java.lang.System.currentTimeMillis());
         threeSale.setUpdateTime(java.lang.System.currentTimeMillis());
         threeSaleMapper.insertSelective(threeSale);
      }
      List<ThreeSale> listExpire = threeSaleMapper.getExpireRecord(inviter.getId(), invitee.getId());
      if (listExpire != null && listExpire.size() > 0) {
         // 删除历史通知
         for (ThreeSale saleExpire : listExpire) {
            msgInviteDetailService.deleteByThreeSale(saleExpire);
         }
         // 删除已失效关系
         threeSaleMapper.deleteExpireRecord(inviter.getId(), invitee.getId());
      }
      // 邀请消息
      userInviteMsgNotificationService.inviteSuccess(inviter.getId(), threeSale);
   }
   
   @Override
   public long countSuccessFirstTeam(Long uid) {
      return threeSaleMapper.countFirstTeam(uid,1);
   }
}