From 7c74ee47c3f1ec69b9494d363621f43ad8b9c640 Mon Sep 17 00:00:00 2001
From: yujian <yujian@163.com>
Date: 星期日, 26 四月 2020 12:14:59 +0800
Subject: [PATCH] 后台调整
---
fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserInfoExtraServiceImpl.java | 183 +++++++++++++++++++++------------------------
1 files changed, 84 insertions(+), 99 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 cfcac6f..932de4d 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,7 @@
import javax.annotation.Resource;
+import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
@@ -39,6 +40,7 @@
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;
import com.yeshi.fanli.exception.user.UserInfoExtraException;
@@ -52,6 +54,8 @@
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;
@@ -96,6 +100,13 @@
@Resource
private UserInviteRecordService userInviteRecordService;
+
+ @Resource
+ @Lazy
+ private UserActivedRecordService userActivedRecordService;
+
+ @Resource
+ private UserAccountMsgNotificationService userAccountMsgNotificationService;
@Resource(name = "producer")
private Producer producer;
@@ -347,47 +358,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);
- }
-
- 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
@@ -449,8 +427,9 @@
if (asInputStream == null) {
LogHelper.test("寰俊澶村儚涓嬭浇澶辫触: " + weiXinUser.getUnionid() + " " + headimgurl);
} else {
- FileUploadResult result = COSManager.getInstance().uploadFile(asInputStream, String.format(
- FilePathEnum.userPortrait.getPath() + "%s_%s.jpg", weiXinUser.getUnionid(), System.currentTimeMillis() + ""));
+ FileUploadResult result = COSManager.getInstance().uploadFile(asInputStream,
+ String.format(FilePathEnum.userWXPortrait.getPath() + "%s_%s.jpg", weiXinUser.getUnionid(),
+ System.currentTimeMillis() + ""));
if (result != null && !StringUtil.isNullOrEmpty(result.getUrl())) {
headimgurl = result.getUrl();
} else {
@@ -470,41 +449,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);
- }
- 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
@@ -518,15 +470,6 @@
UserInfo invitee = userInfoService.selectByPKey(uid);
if (invitee == null) {
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();
@@ -568,8 +511,9 @@
if (asInputStream == null) {
LogHelper.test("寰俊澶村儚涓嬭浇澶辫触: " + weiXinUser.getUnionid() + " " + headimgurl);
} else {
- FileUploadResult result = COSManager.getInstance().uploadFile(asInputStream, String.format(
- FilePathEnum.userPortrait.getPath() + "%s_%s.jpg", weiXinUser.getUnionid(), System.currentTimeMillis() + ""));
+ FileUploadResult result = COSManager.getInstance().uploadFile(asInputStream,
+ String.format(FilePathEnum.userWXPortrait.getPath() + "%s_%s.jpg", weiXinUser.getUnionid(),
+ System.currentTimeMillis() + ""));
if (result != null && !StringUtil.isNullOrEmpty(result.getUrl())) {
headimgurl = result.getUrl();
} else {
@@ -590,10 +534,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);
@@ -605,12 +572,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) {
@@ -621,12 +587,18 @@
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 inviteCode;
}
+
+
@Override
public void updateActiveTime(Long uid, Date date) {
@@ -768,6 +740,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;
}
@@ -814,6 +790,11 @@
if (inviter == null) {
throw new UserInfoExtraException(1, "瀵瑰簲鐨勯個璇峰叧绯讳笉瀛樺湪");
}
+
+ if (inviter.getState() != UserInfo.STATE_NORMAL) {
+ throw new UserInfoExtraException(1, "瀵瑰簲鐨勯個璇峰叧绯讳笉瀛樺湪");
+ }
+
return inviter;
}
@@ -822,7 +803,7 @@
userInfoExtraMapper.updateAutoExtract(days);
}
- @Transactional(rollbackFor=Exception.class)
+ @Transactional(rollbackFor = Exception.class)
@Override
public void updateInviteCodeVip(String inviteCodeVip, Long uid) throws UserInfoExtraException {
if (inviteCodeVip == null || inviteCodeVip.length() < 4 || inviteCodeVip.length() > 12)
@@ -857,34 +838,37 @@
update.setInviteCodeVip(inviteCodeVip);
update.setUpdateTime(new Date());
userInfoExtraMapper.updateByPrimaryKeySelective(update);
-
- if(!Constant.IS_TEST) { //鍙戦�侀個璇风爜鏇存敼鎴愬姛鐨勬秷鎭�
+
+ if (!Constant.IS_TEST) { // 鍙戦�侀個璇风爜鏇存敼鎴愬姛鐨勬秷鎭�
Message message = MQMsgBodyFactory.create(MQTopicName.TOPIC_USER, UserTopicTagEnum.userInfoUpdate,
- new Gson().toJson(new UserInfoUpdateMQMsg(uid, UserInfoUpdateTypeEnum.inviteCode, inviteCodeVip, new Date())));
+ new Gson().toJson(new UserInfoUpdateMQMsg(uid, UserInfoUpdateTypeEnum.inviteCode, inviteCodeVip,
+ new Date())));
producer.send(message);
}
+
+ // 娑堟伅
+ userAccountMsgNotificationService.createChangeInviteCode(uid, extra.getInviteCode(), inviteCodeVip);
}
-
-
+
@Override
public void uploadERCode(MultipartFile file, Long uid) {
UserInfoExtra extra = userInfoExtraMapper.getInfoExtraByUid(uid);
if (extra == null)
return;
-
+
// 鍘嬬缉
- String targetPath = FileUtil.getCacheDir() + "/erCode_" + uid + "_" + System.currentTimeMillis()+ ".jpg";
+ String targetPath = FileUtil.getCacheDir() + "/erCode_" + uid + "_" + System.currentTimeMillis() + ".jpg";
try {
Thumbnails.of(file.getInputStream()).size(200, 200).toFile(targetPath);
} catch (IOException e) {
LogHelper.errorDetailInfo(e);
return;
}
-
+
// 鎵ц涓婁紶
String filePath = FilePathEnum.userERcode.getPath() + UUID.randomUUID().toString().replace("-", "") + ".jpg";
String fileLink = COSManager.getInstance().uploadFile(new File(targetPath), filePath).getUrl();
-
+
// 鍒犻櫎鏈湴鍥剧墖
if (new File(targetPath).exists()) {
new File(targetPath).delete();
@@ -892,7 +876,7 @@
// 鍘熶簩缁寸爜
String erCode = extra.getErCode();
-
+
UserInfoExtra update = new UserInfoExtra();
update.setId(extra.getId());
update.setErCode(fileLink);
@@ -903,4 +887,5 @@
COSManager.getInstance().deleteFile(erCode);
}
}
+
}
--
Gitblit v1.8.0