Commit a095d0f4 authored by 刘基明's avatar 刘基明

消息通知 fix

parent 1fc721e0
...@@ -32,13 +32,11 @@ import com.tanpu.community.service.NotificationService; ...@@ -32,13 +32,11 @@ import com.tanpu.community.service.NotificationService;
import com.tanpu.community.service.ThemeService; import com.tanpu.community.service.ThemeService;
import com.tanpu.community.service.TopicService; import com.tanpu.community.service.TopicService;
import com.tanpu.community.util.ConvertUtil; import com.tanpu.community.util.ConvertUtil;
import com.tanpu.community.util.TimeUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -153,7 +151,7 @@ public class NotificationManager { ...@@ -153,7 +151,7 @@ public class NotificationManager {
for (FollowRelEntity followRelEntity : followRelEntities) { for (FollowRelEntity followRelEntity : followRelEntities) {
notificationService.insert(followRelEntity.getFansId(), followRelEntity.getIdolId(), NotificationTypeEnum.FOLLOW notificationService.insert(followRelEntity.getFansId(), followRelEntity.getIdolId(), NotificationTypeEnum.FOLLOW
, followRelEntity.getFansId(), "", followRelEntity.getUpdateTime()); , followRelEntity.getFansId(), "", followRelEntity.getUpdateTime());
messageNotifyFollow(followRelEntity.getIdolId(), followRelEntity.getFansId()); notificationService.putNotifyCacheFollow(followRelEntity.getIdolId(), followRelEntity.getFansId());
} }
// 转发 // 转发
List<ThemeEntity> themeEntities = themeService.queryAllForward(); List<ThemeEntity> themeEntities = themeService.queryAllForward();
...@@ -168,7 +166,7 @@ public class NotificationManager { ...@@ -168,7 +166,7 @@ public class NotificationManager {
NotificationForwardDO content = NotificationForwardDO.builder().content(s.length() > 500 ? s.substring(0, 500) : s).topicId(themeEntity.getTopicId()).build(); NotificationForwardDO content = NotificationForwardDO.builder().content(s.length() > 500 ? s.substring(0, 500) : s).topicId(themeEntity.getTopicId()).build();
notificationService.insert(themeEntity.getAuthorId(), former.getAuthorId(), NotificationTypeEnum.FORWARD notificationService.insert(themeEntity.getAuthorId(), former.getAuthorId(), NotificationTypeEnum.FORWARD
, themeEntity.getFormerThemeId(), JsonUtil.toJson(content), themeEntity.getUpdateTime()); , themeEntity.getFormerThemeId(), JsonUtil.toJson(content), themeEntity.getUpdateTime());
messageNotify(former.getAuthorId(), themeEntity.getAuthorId(), NotificationTypeEnum.FORWARD); notificationService.putNotifyCache(former.getAuthorId(), themeEntity.getAuthorId(), NotificationTypeEnum.FORWARD);
} }
// 评论 // 评论
List<CommentEntity> commentEntities = commentService.queryAll(); List<CommentEntity> commentEntities = commentService.queryAll();
...@@ -180,7 +178,7 @@ public class NotificationManager { ...@@ -180,7 +178,7 @@ public class NotificationManager {
String s = commentEntity.getContent(); String s = commentEntity.getContent();
notificationService.insert(commentEntity.getAuthorId(), themeEntity.getAuthorId(), NotificationTypeEnum.COMMENT notificationService.insert(commentEntity.getAuthorId(), themeEntity.getAuthorId(), NotificationTypeEnum.COMMENT
, commentEntity.getThemeId(), s, commentEntity.getUpdateTime()); , commentEntity.getThemeId(), s, commentEntity.getUpdateTime());
messageNotify(themeEntity.getAuthorId(), commentEntity.getAuthorId(), NotificationTypeEnum.COMMENT); notificationService.putNotifyCache(themeEntity.getAuthorId(), commentEntity.getAuthorId(), NotificationTypeEnum.COMMENT);
} }
// 点赞 // 点赞
...@@ -191,7 +189,7 @@ public class NotificationManager { ...@@ -191,7 +189,7 @@ public class NotificationManager {
continue; continue;
} }
notificationService.insertLike(collectionEntity.getUserId(), themeEntity.getAuthorId(), collectionEntity.getTargetId(), collectionEntity.getUpdateTime()); notificationService.insertLike(collectionEntity.getUserId(), themeEntity.getAuthorId(), collectionEntity.getTargetId(), collectionEntity.getUpdateTime());
messageNotify(themeEntity.getAuthorId(), collectionEntity.getUserId(), NotificationTypeEnum.LIKE); notificationService.putNotifyCache(themeEntity.getAuthorId(), collectionEntity.getUserId(), NotificationTypeEnum.LIKE);
} }
} }
...@@ -211,21 +209,6 @@ public class NotificationManager { ...@@ -211,21 +209,6 @@ public class NotificationManager {
} }
// 消息通知队列缓存
private void messageNotify(String notifyUserId, String operatorId, NotificationTypeEnum type) {
UserInfoResp userInfo = getUserInfo(operatorId);
redisCache.incr(RedisKeyConstant.MESSAGE_NOTIFY_COUNT + notifyUserId);
redisCache.set(RedisKeyConstant.MESSAGE_NOTIFY_LAST_MSG + notifyUserId, userInfo.getNickName() + type.getType() + "了你的内容", 60 * 60 * 24 * 30);
redisCache.set(RedisKeyConstant.MESSAGE_NOTIFY_LAST_TIME + notifyUserId, TimeUtils.format(LocalDateTime.now()), 60 * 60 * 24 * 30);
}
// 消息通知队列缓存
private void messageNotifyFollow(String notifyUserId, String operatorId) {
UserInfoResp userInfo = getUserInfo(operatorId);
redisCache.incr(RedisKeyConstant.MESSAGE_NOTIFY_COUNT + notifyUserId);
redisCache.set(RedisKeyConstant.MESSAGE_NOTIFY_LAST_MSG + notifyUserId, userInfo.getNickName() + "关注了你", 60 * 60 * 24 * 30);
redisCache.set(RedisKeyConstant.MESSAGE_NOTIFY_LAST_TIME + notifyUserId, TimeUtils.format(LocalDateTime.now()), 60 * 60 * 24 * 30);
}
private UserInfoResp getUserInfo(String authorId) { private UserInfoResp getUserInfo(String authorId) {
CommonResp<UserInfoResp> userInfoNewCommonResp = feignClientForFatools.queryUserInfoNew(authorId); CommonResp<UserInfoResp> userInfoNewCommonResp = feignClientForFatools.queryUserInfoNew(authorId);
......
...@@ -32,7 +32,6 @@ import com.tanpu.community.api.beans.vo.ImagesDTO; ...@@ -32,7 +32,6 @@ import com.tanpu.community.api.beans.vo.ImagesDTO;
import com.tanpu.community.api.beans.vo.feign.fatools.UserInfoResp; import com.tanpu.community.api.beans.vo.feign.fatools.UserInfoResp;
import com.tanpu.community.api.beans.vo.feign.newsfeed.NewsFeedResReq; import com.tanpu.community.api.beans.vo.feign.newsfeed.NewsFeedResReq;
import com.tanpu.community.api.beans.vo.feign.newsfeed.NewsFeedSave4NewCommReq; import com.tanpu.community.api.beans.vo.feign.newsfeed.NewsFeedSave4NewCommReq;
import com.tanpu.community.api.constants.RedisKeyConstant;
import com.tanpu.community.api.enums.BlockTypeEnum; import com.tanpu.community.api.enums.BlockTypeEnum;
import com.tanpu.community.api.enums.DeleteTagEnum; import com.tanpu.community.api.enums.DeleteTagEnum;
import com.tanpu.community.api.enums.NotificationTypeEnum; import com.tanpu.community.api.enums.NotificationTypeEnum;
...@@ -416,7 +415,7 @@ public class ThemeManager { ...@@ -416,7 +415,7 @@ public class ThemeManager {
// 消息通知 // 消息通知
ThemeEntity formerTheme = themeService.queryByThemeId(req.getFormerThemeId()); ThemeEntity formerTheme = themeService.queryByThemeId(req.getFormerThemeId());
notificationService.insertForward(userId, formerTheme.getAuthorId(), formerTheme.getThemeId(), req.getTopicId(), req.getContent().get(0).getValue()); notificationService.insertForward(userId, formerTheme.getAuthorId(), formerTheme.getThemeId(), req.getTopicId(), req.getContent().get(0).getValue());
messageNotify(formerTheme.getAuthorId(),userId,NotificationTypeEnum.FORWARD); notificationService.putNotifyCache(formerTheme.getAuthorId(),userId,NotificationTypeEnum.FORWARD);
} else { } else {
// 修改 // 修改
...@@ -672,7 +671,7 @@ public class ThemeManager { ...@@ -672,7 +671,7 @@ public class ThemeManager {
ThemeEntity themeEntity = themeService.queryByThemeId(req.getThemeId()); ThemeEntity themeEntity = themeService.queryByThemeId(req.getThemeId());
// 消息通知 // 消息通知
notificationService.insertLike(userId, themeEntity.getAuthorId(), req.getThemeId()); notificationService.insertLike(userId, themeEntity.getAuthorId(), req.getThemeId());
messageNotify(themeEntity.getAuthorId(),userId,NotificationTypeEnum.LIKE); notificationService.putNotifyCache(themeEntity.getAuthorId(),userId,NotificationTypeEnum.LIKE);
} }
} else if (OperationTypeEnum.CANCEL.getCode().equals(req.getType())) { } else if (OperationTypeEnum.CANCEL.getCode().equals(req.getType())) {
...@@ -927,12 +926,4 @@ public class ThemeManager { ...@@ -927,12 +926,4 @@ public class ThemeManager {
redisCache.evict(StringUtils.joinWith("_", CACHE_THEME_ID, themeId)); redisCache.evict(StringUtils.joinWith("_", CACHE_THEME_ID, themeId));
} }
// 消息通知队列缓存
private void messageNotify(String notifyUserId,String operatorId, NotificationTypeEnum type){
UserInfoResp userInfo = getUserInfo(operatorId);
redisCache.incr(RedisKeyConstant.MESSAGE_NOTIFY_COUNT + notifyUserId);
redisCache.set(RedisKeyConstant.MESSAGE_NOTIFY_LAST_MSG + notifyUserId, userInfo.getNickName()+type.getType()+"了你的内容", 60 * 60 * 24 * 30);
redisCache.set(RedisKeyConstant.MESSAGE_NOTIFY_LAST_TIME + notifyUserId, TimeUtils.format(LocalDateTime.now()), 60 * 60 * 24 * 30);
}
} }
package com.tanpu.community.service; package com.tanpu.community.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tanpu.common.api.CommonResp;
import com.tanpu.common.exception.BizException;
import com.tanpu.common.util.JsonUtil; import com.tanpu.common.util.JsonUtil;
import com.tanpu.common.uuid.UuidGenHelper; import com.tanpu.common.uuid.UuidGenHelper;
import com.tanpu.community.api.beans.vo.feign.fatools.UserInfoResp;
import com.tanpu.community.api.constants.RedisKeyConstant;
import com.tanpu.community.api.enums.DeleteTagEnum; import com.tanpu.community.api.enums.DeleteTagEnum;
import com.tanpu.community.api.enums.NotificationTypeEnum; import com.tanpu.community.api.enums.NotificationTypeEnum;
import com.tanpu.community.cache.RedisCache;
import com.tanpu.community.dao.entity.NotificationForwardDO; import com.tanpu.community.dao.entity.NotificationForwardDO;
import com.tanpu.community.dao.entity.NotificationLikeDO; import com.tanpu.community.dao.entity.NotificationLikeDO;
import com.tanpu.community.dao.entity.community.NotificationEntity; import com.tanpu.community.dao.entity.community.NotificationEntity;
import com.tanpu.community.dao.mapper.community.NotificationMapper; import com.tanpu.community.dao.mapper.community.NotificationMapper;
import com.tanpu.community.feign.fatools.FeignClientForFatools;
import com.tanpu.community.util.TimeUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -27,6 +34,13 @@ public class NotificationService { ...@@ -27,6 +34,13 @@ public class NotificationService {
@Autowired @Autowired
private UuidGenHelper uuidGenHelper; private UuidGenHelper uuidGenHelper;
@Autowired
private FeignClientForFatools feignClientForFatools;
@Autowired
private RedisCache redisCache;
public void insert(String operatorId,String notifierId,NotificationTypeEnum type,String targetId,String content){ public void insert(String operatorId,String notifierId,NotificationTypeEnum type,String targetId,String content){
NotificationEntity entity = NotificationEntity.builder().operatorId(operatorId) NotificationEntity entity = NotificationEntity.builder().operatorId(operatorId)
...@@ -79,8 +93,8 @@ public class NotificationService { ...@@ -79,8 +93,8 @@ public class NotificationService {
if (entity!=null){ if (entity!=null){
NotificationLikeDO notificationLikeDO = JsonUtil.toBean(entity.getContent(), NotificationLikeDO.class); NotificationLikeDO notificationLikeDO = JsonUtil.toBean(entity.getContent(), NotificationLikeDO.class);
notificationLikeDO.addItem(operatorId); notificationLikeDO.addItem(operatorId);
entity.setContent(JsonUtil.toJson(notificationLikeDO)); entity.setContent(JsonUtil.toJson(notificationLikeDO));
entity.setUpdateTime(LocalDateTime.now());
notificationMapper.updateById(entity); notificationMapper.updateById(entity);
}else { }else {
NotificationLikeDO notificationLikeDO = new NotificationLikeDO(); NotificationLikeDO notificationLikeDO = new NotificationLikeDO();
...@@ -164,6 +178,29 @@ public class NotificationService { ...@@ -164,6 +178,29 @@ public class NotificationService {
} }
// 消息通知队列缓存
public void putNotifyCache(String notifyUserId, String operatorId, NotificationTypeEnum type){
UserInfoResp userInfo = getUserInfo(operatorId);
redisCache.incr(RedisKeyConstant.MESSAGE_NOTIFY_COUNT + notifyUserId);
redisCache.set(RedisKeyConstant.MESSAGE_NOTIFY_LAST_MSG + notifyUserId, userInfo.getNickName()+type.getType()+"了你的内容", 60 * 60 * 24 * 30);
redisCache.set(RedisKeyConstant.MESSAGE_NOTIFY_LAST_TIME + notifyUserId, TimeUtils.format(LocalDateTime.now()), 60 * 60 * 24 * 30);
}
// 消息通知队列缓存
public void putNotifyCacheFollow(String notifyUserId, String operatorId) {
UserInfoResp userInfo = getUserInfo(operatorId);
redisCache.incr(RedisKeyConstant.MESSAGE_NOTIFY_COUNT + notifyUserId);
redisCache.set(RedisKeyConstant.MESSAGE_NOTIFY_LAST_MSG + notifyUserId, userInfo.getNickName() + "关注了你", 60 * 60 * 24 * 30);
redisCache.set(RedisKeyConstant.MESSAGE_NOTIFY_LAST_TIME + notifyUserId, TimeUtils.format(LocalDateTime.now()), 60 * 60 * 24 * 30);
}
private UserInfoResp getUserInfo(String authorId) {
CommonResp<UserInfoResp> userInfoNewCommonResp = feignClientForFatools.queryUserInfoNew(authorId);
if (userInfoNewCommonResp.isNotSuccess()) {
throw new BizException("内部接口调用失败");
}
return userInfoNewCommonResp.getData();
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment