From bb07147aaa96d1ef4c99e358dbbe7dad160dc62a Mon Sep 17 00:00:00 2001
From: yujian <yujian@163.com>
Date: 星期四, 19 十二月 2019 15:43:23 +0800
Subject: [PATCH] Merge branch 'div' of ssh://193.112.35.168:29418/fanli-server into div

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserInfoExtraServiceImpl.java |   88 ++++++++++++++++++++++++++++---------------
 1 files changed, 57 insertions(+), 31 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 442453f..12ef941 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
@@ -19,8 +19,15 @@
 import org.yeshi.utils.entity.FileUploadResult;
 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;
+import com.yeshi.fanli.dto.mq.user.body.InviteCodeActiveMQMsg;
+import com.yeshi.fanli.dto.mq.user.body.UserInfoUpdateMQMsg;
+import com.yeshi.fanli.dto.mq.user.body.UserInfoUpdateMQMsg.UserInfoUpdateTypeEnum;
 import com.yeshi.fanli.dto.wx.WXAccountInfoDTO;
 import com.yeshi.fanli.entity.bus.user.UserInfo;
 import com.yeshi.fanli.entity.bus.user.UserInfoExtra;
@@ -43,6 +50,8 @@
 import com.yeshi.fanli.util.InviteCodeFilterUtil;
 import com.yeshi.fanli.util.StringUtil;
 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;
 
@@ -78,6 +87,9 @@
 
 	@Resource
 	private UserInviteRecordService userInviteRecordService;
+
+	@Resource(name = "producer")
+	private Producer producer;
 
 	@Override
 	public UserInfoExtraVO getRankInfo(Long uid) throws UserInfoExtraException, Exception {
@@ -176,7 +188,7 @@
 		} else {
 			extra.setUserInfo(new UserInfo(uid));
 		}
-		
+
 		// 鏇存柊绛夌骇
 		if (isupdateRank) {
 			List<UserRank> listRank = userRankService.getAllRank();
@@ -276,7 +288,6 @@
 		userInfoExtraMapper.insertSelective(userInfoExtra);
 	}
 
-
 	@Override
 	public UserInfoExtra saveUserInfoExtra(UserInfoExtra userInfoExtra) throws UserInfoExtraException {
 
@@ -313,9 +324,9 @@
 	@Override
 	@Transactional(rollbackFor = Exception.class)
 	public String activateInviteCode(Long uid, String inviteCode) throws UserInfoExtraException {
-		if (uid == null || inviteCode == null) 
+		if (uid == null || inviteCode == null)
 			throw new UserInfoExtraException(1, "婵�娲讳俊鎭笉鑳戒负绌�");
-		
+
 		// 琚個璇蜂汉淇℃伅
 		UserInfo invitee = userInfoService.selectByPKey(uid);
 		if (invitee == null)
@@ -331,7 +342,7 @@
 		UserInfo inviter = userInfoService.getUserInfoByInviteCode(inviteCode);
 		if (inviter == null)
 			throw new UserInfoExtraException(1, "涓婄骇閭�璇风爜涓嶅瓨鍦�");
-		
+
 		// 缁戝畾鍏崇郴
 		try {
 			threeSaleSerivce.bindRelationshipByInviteCode(invitee, inviter);
@@ -346,7 +357,7 @@
 
 		// 鐢熸垚閭�璇风爜
 		String mycode = createInviteCode(uid);
-		if (StringUtil.isNullOrEmpty(mycode)) 
+		if (StringUtil.isNullOrEmpty(mycode))
 			throw new UserInfoExtraException(1, "婵�娲荤爜鐢熸垚澶辫触");
 
 		UserInfoExtra userInfoExtra = new UserInfoExtra();
@@ -360,6 +371,12 @@
 			userInfoExtra.setCreateTime(new Date());
 			userInfoExtraMapper.insertSelective(userInfoExtra);
 		}
+
+		// 鍙戦�佹縺娲绘垚鍔熸秷鎭�
+		Message message = MQMsgBodyFactory.create(MQTopicName.TOPIC_USER, UserTopicTagEnum.inviteCodeActive,
+				new Gson().toJson(new InviteCodeActiveMQMsg(uid, new Date())));
+		producer.send(message);
+
 		return mycode;
 	}
 
@@ -368,7 +385,7 @@
 	public void activationInviteWX(WXAccountInfoDTO wxAccount, Long uid, String code) throws UserInfoExtraException {
 		if (uid == null || code == null)
 			throw new UserInfoExtraException(1, "婵�娲讳俊鎭笉瀹屾暣");
-		 
+
 		UserInfo invitee = userInfoService.selectByPKey(uid);
 		if (invitee == null)
 			throw new UserInfoExtraException(1, "鐢ㄦ埛涓嶅瓨鍦�");
@@ -458,9 +475,9 @@
 
 		// 鐢熸垚閭�璇风爜
 		String inviteCode = createInviteCode(uid);
-		if (StringUtil.isNullOrEmpty(inviteCode)) 
+		if (StringUtil.isNullOrEmpty(inviteCode))
 			throw new UserInfoExtraException(1, "婵�娲荤爜鐢熸垚澶辫触");
-		
+
 		UserInfoExtra userInfoExtra = new UserInfoExtra();
 		userInfoExtra.setUserInfo(invitee);
 		userInfoExtra.setInviteCode(inviteCode);
@@ -472,6 +489,10 @@
 			userInfoExtra.setCreateTime(new Date());
 			userInfoExtraMapper.insertSelective(userInfoExtra);
 		}
+		// 鍙戦�佹縺娲绘垚鍔熸秷鎭�
+		Message message = MQMsgBodyFactory.create(MQTopicName.TOPIC_USER, UserTopicTagEnum.inviteCodeActive,
+				new Gson().toJson(new InviteCodeActiveMQMsg(uid, new Date())));
+		producer.send(message);
 	}
 
 	@Override
