关注好友时添加发送消息业务

main
wangqing 12 months ago
parent aaa24e442b
commit abe80d4eea

@ -20,10 +20,23 @@ public class UserMessageDto implements Serializable {
private String messageId; private String messageId;
/** /**
* ID * ID
*/ */
private String userId; private String userId;
/**
* 1 23 4 5.
*/
private Integer type;
/**
* ,icon
*/
private String sendUserAvatar;
private String sendUserId;
private String sendUserNickName;
/** /**
* *

@ -3,11 +3,15 @@ package com.luoo.user.controller;
import api.Result; import api.Result;
import api.StatusCode; import api.StatusCode;
import com.luoo.user.pojo.UserInfo;
import com.luoo.user.service.FriendService; import com.luoo.user.service.FriendService;
import com.luoo.user.service.UserInfoService; import com.luoo.user.service.UserInfoService;
import constants.Constants;
import controller.BaseController; import controller.BaseController;
import dto.UserLoginDto; import dto.UserLoginDto;
import dto.UserMessageDto;
import io.jsonwebtoken.Claims; import io.jsonwebtoken.Claims;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -26,6 +30,9 @@ public class FriendController extends BaseController {
@Autowired @Autowired
private UserInfoService userInfoService; private UserInfoService userInfoService;
@Autowired
private RabbitTemplate rabbitTemplate;
/** /**
* 12 * 12
@ -37,7 +44,7 @@ public class FriendController extends BaseController {
//验证是否登录并且拿到ID //验证是否登录并且拿到ID
String token = (String) request.getAttribute("claims_user"); String token = (String) request.getAttribute("claims_user");
UserLoginDto userLoginDto = getUserLoginDto(token); UserLoginDto userLoginDto = getUserLoginDto("Bearer "+token);
if (null == userLoginDto) { if (null == userLoginDto) {
return Result.unauthorized(null); return Result.unauthorized(null);
} }
@ -52,6 +59,20 @@ public class FriendController extends BaseController {
} }
if (flag == 1) { if (flag == 1) {
userInfoService.updatefanscountandfollowcount(1,userid,friendid); 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(); return Result.success();
} }

@ -9,6 +9,9 @@ import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import util.IdWorker;
import java.util.Date;
@Component @Component
@RabbitListener(queues = "userMessage") @RabbitListener(queues = "userMessage")
@ -17,12 +20,18 @@ public class UserMessageListener {
@Autowired @Autowired
private UserMessageDao userMessageDao; private UserMessageDao userMessageDao;
@Autowired
private IdWorker idWorker;
@RabbitHandler @RabbitHandler
public void executeSendUserMessage(UserMessageDto userMessageDto) { public void executeSendUserMessage(UserMessageDto userMessageDto) {
UserMessage userMessage = new UserMessage(); UserMessage userMessage = new UserMessage();
BeanUtils.copyProperties(userMessageDto,userMessage); BeanUtils.copyProperties(userMessageDto,userMessage);
userMessage.setMessageId(idWorker.nextId()+""); //id
userMessage.setHaveRead(0); //初始状态未读
userMessage.setSendTime(new Date()); //消息产生的时间
userMessageDao.save(userMessage); userMessageDao.save(userMessage);
} }

@ -22,11 +22,24 @@ public class UserMessage implements Serializable {
private String messageId; private String messageId;
/** /**
* ID * ID
*/ */
private String userId; private String userId;
/**
* 1 23 4 5.
*/
private Integer type;
/**
* ,icon
*/
private String sendUserAvatar;
private String sendUserId;
private String sendUserNickName;
/** /**
* *
*/ */

@ -35,9 +35,6 @@ public class UserMessageService {
public void sendUserMessage(UserMessageDto userMessageDto) { public void sendUserMessage(UserMessageDto userMessageDto) {
userMessageDto.setMessageId(idWorker.nextId()+"");
userMessageDto.setHaveRead(0);
userMessageDto.setSendTime(new Date());
rabbitTemplate.convertAndSend("userMessage",userMessageDto); rabbitTemplate.convertAndSend("userMessage",userMessageDto);
} }

Loading…
Cancel
Save