From dc5be7d38446f70e6ff86df311119c32b41fe7f8 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期六, 28 十一月 2020 16:37:05 +0800
Subject: [PATCH] 大淘客搜索接口升级

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserInfoExtraServiceImpl.java |  189 +++++++++++++++++++----------------------------
 1 files changed, 77 insertions(+), 112 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserInfoExtraServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserInfoExtraServiceImpl.java
index 1dc815a..65dd174 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserInfoExtraServiceImpl.java
+++ b/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;
@@ -23,11 +25,10 @@
 import org.yeshi.utils.FileUtil;
 import org.yeshi.utils.HttpUtil;
 import org.yeshi.utils.entity.FileUploadResult;
+import org.yeshi.utils.entity.wx.WeiXinUser;
 import org.yeshi.utils.tencentcloud.COSManager;
 
 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;
@@ -39,7 +40,6 @@
 import com.yeshi.fanli.entity.bus.user.UserInfoExtra;
 import com.yeshi.fanli.entity.bus.user.UserRank;
 import com.yeshi.fanli.entity.bus.user.UserRankRecord;
-import com.yeshi.fanli.entity.bus.user.WeiXinUser;
 import com.yeshi.fanli.entity.bus.user.notify.UserActivedRecord;
 import com.yeshi.fanli.entity.system.ConfigKeyEnum;
 import com.yeshi.fanli.exception.user.ThreeSaleException;
@@ -54,18 +54,16 @@
 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;
-import com.yeshi.fanli.util.wx.WXLoginUtil;
 import com.yeshi.fanli.vo.user.UserInfoExtraVO;
 
 import net.coobird.thumbnailator.Thumbnails;
+import org.yeshi.utils.wx.WXAppLoginUtil;
 
 @Service
 public class UserInfoExtraServiceImpl implements UserInfoExtraService {
@@ -103,9 +101,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 +116,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 +357,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
@@ -414,7 +383,7 @@
 			throw new UserInfoExtraException(1, "宸茬粡婵�娲�, 鏃犻渶鍐嶆婵�娲�");
 
 		// 鑾峰彇寰俊淇℃伅
-		WeiXinUser weiXinUser = WXLoginUtil.getWeiXinUser(code, wxAccount.getAppId(), wxAccount.getAppSecret());
+		WeiXinUser weiXinUser = WXAppLoginUtil.getWeiXinUser(code, wxAccount.getAppId(), wxAccount.getAppSecret());
 		if (weiXinUser == null) {
 			throw new UserInfoExtraException(1, "寰俊鎺堟潈澶辫触");
 		}
@@ -426,7 +395,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, "姝ゅ井淇″凡琚叾浠栧笎鍙风粦瀹�");
 			}
@@ -479,43 +448,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
@@ -531,15 +471,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, "寰俊鎺堟潈澶辫触");
@@ -548,7 +479,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, "姝ゅ井淇″凡琚叾浠栧笎鍙风粦瀹�");
 			}
@@ -602,10 +533,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 +571,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) {
@@ -637,10 +590,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) {
@@ -782,6 +739,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;
 	}
@@ -810,7 +771,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, "姝ゅ井淇″凡琚叾浠栧笎鍙风粦瀹�");
 			}
@@ -828,13 +789,14 @@
 		if (inviter == null) {
 			throw new UserInfoExtraException(1, "瀵瑰簲鐨勯個璇峰叧绯讳笉瀛樺湪");
 		}
+		
+		if (inviter.getState() != UserInfo.STATE_NORMAL) {
+			throw new UserInfoExtraException(1, "瀵瑰簲鐨勯個璇峰叧绯讳笉瀛樺湪");
+		}
+		
 		return inviter;
 	}
 
-	@Override
-	public void updateAutoExtract(Integer days) {
-		userInfoExtraMapper.updateAutoExtract(days);
-	}
 
 	@Transactional(rollbackFor = Exception.class)
 	@Override
@@ -874,10 +836,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

--
Gitblit v1.8.0