From 06bbeaeb73178a6cff0f207a1a284a73f6445e25 Mon Sep 17 00:00:00 2001 From: yujian <yujian@163.com> Date: 星期四, 02 四月 2020 17:04:13 +0800 Subject: [PATCH] 消息 --- fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserInfoExtraServiceImpl.java | 108 +++++++++++++++++++++++++++++++++++++++-------------- 1 files changed, 79 insertions(+), 29 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 f009215..31a5a30 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,8 @@ 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; import com.yeshi.fanli.log.LogHelper; @@ -51,7 +54,9 @@ 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.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.util.account.UserUtil; @@ -95,6 +100,10 @@ @Resource private UserInviteRecordService userInviteRecordService; + @Resource + @Lazy + private UserActivedRecordService userActivedRecordService; + @Resource(name = "producer") private Producer producer; @@ -107,10 +116,10 @@ } // 绛夌骇瀵圭収琛� - String contrast = configService.get("user_rank_contrast"); + String contrast = configService.get(ConfigKeyEnum.userRankContrast.getKey()); extraVO.setRankContrast(contrast); // 鐗瑰埆鎻愰啋 - String rankTip = configService.get("user_rank_tip"); + String rankTip = configService.get(ConfigKeyEnum.userRankTip.getKey()); extraVO.setRankTip(rankTip); Integer rankOrderNum = extraVO.getRankOrderNum(); @@ -347,7 +356,7 @@ inviteCode = inviteCode.toUpperCase(); // 閭�璇风爜瀵瑰簲鐢ㄦ埛淇℃伅 UserInfo inviter = userInfoService.getUserInfoByInviteCode(inviteCode); - if (inviter == null) + if (inviter == null || inviter.getState() != UserInfo.STATE_NORMAL) throw new UserInfoExtraException(1, "涓婄骇閭�璇风爜涓嶅瓨鍦�"); // 缁戝畾鍏崇郴 @@ -378,11 +387,13 @@ userInfoExtra.setCreateTime(new Date()); userInfoExtraMapper.insertSelective(userInfoExtra); } + userActivedRecordService.add(new UserActivedRecord(uid)); - // 鍙戦�佹縺娲绘垚鍔熸秷鎭� - Message message = MQMsgBodyFactory.create(MQTopicName.TOPIC_USER, UserTopicTagEnum.inviteCodeActive, - new Gson().toJson(new InviteCodeActiveMQMsg(uid, new Date()))); - producer.send(message); + 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; } @@ -446,8 +457,9 @@ if (asInputStream == null) { LogHelper.test("寰俊澶村儚涓嬭浇澶辫触: " + weiXinUser.getUnionid() + " " + headimgurl); } else { - FileUploadResult result = COSManager.getInstance().uploadFile(asInputStream, String.format( - "/portrait/wx/%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 { @@ -467,6 +479,11 @@ Long inviterId = userInviteRecordService.getNewestInviterId(wxUnionId); if (inviterId == null) throw new UserInfoExtraException(1, "娌℃湁瀵瑰簲鐨勯個璇峰叧绯�"); + + UserInfo boss = userInfoService.selectByPKey(inviterId); + if (boss == null || boss.getState() != UserInfo.STATE_NORMAL) { + throw new UserInfoExtraException(1, "娌℃湁瀵瑰簲鐨勯個璇峰叧绯�"); + } // 缁戝畾鍏崇郴 try { @@ -496,10 +513,14 @@ 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); + 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); + } } @Override @@ -563,8 +584,9 @@ if (asInputStream == null) { LogHelper.test("寰俊澶村儚涓嬭浇澶辫触: " + weiXinUser.getUnionid() + " " + headimgurl); } else { - FileUploadResult result = COSManager.getInstance().uploadFile(asInputStream, String.format( - "/portrait/wx/%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 { @@ -583,6 +605,11 @@ // 閭�璇蜂汉ID -1.5.3鏂扮増 Long inviterId = userInviteRecordService.getNewestInviterId(wxUnionId); if (inviterId == null) { + throw new UserInfoExtraException(1, "娌℃湁瀵瑰簲鐨勯個璇峰叧绯�"); + } + + UserInfo boss = userInfoService.selectByPKey(inviterId); + if (boss == null || boss.getState() != UserInfo.STATE_NORMAL) { throw new UserInfoExtraException(1, "娌℃湁瀵瑰簲鐨勯個璇峰叧绯�"); } @@ -614,6 +641,14 @@ } 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); } } @@ -757,6 +792,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; } @@ -803,6 +842,11 @@ if (inviter == null) { throw new UserInfoExtraException(1, "瀵瑰簲鐨勯個璇峰叧绯讳笉瀛樺湪"); } + + if (inviter.getState() != UserInfo.STATE_NORMAL) { + throw new UserInfoExtraException(1, "瀵瑰簲鐨勯個璇峰叧绯讳笉瀛樺湪"); + } + return inviter; } @@ -811,7 +855,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) @@ -846,36 +890,41 @@ 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); + + 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); + } } - - + @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 = "/img/user/erCode/" + UUID.randomUUID().toString().replace("-", "") + ".jpg"; + 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(); } + + // 鍘熶簩缁寸爜 + String erCode = extra.getErCode(); UserInfoExtra update = new UserInfoExtra(); update.setId(extra.getId()); @@ -883,8 +932,9 @@ userInfoExtraMapper.updateByPrimaryKeySelective(update); // 鍘熶簩缁寸爜 - if (!StringUtil.isNullOrEmpty(extra.getErCode())) { - COSManager.getInstance().deleteFile(extra.getErCode()); + if (!StringUtil.isNullOrEmpty(erCode)) { + COSManager.getInstance().deleteFile(erCode); } } + } -- Gitblit v1.8.0