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

消息通知 fix

parent 1fc721e0
......@@ -32,13 +32,11 @@ import com.tanpu.community.service.NotificationService;
import com.tanpu.community.service.ThemeService;
import com.tanpu.community.service.TopicService;
import com.tanpu.community.util.ConvertUtil;
import com.tanpu.community.util.TimeUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
......@@ -153,7 +151,7 @@ public class NotificationManager {
for (FollowRelEntity followRelEntity : followRelEntities) {
notificationService.insert(followRelEntity.getFansId(), followRelEntity.getIdolId(), NotificationTypeEnum.FOLLOW
, followRelEntity.getFansId(), "", followRelEntity.getUpdateTime());
messageNotifyFollow(followRelEntity.getIdolId(), followRelEntity.getFansId());
notificationService.putNotifyCacheFollow(followRelEntity.getIdolId(), followRelEntity.getFansId());
}
// 转发
List<ThemeEntity> themeEntities = themeService.queryAllForward();
......@@ -168,7 +166,7 @@ public class NotificationManager {
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
, 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();
......@@ -180,7 +178,7 @@ public class NotificationManager {
String s = commentEntity.getContent();
notificationService.insert(commentEntity.getAuthorId(), themeEntity.getAuthorId(), NotificationTypeEnum.COMMENT
, 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 {
continue;
}
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 {
}
// 消息通知队列缓存
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) {
CommonResp<UserInfoResp> userInfoNewCommonResp = feignClientForFatools.queryUserInfoNew(authorId);
......
......@@ -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.newsfeed.NewsFeedResReq;
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.DeleteTagEnum;
import com.tanpu.community.api.enums.NotificationTypeEnum;
......@@ -416,7 +415,7 @@ public class ThemeManager {
// 消息通知
ThemeEntity formerTheme = themeService.queryByThemeId(req.getFormerThemeId());
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 {
// 修改
......@@ -672,7 +671,7 @@ public class ThemeManager {
ThemeEntity themeEntity = themeService.queryByThemeId(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())) {
......@@ -927,12 +926,4 @@ public class ThemeManager {
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;
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.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.NotificationTypeEnum;
import com.tanpu.community.cache.RedisCache;
import com.tanpu.community.dao.entity.NotificationForwardDO;
import com.tanpu.community.dao.entity.NotificationLikeDO;
import com.tanpu.community.dao.entity.community.NotificationEntity;
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.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -27,6 +34,13 @@ public class NotificationService {
@Autowired
private UuidGenHelper uuidGenHelper;
@Autowired
private FeignClientForFatools feignClientForFatools;
@Autowired
private RedisCache redisCache;
public void insert(String operatorId,String notifierId,NotificationTypeEnum type,String targetId,String content){
NotificationEntity entity = NotificationEntity.builder().operatorId(operatorId)
......@@ -79,8 +93,8 @@ public class NotificationService {
if (entity!=null){
NotificationLikeDO notificationLikeDO = JsonUtil.toBean(entity.getContent(), NotificationLikeDO.class);
notificationLikeDO.addItem(operatorId);
entity.setContent(JsonUtil.toJson(notificationLikeDO));
entity.setUpdateTime(LocalDateTime.now());
notificationMapper.updateById(entity);
}else {
NotificationLikeDO notificationLikeDO = new NotificationLikeDO();
......@@ -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