diff --git a/luoo_common/src/main/java/dto/UserMessageDto.java b/luoo_common/src/main/java/dto/UserMessageDto.java index d0c9b9f..c724718 100644 --- a/luoo_common/src/main/java/dto/UserMessageDto.java +++ b/luoo_common/src/main/java/dto/UserMessageDto.java @@ -20,10 +20,23 @@ public class UserMessageDto implements Serializable { private String messageId; /** - * 消息ID + * 接收人ID */ private String userId; + /** + * 消息类型 1新评论 ,2新赞,3新关注, 4私信 5.系统消息 + */ + private Integer type; + + /** + * 当消息类型是新评论 新评论 新赞 新关注 私信时,显示发起用户的头像,当时系统消息时,显示默认系统消息icon。 + */ + private String sendUserAvatar; + + private String sendUserId; + + private String sendUserNickName; /** * 消息标题 diff --git a/luoo_user/src/main/java/com/luoo/user/controller/FriendController.java b/luoo_user/src/main/java/com/luoo/user/controller/FriendController.java index 84a7399..6a167af 100644 --- a/luoo_user/src/main/java/com/luoo/user/controller/FriendController.java +++ b/luoo_user/src/main/java/com/luoo/user/controller/FriendController.java @@ -3,11 +3,15 @@ package com.luoo.user.controller; import api.Result; import api.StatusCode; +import com.luoo.user.pojo.UserInfo; import com.luoo.user.service.FriendService; import com.luoo.user.service.UserInfoService; +import constants.Constants; import controller.BaseController; import dto.UserLoginDto; +import dto.UserMessageDto; import io.jsonwebtoken.Claims; +import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -26,6 +30,9 @@ public class FriendController extends BaseController { @Autowired private UserInfoService userInfoService; + @Autowired + private RabbitTemplate rabbitTemplate; + /** * 添加好友或者添加非好友(关注还是拉黑) 1是关注,2是拉黑 @@ -37,7 +44,7 @@ public class FriendController extends BaseController { //验证是否登录,并且拿到ID String token = (String) request.getAttribute("claims_user"); - UserLoginDto userLoginDto = getUserLoginDto(token); + UserLoginDto userLoginDto = getUserLoginDto("Bearer "+token); if (null == userLoginDto) { return Result.unauthorized(null); } @@ -52,6 +59,20 @@ public class FriendController extends BaseController { } if (flag == 1) { userInfoService.updatefanscountandfollowcount(1,userid,friendid); + + UserInfo userInfo =userInfoService.findById(userid); + /** + * 向friend发送消息 + */ + UserMessageDto userMessageDto = new UserMessageDto(); + userMessageDto.setType(3); //消息类型 1新评论 ,2新赞,3新关注, 4私信 5.系统消息 + userMessageDto.setUserId(friendid); + userMessageDto.setContent(userInfo.getNickName()+" 关注了你"); + userMessageDto.setTitle("您有新的粉丝"); + userMessageDto.setSendUserAvatar(Constants.RESOURCE_PREFIX+userInfo.getAvatar()); + userMessageDto.setSendUserId(userid); + userMessageDto.setSendUserNickName(userInfo.getNickName()); + rabbitTemplate.convertAndSend("userMessage",userMessageDto); return Result.success(); } diff --git a/luoo_user/src/main/java/com/luoo/user/listener/UserMessageListener.java b/luoo_user/src/main/java/com/luoo/user/listener/UserMessageListener.java index 79a706a..239328a 100644 --- a/luoo_user/src/main/java/com/luoo/user/listener/UserMessageListener.java +++ b/luoo_user/src/main/java/com/luoo/user/listener/UserMessageListener.java @@ -9,6 +9,9 @@ import org.springframework.amqp.rabbit.annotation.RabbitListener; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import util.IdWorker; + +import java.util.Date; @Component @RabbitListener(queues = "userMessage") @@ -17,12 +20,18 @@ public class UserMessageListener { @Autowired private UserMessageDao userMessageDao; + @Autowired + private IdWorker idWorker; + @RabbitHandler public void executeSendUserMessage(UserMessageDto userMessageDto) { UserMessage userMessage = new UserMessage(); BeanUtils.copyProperties(userMessageDto,userMessage); + userMessage.setMessageId(idWorker.nextId()+""); //id + userMessage.setHaveRead(0); //初始状态未读 + userMessage.setSendTime(new Date()); //消息产生的时间 userMessageDao.save(userMessage); } diff --git a/luoo_user/src/main/java/com/luoo/user/pojo/UserMessage.java b/luoo_user/src/main/java/com/luoo/user/pojo/UserMessage.java index 12102e8..c4b1ea7 100644 --- a/luoo_user/src/main/java/com/luoo/user/pojo/UserMessage.java +++ b/luoo_user/src/main/java/com/luoo/user/pojo/UserMessage.java @@ -22,11 +22,24 @@ public class UserMessage implements Serializable { private String messageId; /** - * 消息ID + * 接收人ID */ private String userId; + /** + * 消息类型 1新评论 ,2新赞,3新关注, 4私信 5.系统消息 + */ + private Integer type; + + /** + * 当消息类型是新评论 新评论 新赞 新关注 私信时,显示发起用户的头像,当时系统消息时,显示默认系统消息icon。 + */ + private String sendUserAvatar; + + private String sendUserId; + + private String sendUserNickName; /** * 消息标题 */ diff --git a/luoo_user/src/main/java/com/luoo/user/service/UserMessageService.java b/luoo_user/src/main/java/com/luoo/user/service/UserMessageService.java index 533c1d9..98ef26a 100644 --- a/luoo_user/src/main/java/com/luoo/user/service/UserMessageService.java +++ b/luoo_user/src/main/java/com/luoo/user/service/UserMessageService.java @@ -35,9 +35,6 @@ public class UserMessageService { public void sendUserMessage(UserMessageDto userMessageDto) { - userMessageDto.setMessageId(idWorker.nextId()+""); - userMessageDto.setHaveRead(0); - userMessageDto.setSendTime(new Date()); rabbitTemplate.convertAndSend("userMessage",userMessageDto); }