Commit 5b1c203d authored by 刘基明's avatar 刘基明

消息通知条数更新

parent 6c862fe0
......@@ -23,4 +23,10 @@ public class RedisKeyConstant {
// 关注的人,上次浏览的最新主题last id
public static final String CACHE_IDOL_THEME_LAST_ID = "CACHE_IDOL_THEME_LAST_ID_";
// 消息通知
public static final String MESSAGE_NOTIFY_COUNT = "MESSAGE_NOTIFY_COUNT_";
public static final String MESSAGE_NOTIFY_LAST_MSG = "MESSAGE_NOTIFY_LAST_MSG_";
public static final String MESSAGE_NOTIFY_LAST_TIME = "MESSAGE_NOTIFY_LAST_TIME_";
}
......@@ -51,6 +51,11 @@ public class RedisCache {
return redisHelper.get(key);
}
public void incr(String key) {
key = cacheName + ":" + key;
redisHelper.incr(key);
}
public void put(String key, Object obj, Integer expireSeconds) {
key = cacheName + ":" + key;
String value = JsonUtil.toJson(obj);
......
......@@ -10,6 +10,7 @@ import com.tanpu.community.api.beans.req.comment.CreateCommentReq;
import com.tanpu.community.api.beans.req.comment.LikeCommentReq;
import com.tanpu.community.api.beans.req.comment.ReportCommentReq;
import com.tanpu.community.api.beans.vo.feign.fatools.UserInfoResp;
import com.tanpu.community.api.constants.RedisKeyConstant;
import com.tanpu.community.api.enums.NotificationTypeEnum;
import com.tanpu.community.api.enums.OperationTypeEnum;
import com.tanpu.community.cache.RedisCache;
......@@ -22,6 +23,7 @@ import com.tanpu.community.service.NotificationService;
import com.tanpu.community.service.ReportLogService;
import com.tanpu.community.service.ThemeService;
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;
......@@ -90,6 +92,7 @@ public class CommentManager {
// 消息通知
ThemeEntity themeEntity = themeService.queryByThemeId(req.getThemeId());
notificationService.insert(userId,themeEntity.getAuthorId(), NotificationTypeEnum.COMMENT,req.getThemeId(),req.getComment());
messageNotify(themeEntity.getAuthorId(),userId,NotificationTypeEnum.COMMENT);
return commentQo;
}
......@@ -169,4 +172,12 @@ public class CommentManager {
public void delete(String commentId, String userId) {
commentService.delete(commentId,userId);
}
// 消息通知队列缓存
private void messageNotify(String notifyUserId,String operatorId, NotificationTypeEnum type){
UserInfoResp userInfo = getUserInfo(operatorId);
redisCache.incr(RedisKeyConstant.MESSAGE_NOTIFY_COUNT + notifyUserId);
redisCache.put(RedisKeyConstant.MESSAGE_NOTIFY_LAST_MSG + notifyUserId, userInfo.getNickName()+type.getType()+"了你的内容", 60 * 60 * 24 * 30);
redisCache.put(RedisKeyConstant.MESSAGE_NOTIFY_LAST_TIME + notifyUserId, TimeUtils.format(LocalDateTime.now()), 60 * 60 * 24 * 30);
}
}
......@@ -17,6 +17,7 @@ import com.tanpu.community.api.beans.vo.feign.fatools.UserInfoNewChief;
import com.tanpu.community.api.beans.vo.feign.fatools.UserInfoOrg;
import com.tanpu.community.api.beans.vo.feign.fatools.UserInfoResp;
import com.tanpu.community.api.beans.vo.feign.fund.FundCompanySimpleVO;
import com.tanpu.community.api.constants.RedisKeyConstant;
import com.tanpu.community.api.enums.*;
import com.tanpu.community.cache.RedisCache;
import com.tanpu.community.dao.entity.community.FollowRelEntity;
......@@ -30,6 +31,7 @@ import com.tanpu.community.service.FollowRelService;
import com.tanpu.community.service.NotificationService;
import com.tanpu.community.util.ConvertUtil;
import com.tanpu.community.util.PageUtils;
import com.tanpu.community.util.TimeUtils;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
......@@ -37,6 +39,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
......@@ -214,7 +217,7 @@ public class HomePageManager {
List<FollowQo> collect = userInfoNews.stream().map(ConvertUtil::userInfoNew2FollowQo).collect(Collectors.toList());
followQos = judgeFollowed(collect, userId);
}
return PageUtils.page(userIdsPage,followQos);
return PageUtils.page(userIdsPage, followQos);
}
......@@ -232,13 +235,30 @@ public class HomePageManager {
public void addFollowRel(FollowRelReq req, String followerId) {
if (OperationTypeEnum.CONFIRM.getCode().equals(req.getType())) {
if(followRelService.addFollowRel(req.getFollowUserId(), followerId)){
notificationService.insert(followerId,req.getFollowUserId(),NotificationTypeEnum.FOLLOW,req.getFollowUserId(),null);
// 第一次关注才有消息通知
if (followRelService.addFollowRel(req.getFollowUserId(), followerId)) {
notificationService.insert(followerId, req.getFollowUserId(), NotificationTypeEnum.FOLLOW, req.getFollowUserId(), null);
messageFollowNotify(req.getFollowUserId(), followerId);
}
} else if (OperationTypeEnum.CANCEL.getCode().equals(req.getType())) {
followRelService.deleteFollowRel(req.getFollowUserId(), followerId);
}
}
// 消息通知队列缓存-关注
private void messageFollowNotify(String notifyUserId, String operatorId) {
UserInfoResp userInfo = getUserInfo(operatorId);
redisCache.incr(RedisKeyConstant.MESSAGE_NOTIFY_COUNT + notifyUserId);
redisCache.put(RedisKeyConstant.MESSAGE_NOTIFY_LAST_MSG + notifyUserId, userInfo.getNickName() + "关注了你", 60 * 60 * 24 * 30);
redisCache.put(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();
}
}
......@@ -8,6 +8,7 @@ import com.tanpu.community.api.beans.qo.ThemeNotifyQo;
import com.tanpu.community.api.beans.qo.ThemeQo;
import com.tanpu.community.api.beans.req.notification.NotifyQueryReq;
import com.tanpu.community.api.beans.vo.feign.fatools.UserInfoResp;
import com.tanpu.community.api.constants.RedisKeyConstant;
import com.tanpu.community.api.enums.ThemeTypeEnum;
import com.tanpu.community.cache.RedisCache;
import com.tanpu.community.dao.entity.community.NotificationEntity;
......@@ -18,13 +19,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 static com.tanpu.community.api.constants.RedisKeyConstant.CACHE_FEIGN_USER_INFO;
......@@ -79,15 +78,16 @@ public class NotificationManager {
if (ThemeTypeEnum.LONG_TEXT.getCode().equals(former.getThemeType())){
themeNotifyQo.setContent(former.getTitle());
}
}
}
if (StringUtils.isNotEmpty(themeNotifyQo.getTopicId())){
TopicEntity topicEntity = topicService.queryById(themeNotifyQo.getTopicId());
themeNotifyQo.setTopicTitle(topicEntity.getTopicTitle());
}
}
redisCache.evict(RedisKeyConstant.MESSAGE_NOTIFY_COUNT + userId);
return themeNotifyQos;
}
......@@ -102,8 +102,11 @@ public class NotificationManager {
public NotificationQo queryBriefInfo(String userId){
String count = redisCache.get(RedisKeyConstant.MESSAGE_NOTIFY_COUNT+userId);
String lastMsg = redisCache.get(RedisKeyConstant.MESSAGE_NOTIFY_LAST_MSG+userId);
String lastTime = redisCache.get(RedisKeyConstant.MESSAGE_NOTIFY_LAST_TIME+userId);
return NotificationQo.builder().message(" {用户名}关注了你").updateCount(99).updateTime(TimeUtils.format(LocalDateTime.now())).build();
return NotificationQo.builder().message(lastMsg).updateCount(count==null?0:Integer.parseInt(count)).updateTime(lastTime).build();
}
......
......@@ -32,8 +32,10 @@ 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;
import com.tanpu.community.api.enums.OperationTypeEnum;
import com.tanpu.community.api.enums.ThemeListTypeEnum;
import com.tanpu.community.api.enums.ThemeTypeEnum;
......@@ -388,10 +390,10 @@ public class ThemeManager {
if (content.getProductType() == null) {
throw new BizException(ErrorCodeConstant.ILLEGAL_ARGEMENT.getCode(), "附件产品FUND缺少类型");
}
if ( content.getProductType() == ProductTypeEnum.CUSTOMER_IMPORT.type){
if (content.getProductType() == ProductTypeEnum.CUSTOMER_IMPORT.type) {
throw new BizException(ErrorCodeConstant.LIMIT_CONTENT.getCode(), "圈子暂不支持私有基金");
}
if ( content.getProductType() == ProductTypeEnum.NOT_NET_PRODUCT.type){
if (content.getProductType() == ProductTypeEnum.NOT_NET_PRODUCT.type) {
throw new BizException(ErrorCodeConstant.LIMIT_CONTENT.getCode(), "圈子暂不支持无净值私有基金");
}
}
......@@ -413,7 +415,9 @@ public class ThemeManager {
themeService.insertTheme(themeEntity);
// 消息通知
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);
} else {
// 修改
themeService.update(themeEntity, req.getEditThemeId());
......@@ -664,9 +668,11 @@ public class ThemeManager {
// 点赞/取消点赞
public void like(LikeThemeReq req, String userId) {
if (OperationTypeEnum.CONFIRM.getCode().equals(req.getType())) {
if(collectionService.saveOrUpdate(req.getThemeId(), userId, CollectionTypeEnum.LIKE_THEME)){
if (collectionService.saveOrUpdate(req.getThemeId(), userId, CollectionTypeEnum.LIKE_THEME)) {
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);
}
} else if (OperationTypeEnum.CANCEL.getCode().equals(req.getType())) {
......@@ -921,5 +927,12 @@ 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.put(RedisKeyConstant.MESSAGE_NOTIFY_LAST_MSG + notifyUserId, userInfo.getNickName()+type.getType()+"了你的内容", 60 * 60 * 24 * 30);
redisCache.put(RedisKeyConstant.MESSAGE_NOTIFY_LAST_TIME + notifyUserId, TimeUtils.format(LocalDateTime.now()), 60 * 60 * 24 * 30);
}
}
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