From b803abf95ed0cc721f8f9e767283e5ac6b8ca090 Mon Sep 17 00:00:00 2001
From: yujian <yujian@163.com>
Date: 星期六, 18 四月 2020 11:52:17 +0800
Subject: [PATCH] 活跃消息

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/user/invite/ThreeSaleSerivceImpl.java |  187 +++++++++++++++++++++++++++++-----------------
 1 files changed, 117 insertions(+), 70 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/user/invite/ThreeSaleSerivceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/user/invite/ThreeSaleSerivceImpl.java
index 9cecfe1..94b524a 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/user/invite/ThreeSaleSerivceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/user/invite/ThreeSaleSerivceImpl.java
@@ -21,7 +21,6 @@
 import com.yeshi.fanli.dto.mq.user.body.UserInviteMQMsg;
 import com.yeshi.fanli.entity.bus.user.ThreeSale;
 import com.yeshi.fanli.entity.bus.user.ThreeSaleExtraInfo;
-import com.yeshi.fanli.entity.bus.user.UserActiveLog;
 import com.yeshi.fanli.entity.bus.user.UserInfo;
 import com.yeshi.fanli.exception.user.ThreeSaleException;
 import com.yeshi.fanli.service.inter.order.config.HongBaoManageService;
@@ -35,7 +34,6 @@
 import com.yeshi.fanli.service.inter.user.invite.UserInviteMsgNotificationService;
 import com.yeshi.fanli.util.Constant;
 import com.yeshi.fanli.util.StringUtil;
-import com.yeshi.fanli.util.VersionUtil;
 import com.yeshi.fanli.util.rocketmq.MQMsgBodyFactory;
 import com.yeshi.fanli.util.rocketmq.MQTopicName;
 
@@ -117,9 +115,6 @@
 				threeSaleMapper.deleteExpireRecord(inviter.getId(), inviteeUser.getId());
 			}
 
-			// 鍒涘缓閫氱煡
-			userInviteMsgNotificationService.inviteScan(inviter.getId(), threeSale);
-
 		} else {// 鏄凡缁忓瓨鍦ㄧ殑鐢ㄦ埛
 			if (worker.getId().longValue() == inviter.getId())
 				throw new ThreeSaleException(4, "涓嶈兘缁戝畾鑷繁");
@@ -134,7 +129,7 @@
 				List<ThreeSale> list = listByWorkerId(worker.getId());
 				if (list != null && list.size() > 0) {
 					for (ThreeSale ts : list) {
-						if (!ts.getState() && ts.getExpire() == ThreeSale.EXPIRE_OUTOFDATE) {
+						if (!ts.getState() && ts.getExpire() == ThreeSale.EXPIRE_BREAK) {
 							outOfDateCount++;
 						}
 					}
@@ -163,9 +158,6 @@
 							threeSaleMapper.deleteExpireRecord(inviter.getId(), worker.getId());
 						}
 
-						userInviteMsgNotificationService.inviteScan(inviter.getId(), threeSale);
-						// threeSaleSerivce.bind(invitee, inviter);
-
 					} else {
 						// 杩樺瓨鍦ㄦ湁鏁堢殑閭�璇凤紝鍒欎笉鍋氬鐞�
 					}
@@ -179,7 +171,7 @@
 				if (list != null)
 					for (int i = 0; i < list.size(); i++) {
 						if (list.get(i).getState() != null && list.get(i).getState() == false
-								&& list.get(i).getExpire() == ThreeSale.EXPIRE_OUTOFDATE) {// 杩囨湡鐨�
+								&& list.get(i).getExpire() == ThreeSale.EXPIRE_BREAK) {// 杩囨湡鐨�
 							list.remove(i);
 							i--;
 						}
@@ -195,7 +187,6 @@
 					ts.setSucceedTime(System.currentTimeMillis());
 					ts.setWorker(worker);
 					threeSaleMapper.insertSelective(ts);
-					inviteSuccess(inviter.getId(), worker.getId(), ts);
 				} else {
 					if (!list.get(0).getState() && list.get(0).getExpire() == ThreeSale.EXPIRE_NORMAL
 							&& list.get(0).getBoss().getId() == inviter.getId().longValue()) {// 鏈敓鏁堢殑涓婄骇鍜岀幇鍦ㄤ笂绾т竴鏍峰氨鐢熸晥
@@ -203,7 +194,6 @@
 						update.setState(true);
 						update.setSucceedTime(System.currentTimeMillis());
 						threeSaleMapper.updateByPrimaryKeySelective(update);
-						inviteSuccess(list.get(0).getBoss().getId(), list.get(0).getWorker().getId(), list.get(0));
 					}
 				}
 			}
@@ -238,7 +228,7 @@
 			// if (inviter != null)
 			// reComputeUserRank(inviter.getId());
 			// 娣诲姞鍒伴槦鍒�
-			inviteSuccess(oldSale.getBoss().getId(), oldSale.getWorker().getId(), oldSale);
+			inviteSuccess(worker.getId(), oldSale.getBoss().getId());
 		}
 	}
 
@@ -277,20 +267,7 @@
 		return threeSaleMapper.deleteByPrimaryKey(id);
 	}
 
