Commit 0cf557e3 authored by 刘基明's avatar 刘基明

删除评论时删除消息通知

parent 49ed72df
......@@ -169,11 +169,10 @@ public class CommentManager {
//删除评论
public void delete(String commentId, String userId) {
commentService.delete(commentId,userId);
notificationService.deleteComment(commentId);
CommentEntity commentEntity = commentService.queryByIdIncludeDelete(commentId);
ThemeEntity themeEntity = themeService.queryByThemeId(commentEntity.getThemeId());
notificationService.deleteNotifyCache(themeEntity.getAuthorId(),userId,commentId,commentEntity.getCreateTime());
notificationService.deleteCommentNotify(themeEntity.getAuthorId(),userId,commentId,commentEntity.getCreateTime());
}
......
......@@ -195,15 +195,10 @@ public class NotificationService {
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();
}
public void deleteNotifyCache(String notifyUserId, String operatorId, String commentId, LocalDateTime commentTime) {
// 删除评论及缓存
public void deleteCommentNotify(String notifyUserId, String operatorId, String commentId, LocalDateTime commentTime) {
// 物理删除
NotificationEntity commentNotify = notificationMapper.selectOne(new LambdaQueryWrapper<NotificationEntity>().eq(NotificationEntity::getTargetId, commentId));
NotificationEntity last = notificationMapper.selectOne(new LambdaQueryWrapper<NotificationEntity>().eq(NotificationEntity::getNotifiedUserId, notifyUserId)
......@@ -216,10 +211,12 @@ public class NotificationService {
.orderByDesc(NotificationEntity::getUpdateTime)
.last("limit 1"));
if (last == null) {
// 没有其他通知,置空
redisCache.evict(RedisKeyConstant.MESSAGE_NOTIFY_LAST_MSG + notifyUserId);
redisCache.evict(RedisKeyConstant.MESSAGE_NOTIFY_LAST_TIME + notifyUserId);
} else {
// 有通知
UserInfoResp userInfo = getUserInfo(last.getOperatorId());
redisCache.set(RedisKeyConstant.MESSAGE_NOTIFY_LAST_TIME + notifyUserId, TimeUtils.format(last.getUpdateTime()), 60 * 60 * 24 * 30);
if (NotificationTypeEnum.FOLLOW.getCode().equals(last.getMessageType())) {
......@@ -228,22 +225,16 @@ public class NotificationService {
redisCache.set(RedisKeyConstant.MESSAGE_NOTIFY_LAST_MSG + notifyUserId
, userInfo.getNickName() + NotificationTypeEnum.lookup(last.getMessageType()) + "了你的内容"
, 60 * 60 * 24 * 30);
}
}
}
LocalDateTime lastQueryTime = TimeUtils.reFormat(redisCache.get(RedisKeyConstant.MESSAGE_NOTIFY_QUERY_TIME + notifyUserId));
// 如果删除的评论时时间在红点提示时间内,则需要加工缓存
if (TimeUtils.lessThan(lastQueryTime, commentTime)) {
UserInfoResp userInfo = getUserInfo(operatorId);
// 红点数-1
// 处理更新数量
String lastQueryTime = redisCache.get(RedisKeyConstant.MESSAGE_NOTIFY_QUERY_TIME + notifyUserId);
// 如果删除的评论时时间在红点提示时间内,则缓存数-1
if (!TimeUtils.lessThan(lastQueryTime, commentTime)) {
redisCache.decr(RedisKeyConstant.MESSAGE_NOTIFY_COUNT + notifyUserId);
}
}
......@@ -275,4 +266,11 @@ public class NotificationService {
}
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