From bf7711423a8ffa68549e1a1316099f838bd79ac8 Mon Sep 17 00:00:00 2001 From: wangqing <408564126@qq.com> Date: Tue, 30 Jan 2024 18:07:47 +0800 Subject: [PATCH] send message when collect a friend --- .../controller/UserCollectController.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/luoo_user/src/main/java/com/luoo/user/controller/UserCollectController.java b/luoo_user/src/main/java/com/luoo/user/controller/UserCollectController.java index 9e1348c..9b633e7 100644 --- a/luoo_user/src/main/java/com/luoo/user/controller/UserCollectController.java +++ b/luoo_user/src/main/java/com/luoo/user/controller/UserCollectController.java @@ -3,12 +3,18 @@ package com.luoo.user.controller; import annotation.GlobalInterceptor; import annotation.VerifyParam; import api.Result; +import com.luoo.user.pojo.UserInfo; import com.luoo.user.service.UserCollectService; +import com.luoo.user.service.UserInfoService; +import constants.Constants; import dto.UserLoginDto; +import dto.UserMessageDto; +import enums.MessageTypeEnum; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; +import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import util.JwtUtil; @@ -22,6 +28,12 @@ public class UserCollectController { @Autowired private UserCollectService userCollectService; + @Autowired + private UserInfoService userInfoService; + + @Autowired + private RabbitTemplate rabbitTemplate; + //@ApiOperation(value = "1.喜欢歌曲/收藏期刊/关注/黑名单/点赞") @ApiOperation(value = "1.喜欢歌曲/收藏期刊/关注/黑名单") @ApiImplicitParams({ @@ -36,6 +48,24 @@ public class UserCollectController { @VerifyParam(required = true) @RequestParam("collectType") Integer collectType) { UserLoginDto loginDto = jwtUtil.getUserLoginDto(authorization); userCollectService.saveCollect(loginDto.getUserId(), objectId, collectType); + + if(collectType==2) { + + UserInfo userInfo =userInfoService.findById(loginDto.getUserId()); + /** + * 向friend发送消息 + */ + UserMessageDto userMessageDto = new UserMessageDto(); + userMessageDto.setType(MessageTypeEnum.FOLLOW.getType()); //消息类型 1私信 ,2新赞,3新关注, 4新评论 5.系统消息 + userMessageDto.setUserId(objectId); + userMessageDto.setContent(userInfo.getNickName()+" 关注了你"); + userMessageDto.setTitle("您有新的粉丝"); + userMessageDto.setSendUserAvatar(Constants.RESOURCE_PREFIX+userInfo.getAvatar()); + userMessageDto.setSendUserId(userInfo.getId()); + userMessageDto.setSendUserNickName(userInfo.getNickName()); + rabbitTemplate.convertAndSend("userMessage",userMessageDto); + } + return Result.success(); }