-	@Override
-	public List<Long> queryLongTimeFailed(int daysNum) {
-		return threeSaleMapper.queryLongTimeFailed(daysNum);
-	}
 
-	@Override
-	public List<ThreeSale> queryLongTimeSuccess(int daysNum) {
-		return threeSaleMapper.queryLongTimeSuccess(daysNum);
-	}
-
-	@Override
-	public int updateExpire(List<Long> list) {
-		return threeSaleMapper.updateExpire(list);
-	}
 
 	@Override
 	public List<ThreeSale> listFirstTeamQuery(long start, int count, Long uid, Integer state, String startTime,
@@ -499,75 +476,66 @@
 		return threeSaleMapper.getSuccessRelationshipNum(uid);
 	}
 
+
 	@Override
 	@Transactional(rollbackFor = Exception.class)
-	public void bindRelationshipByInviteCode(UserInfo invitee, UserInfo inviter) throws ThreeSaleException {
-		if (invitee == null || inviter == null)
+	public void bindInviteRelationship(Long workerId, Long bossId) throws ThreeSaleException {
+		if (workerId == null || bossId == null)
 			throw new ThreeSaleException(1, "鐢ㄦ埛淇℃伅涓虹┖");
-
+		
 		// 鏂板缓绔嬬‘瀹氬叧绯�
 		ThreeSale threeSale = new ThreeSale();
-		threeSale.setBoss(inviter);
-		threeSale.setWorker(invitee);
+		threeSale.setBoss(new UserInfo(bossId));
+		threeSale.setWorker(new UserInfo(workerId));
 		threeSale.setState(true);
 		threeSale.setExpire(ThreeSale.EXPIRE_NORMAL);
 		threeSale.setSucceedTime(java.lang.System.currentTimeMillis());
 		threeSale.setCreateTime(java.lang.System.currentTimeMillis());
 		threeSale.setUpdateTime(java.lang.System.currentTimeMillis());
 		threeSaleMapper.insertSelective(threeSale);
-
-		inviteSuccess(inviter.getId(), invitee.getId(), threeSale);
-	}
-
-	@Override
-	@Transactional(rollbackFor = Exception.class)
-	public void bindRelationshipByWX(UserInfo invitee, Long inviterId) throws ThreeSaleException {
-		if (invitee == null || inviterId == null)
-			throw new ThreeSaleException(1, "鐢ㄦ埛淇℃伅涓虹┖");
-		// 鏂板缓绔嬬‘瀹氬叧绯�
-		ThreeSale threeSale = new ThreeSale();
-		threeSale.setBoss(new UserInfo(inviterId));
-		threeSale.setWorker(invitee);
-		threeSale.setState(true);
-		threeSale.setExpire(ThreeSale.EXPIRE_NORMAL);
-		threeSale.setSucceedTime(java.lang.System.currentTimeMillis());
-		threeSale.setCreateTime(java.lang.System.currentTimeMillis());
-		threeSale.setUpdateTime(java.lang.System.currentTimeMillis());
-		threeSaleMapper.insertSelective(threeSale);
-
-		UserInfo boss = userInfoService.selectByPKey(threeSale.getBoss().getId());
-		threeSale.setBoss(boss);
-		threeSale.setWorker(invitee);
 
 		// 閭�璇锋垚鍔燂細娑堟伅銆佺浉鍏冲鐞�
-		inviteSuccess(boss.getId(), invitee.getId(), threeSale);
+		inviteSuccess(workerId, bossId);
 	}
 
 	/**
 	 * 閭�璇锋垚鍔�
 	 */
 	@Transactional
-	private void inviteSuccess(Long bossId, Long workerId, ThreeSale threeSale) {
-		// 閭�璇锋秷鎭�
-		UserActiveLog activeLog = userActiveLogService.getUserLatestActiveInfo(bossId);
-		if (activeLog != null && VersionUtil.greaterThan_2_0_5(
-				"appstore".equalsIgnoreCase(activeLog.getChannel()) ? "ios" : "android", activeLog.getVersionCode())) { // 2.1鐗堟湰浠ヤ笂
-			userInviteMsgNotificationService.inviteSuccess2_1(bossId, threeSale);
-		} else { // 鏈�鍒濇秷鎭�
-			userInviteMsgNotificationService.inviteSuccess(threeSale.getBoss().getId(), threeSale);
+	private void inviteSuccess(Long workerId, Long bossId) {
+		if (!Constant.IS_TEST) {
+			UserInviteMQMsg msg = new UserInviteMQMsg(bossId, workerId, null, new Date(), UserInviteMQMsg.STATE_SUCCESS);
+			Message message = MQMsgBodyFactory.create(MQTopicName.TOPIC_USER, UserTopicTagEnum.inviteSuccess, msg);
+			producer.send(message);
 		}
 
 		executor.execute(new Runnable() {
 			@Override
 			public void run() {
-				// 閭�璇烽噾甯�
-				integralGetService.addInviteLevelOne(bossId, workerId);
+				try { // 閭�璇烽噾甯�
+					integralGetService.addInviteLevelOne(bossId, workerId);
+				} catch (Exception e) {
+					e.printStackTrace();
+				}
+				
+				try {
+					// 鐩存帴绮変笣閭�璇锋垚鍔�
+					UserInfo invitee = userInfoService.selectByPKey(workerId);
+					userInviteMsgNotificationService.directInviteSuccess(bossId, invitee.getNickName(),
+							invitee.getPortrait(), new Date());
+					
+					// 闂存帴绮変笣閭�璇锋垚鍔�
+					ThreeSale myBoss = threeSaleMapper.getMyBoss(bossId);
+					if (myBoss != null) {
+						UserInfo boss = userInfoService.selectByPKey(bossId);
+						userInviteMsgNotificationService.indirectInviteSuccess(myBoss.getBoss().getId(), 
+								boss.getNickName(),	invitee.getNickName(), invitee.getPortrait(), new Date());
+					}
+				} catch (Exception e) {
+					e.printStackTrace();
+				}
 			}
 		});
-		UserInviteMQMsg msg = new UserInviteMQMsg(bossId, workerId, null, new Date(), UserInviteMQMsg.STATE_SUCCESS);
-		Message message = MQMsgBodyFactory.create(MQTopicName.TOPIC_USER, UserTopicTagEnum.inviteSuccess, msg);
-		if (!Constant.IS_TEST)
-			producer.send(message);
 	}
 
 	/**
@@ -607,6 +575,26 @@
 	}
 
 	@Override
+	public List<ThreeSale> listFirstTeamByUndeleted(long start, int count, Long uid) {
+		return threeSaleMapper.listFirstTeamByUndeleted(start, count, uid);
+	}
+
+	@Override
+	public long countFirstTeamByUndeleted(Long uid) {
+		return threeSaleMapper.countFirstTeamByUndeleted(uid);
+	}
+
+	@Override
+	public List<ThreeSale> listSecondTeamByUndeleted(long start, int count, Long uid) {
+		return threeSaleMapper.listSecondTeamByUndeleted(start, count, uid);
+	}
+
+	@Override
+	public long countSecondTeamByUndeleted(Long uid) {
+		return threeSaleMapper.countSecondTeamByUndeleted(uid);
+	}
+
+	@Override
 	public List<ThreeSale> listSecondTeam(long start, int count, Long uid, Integer state) {
 		return threeSaleMapper.listSecondTeam(start, count, uid, state);
 	}
@@ -631,10 +619,69 @@
 		return threeSaleMapper.getTeamOrderNumByWorkerId(workerId);
 	}
 
-	
 	@Override
 	public List<ThreeSale> getValidWorkerIdsByTime(Long bossId, long limitTime) {
 		return threeSaleMapper.getValidWorkerIdsByTime(bossId, limitTime);
 	}
 
+	@Override
+	public List<ThreeSale> getMyBossDeepList(Long uid, int deep) {
+
+		List<ThreeSale> deepList = new ArrayList<>();
+		ThreeSale boss = getMyBoss(uid);
+		while (deep > 0 && boss != null) {
+			deep--;
+			deepList.add(boss);
+			boss = getMyBoss(boss.getBoss().getId());
+		}
+
+		return deepList;
+	}
+
+	@Override
+	public List<ThreeSale> getMyBossDeepList(Long uid) {
+		//TODO 闇�瑕佹洿鍔犵畝渚跨殑鏂瑰紡澶勭悊
+		return getMyBossDeepList(uid, 100);
+	}
+
+	@Override
+	public void remvoeBreak(Long id, Long uid, Long tid) {
+		ThreeSale threeSale = threeSaleMapper.selectByPrimaryKey(id);
+		if (threeSale == null) {
+			return;
+		}
+
+		Long workerId = threeSale.getWorker().getId();
+		if (tid.longValue() != workerId.longValue()) {
+			return;
+		}
+
+		Integer expire = threeSale.getExpire();
+		if (expire == ThreeSale.EXPIRE_NORMAL) {
+			return;
+		}
+
+		int upExpire = expire;
+		Long bossId = threeSale.getBoss().getId();
+		if (bossId.longValue() == uid.longValue()) { // 鐩存帴绮変笣
+			if (expire == ThreeSale.EXPIRE_BREAK_VIP_DEL4) {
+				upExpire = ThreeSale.EXPIRE_BREAK_VIP_DEL34;
+			} else {
+				upExpire = ThreeSale.EXPIRE_BREAK_VIP_DEL3;
+			}
+		} else { // 闂存帴绮変笣
+			if (expire == ThreeSale.EXPIRE_BREAK_VIP_DEL3) {
+				upExpire = ThreeSale.EXPIRE_BREAK_VIP_DEL34;
+			} else {
+				upExpire = ThreeSale.EXPIRE_BREAK_VIP_DEL4;
+			}
+		}
+
+		ThreeSale update = new ThreeSale();
+		update.setId(id);
+		update.setExpire(upExpire);
+		update.setUpdateTime(java.lang.System.currentTimeMillis());
+		threeSaleMapper.updateByPrimaryKeySelective(update);
+	}
+
 }

--
Gitblit v1.8.0