diff --git a/luoo_comment/src/main/java/com/luoo/comment/pojo/UserInfo.java b/luoo_comment/src/main/java/com/luoo/comment/pojo/UserInfo.java index bbdbfd5..9ec5d85 100644 --- a/luoo_comment/src/main/java/com/luoo/comment/pojo/UserInfo.java +++ b/luoo_comment/src/main/java/com/luoo/comment/pojo/UserInfo.java @@ -136,4 +136,13 @@ public class UserInfo implements Serializable { private int onlineStatus; private String badges; + + /** + * 是否启用通知 + */ + private int enableNotice; + /** + * 是否启用推送 + */ + private int enablePush; } diff --git a/luoo_comment/src/main/java/com/luoo/comment/service/CommentService.java b/luoo_comment/src/main/java/com/luoo/comment/service/CommentService.java index c8e4665..d72364a 100644 --- a/luoo_comment/src/main/java/com/luoo/comment/service/CommentService.java +++ b/luoo_comment/src/main/java/com/luoo/comment/service/CommentService.java @@ -106,7 +106,12 @@ public class CommentService { commentHis.setJournalId(parentComment.getJournalId()); commentHis.setJournalImage(parentComment.getJournalImage()); commentHis.setCreateTime(new Date()); - commentHisDao.save(commentHis); + UserInfo parentCommentUser =userInfoService.findById(parentComment.getUserId()); + if (0 != parentCommentUser.getEnableNotice()) { + commentHisDao.save(commentHis); + } + + comment.setJournalId("");//如果有父节点,将期刊号置为空 // 将parentComment的rootID值带过来 @@ -134,7 +139,10 @@ public class CommentService { userMessageDto.setSendUserAvatar(Constants.RESOURCE_PREFIX+userLoginDto.getAvatar()); userMessageDto.setSendUserId(userLoginDto.getUserId()); userMessageDto.setSendUserNickName(userLoginDto.getNickName()); - rabbitTemplate.convertAndSend("userMessage",userMessageDto); + if (0 != parentCommentUser.getEnableNotice()) { + rabbitTemplate.convertAndSend("userMessage",userMessageDto); + } + @@ -232,18 +240,22 @@ public class CommentService { mongoTemplate.updateFirst(query,update,"comment"); Comment parentComment = commentDao.findById(commentId).get(); - /** - * 向被点赞者发消息 - */ - UserMessageDto userMessageDto = new UserMessageDto(); - userMessageDto.setType(MessageTypeEnum.THUMB_UP.getType()); //消息类型 1私信 ,2新赞,3新关注, 4新评论 5.系统消息 - userMessageDto.setUserId(parentComment.getUserId()); - userMessageDto.setContent(userLoginDto.getNickName()+" 点赞了你的评论"); - userMessageDto.setTitle("您有新的点赞"); - userMessageDto.setSendUserAvatar(Constants.RESOURCE_PREFIX+userLoginDto.getAvatar()); - userMessageDto.setSendUserId(userLoginDto.getUserId()); - userMessageDto.setSendUserNickName(userLoginDto.getNickName()); - rabbitTemplate.convertAndSend("userMessage",userMessageDto); + UserInfo parentCommentUser =userInfoService.findById(parentComment.getUserId()); + if (0 != parentCommentUser.getEnableNotice()) { + /** + * 向被点赞者发消息 + */ + UserMessageDto userMessageDto = new UserMessageDto(); + userMessageDto.setType(MessageTypeEnum.THUMB_UP.getType()); //消息类型 1私信 ,2新赞,3新关注, 4新评论 5.系统消息 + userMessageDto.setUserId(parentComment.getUserId()); + userMessageDto.setContent(userLoginDto.getNickName()+" 点赞了你的评论"); + userMessageDto.setTitle("您有新的点赞"); + userMessageDto.setSendUserAvatar(Constants.RESOURCE_PREFIX+userLoginDto.getAvatar()); + userMessageDto.setSendUserId(userLoginDto.getUserId()); + userMessageDto.setSendUserNickName(userLoginDto.getNickName()); + rabbitTemplate.convertAndSend("userMessage",userMessageDto); + } + } public Page search(int page, int size) { diff --git a/luoo_user/src/main/java/com/luoo/user/controller/MyController.java b/luoo_user/src/main/java/com/luoo/user/controller/MyController.java index d38b643..5c5c31b 100644 --- a/luoo_user/src/main/java/com/luoo/user/controller/MyController.java +++ b/luoo_user/src/main/java/com/luoo/user/controller/MyController.java @@ -121,6 +121,14 @@ public class MyController extends BaseController { userRespDTO.setAppleId(user.getAppleId()); userRespDTO.setWxNickname(user.getWxNickname()); userRespDTO.setAppleEmail(user.getAppleEmail()); + userRespDTO.setEnableNotice(1); + userRespDTO.setEnablePush(1); + if (0 ==user.getEnableNotice()) { + userRespDTO.setEnableNotice(0); + } + if (0 == user.getEnablePush()) { + userRespDTO.setEnablePush(0); + } return Result.success(userRespDTO); } @@ -514,8 +522,35 @@ public class MyController extends BaseController { return Result.success(token); } + @ApiOperation(value = "14.1 启用/停用 消息, 0为停用,1为启用", notes = "启用/停用 消息, 0为停用,1为启用") + @PutMapping("/enableNotice/{flag}") + public Result updateEnableNotice(@RequestHeader(value = "Authorization", required = true) String authorization,@PathVariable int flag){ + //验证是否登录,并且拿到ID + UserLoginDto userLoginDto = getUserLoginDto(authorization); + if (null == userLoginDto) { + return Result.unauthorized(null); + } + String userId = userLoginDto.getUserId(); + UserInfo userInfo = userInfoService.findById(userId); + userInfo.setEnableNotice(flag); + userInfoService.update(userInfo); + return Result.success(); + } - + @ApiOperation(value = "14.2 启用/停用 推送, 0为停用,1为启用", notes = "启用/停用 推送, 0为停用,1为启用") + @PutMapping("/enablePush/{flag}") + public Result updateEnablePush(@RequestHeader(value = "Authorization", required = true) String authorization,@PathVariable int flag){ + //验证是否登录,并且拿到ID + UserLoginDto userLoginDto = getUserLoginDto(authorization); + if (null == userLoginDto) { + return Result.unauthorized(null); + } + String userId = userLoginDto.getUserId(); + UserInfo userInfo = userInfoService.findById(userId); + userInfo.setEnablePush(flag); + userInfoService.update(userInfo); + return Result.success(); + } private Integer getIndex(UserInfo u) { return Integer.valueOf(Arrays.stream(u.getBadges().split(",")).filter(s->s.startsWith(String.valueOf(UserBadgeEnum.CONTRIBUTOR.getCode()))).findFirst().get().split("_")[1]); } diff --git a/luoo_user/src/main/java/com/luoo/user/dto/response/UserRespDTO.java b/luoo_user/src/main/java/com/luoo/user/dto/response/UserRespDTO.java index f042f37..14e758f 100644 --- a/luoo_user/src/main/java/com/luoo/user/dto/response/UserRespDTO.java +++ b/luoo_user/src/main/java/com/luoo/user/dto/response/UserRespDTO.java @@ -59,4 +59,15 @@ public class UserRespDTO implements Serializable { @ApiModelProperty(value = "apple绑定的邮箱") private String appleEmail; + + /** + * 是否启用通知 + */ + @ApiModelProperty(value = "是否启用通知,0为关闭,1为启用,默认启用") + private int enableNotice; + /** + * 是否启用推送 + */ + @ApiModelProperty(value = "是否启用推送,0为关闭,1为启用,默认启用") + private int enablePush; } diff --git a/luoo_user/src/main/java/com/luoo/user/pojo/UserInfo.java b/luoo_user/src/main/java/com/luoo/user/pojo/UserInfo.java index 0b81bc0..72f4787 100644 --- a/luoo_user/src/main/java/com/luoo/user/pojo/UserInfo.java +++ b/luoo_user/src/main/java/com/luoo/user/pojo/UserInfo.java @@ -160,4 +160,13 @@ public class UserInfo implements Serializable { private int onlineStatus; private String badges; + + /** + * 是否启用通知 + */ + private int enableNotice; + /** + * 是否启用推送 + */ + private int enablePush; } diff --git a/luoo_user/src/main/java/com/luoo/user/service/UserCollectInfoService.java b/luoo_user/src/main/java/com/luoo/user/service/UserCollectInfoService.java index dad15df..535248f 100644 --- a/luoo_user/src/main/java/com/luoo/user/service/UserCollectInfoService.java +++ b/luoo_user/src/main/java/com/luoo/user/service/UserCollectInfoService.java @@ -277,7 +277,12 @@ public class UserCollectInfoService { userInfoDao.save(other); // 向他人发送 新粉丝 消息 - sendMessageToFollows(user, objectId); + + UserInfo followUserInfo =userInfoDao.findById(objectId).get(); + if (0 != followUserInfo.getEnableNotice()) { + sendMessageToFollows(user, objectId); + } + } private void sendMessageToFollows(UserInfo userInfo, String followId) { diff --git a/luoo_user/src/main/java/com/luoo/user/service/WeChatAouth2Service.java b/luoo_user/src/main/java/com/luoo/user/service/WeChatAouth2Service.java index f8a7855..009db53 100644 --- a/luoo_user/src/main/java/com/luoo/user/service/WeChatAouth2Service.java +++ b/luoo_user/src/main/java/com/luoo/user/service/WeChatAouth2Service.java @@ -275,7 +275,7 @@ public class WeChatAouth2Service { log.info("getWechatName:" + string); Aouth2WeChatUserinfoResponse aouth2WeChatTokenResponse = JSON.parseObject(string, Aouth2WeChatUserinfoResponse.class); - return aouth2WeChatTokenResponse.getNickname(); + return new String(aouth2WeChatTokenResponse.getNickname().getBytes(StandardCharsets.ISO_8859_1),StandardCharsets.UTF_8); } public Aouth2WeChatTokenResponse refreshAccessToken(String refresh_token) {