@@ -571,10 +592,11 @@
 		}
 
 		// 鐢熸垚閭�璇风爜
-		String inviteCode = createInviteCode(uid);;
-		if (StringUtil.isNullOrEmpty(inviteCode)) 
+		String inviteCode = createInviteCode(uid);
+		;
+		if (StringUtil.isNullOrEmpty(inviteCode))
 			throw new UserInfoExtraException(1, "婵�娲荤爜鐢熸垚澶辫触");
-		
+
 		UserInfoExtra userInfoExtra = new UserInfoExtra();
 		userInfoExtra.setUserInfo(invitee);
 		userInfoExtra.setInviteCode(inviteCode);
@@ -617,12 +639,12 @@
 	public void updateGoldCoin(Long id, Integer goldCoin) {
 		userInfoExtraMapper.updateGoldCoin(id, goldCoin);
 	}
-	
+
 	@Override
 	public void addGoldCoinByUid(Long uid, Integer goldCoin) {
 		userInfoExtraMapper.addGoldCoinByUid(uid, goldCoin);
 	}
-	
+
 	@Override
 	public void updateByPrimaryKeySelective(UserInfoExtra record) {
 		userInfoExtraMapper.updateByPrimaryKeySelective(record);
@@ -640,17 +662,17 @@
 			// vip閭�璇风爜浼樺厛
 			if (!StringUtil.isNullOrEmpty(userInfoExtra.getInviteCodeVip()))
 				return userInfoExtra.getInviteCodeVip();
-			
+
 			if (!StringUtil.isNullOrEmpty(userInfoExtra.getInviteCode()))
 				return userInfoExtra.getInviteCode();
-			
+
 			// 鏄惁婊¤冻鐢熶骇閭�璇风爜
 			int relationshipNum = threeSaleSerivce.getSuccessRelationshipNum(uid);
 			if (relationshipNum > 0) {
 				try {
 					String inviteCode = createInviteCode(uid);
 					if (!StringUtil.isNullOrEmpty(inviteCode)) {
-						UserInfoExtra extra= new UserInfoExtra();
+						UserInfoExtra extra = new UserInfoExtra();
 						extra.setId(userInfoExtra.getId());
 						extra.setInviteCode(inviteCode);
 						userInfoExtraMapper.updateByPrimaryKeySelective(extra);
@@ -666,12 +688,13 @@
 
 	/**
 	 * 鐢熶骇閭�璇风爜
+	 * 
 	 * @param uid
 	 * @return
 	 */
 	private String createInviteCode(Long uid) {
 		String inviteCode = null;
-		for (int i = 1; i <= 5; i ++) {
+		for (int i = 1; i <= 5; i++) {
 			inviteCode = UserUtil.getInviteCode(i, uid);
 			long countCode = userInfoExtraMapper.countByInviteCode(inviteCode);
 			if (countCode <= 0)
@@ -679,8 +702,7 @@
 		}
 		return inviteCode;
 	}
-	
-	
+
 	@Override
 	public long countByRankId(Long rankId) {
 		return userInfoExtraMapper.countByRankId(rankId);
@@ -724,11 +746,11 @@
 	public UserInfo getUserByInviteCode(String inviteCode) throws UserInfoExtraException {
 		if (StringUtil.isNullOrEmpty(inviteCode))
 			throw new UserInfoExtraException(1, "閭�璇风爜涓嶈兘涓虹┖");
-		 
+
 		UserInfo inviter = userInfoService.getUserInfoByInviteCode(inviteCode);
 		if (inviter == null)
 			throw new UserInfoExtraException(1, "涓婄骇閭�璇风爜涓嶅瓨鍦�");
-		
+
 		return inviter;
 	}
 
@@ -782,40 +804,44 @@
 		userInfoExtraMapper.updateAutoExtract(days);
 	}
 
-	@Transactional
+	@Transactional(rollbackFor=Exception.class)
 	@Override
 	public void updateInviteCodeVip(String inviteCodeVip, Long uid) throws UserInfoExtraException {
 		if (inviteCodeVip == null || inviteCodeVip.length() < 4 || inviteCodeVip.length() > 12)
 			throw new UserInfoExtraException(1, "閭�璇风爜蹇呴』涓�4鍒�12浣�");
-		
+
 		UserInfoExtra extra = getUserInfoExtra(uid);
 		if (extra == null)
 			throw new UserInfoExtraException(2, "鐢ㄦ埛淇℃伅涓嶅瓨鍦�");
 
 		if (StringUtil.isNullOrEmpty(extra.getInviteCode()))
 			throw new UserInfoExtraException(3, "閭�璇风爜灏氭湭婵�娲�");
-		
+
 		if (!StringUtil.isNullOrEmpty(extra.getInviteCodeVip()))
 			throw new UserInfoExtraException(4, "鍙兘淇敼涓�娆�");
-		
+
 		// 杞崲鎴愬ぇ鍐�
 		inviteCodeVip = inviteCodeVip.toUpperCase();
-		
+
 		// 楠岃瘉鐗规畩鐮�
-		if(InviteCodeFilterUtil.isSpecialCode(inviteCodeVip))
+		if (InviteCodeFilterUtil.isSpecialCode(inviteCodeVip))
 			throw new UserInfoExtraException(5, "閭�璇风爜宸插瓨鍦�");
-		
+
 		if (inviteCodeVip.equalsIgnoreCase(extra.getInviteCode()))
 			throw new UserInfoExtraException(5, "涓嶈兘涓哄師閭�璇风爜");
-		
+
 		long count = userInfoExtraMapper.countByInviteCode(inviteCodeVip);
 		if (count > 0)
 			throw new UserInfoExtraException(6, "閭�璇风爜宸插瓨鍦�");
-		
+
 		UserInfoExtra update = new UserInfoExtra();
 		update.setId(extra.getId());
 		update.setInviteCodeVip(inviteCodeVip);
 		update.setUpdateTime(new Date());
 		userInfoExtraMapper.updateByPrimaryKeySelective(update);
+	    //鍙戦�侀個璇风爜鏇存敼鎴愬姛鐨勬秷鎭�
+		Message message = MQMsgBodyFactory.create(MQTopicName.TOPIC_USER, UserTopicTagEnum.userInfoUpdate,
+				new Gson().toJson(new UserInfoUpdateMQMsg(uid, UserInfoUpdateTypeEnum.inviteCode, inviteCodeVip, new Date())));
+		producer.send(message);
 	}
 }

--
Gitblit v1.8.0