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

同步评论转发,评论点赞消息通知

parent d1d79e13
......@@ -24,4 +24,7 @@ public class CreateCommentReq {
@ApiModelProperty(value = "评论内容")
private String comment;
@ApiModelProperty(value = "同步转发,1 同步 ,0 不同步(默认)")
private int syncForward = 0;
}
......@@ -21,8 +21,11 @@ public class ForwardThemeReq {
private List<ThemeContentReq> content;
@ApiModelProperty(value = "话题Id")
private String topicId="";
private String topicId = "";
@ApiModelProperty(value = "修改,则传入正在编辑的ThemeId")
private String editThemeId="";
private String editThemeId = "";
@ApiModelProperty(value = "同步评论,1 同步 ,0 不同步(默认)")
private int syncComment = 0;
}
......@@ -3,12 +3,18 @@ package com.tanpu.community.api.beans.req.theme;
import com.tanpu.community.api.beans.vo.ImagesDTO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
@Data
@ApiModel(value = "主题内容")
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class ThemeContentReq {
@ApiModelProperty(value = "RelTypeEnum类型,108:文本,88:产品 3:直播 6:短视频 303:新版课程-视频,304: 新版课程-音频,109:单图(长文) 110:多图(讨论))")
......
package com.tanpu.community.api.constants;
public class BizConstant {
public static class SyncCommentType{
public static final int SYNC_COMMENT=1;
public static final int NOT_SYNC_COMMENT=0;
}
public static class SyncForwardType{
public static final int SYNC_FORWARD=1;
public static final int NOT_SYNC_FORWARD=0;
}
}
......@@ -12,6 +12,7 @@ public enum NotificationTypeEnum {
LIKE(2,"点赞"),
COMMENT(3,"评论"),
FOLLOW(4,"关注"),
COMMENT_LIKE(5,"点赞评论"),
ALL(0,"全部");
private Integer code;
......
......@@ -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.BizConstant;
import com.tanpu.community.api.enums.NotificationTypeEnum;
import com.tanpu.community.api.enums.OperationTypeEnum;
import com.tanpu.community.cache.RedisCache;
......@@ -28,7 +29,6 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.Comparator;
import java.util.List;
import java.util.Set;
......@@ -71,7 +71,6 @@ public class CommentManager {
throw new IllegalArgumentException("评论内容不能超过500字");
}
LocalDateTime now = LocalDateTime.now();
CommentEntity commentEntity = CommentEntity.builder()
.themeId(req.getThemeId())
.parentId(req.getParentId())
......@@ -79,18 +78,27 @@ public class CommentManager {
.authorId(userId)
.content(req.getComment())
.commentType(CommentTypeEnum.THEME.getCode())
.createTime(now)
.updateTime(now)
.build();
commentService.insertComment(commentEntity);
CommentQo commentQo = ConvertUtil.commentEntity2Qo(commentEntity);
buildUserInfo(commentQo);
// 消息通知
ThemeEntity themeEntity = themeService.queryByThemeId(req.getThemeId());
notificationService.insert(userId,themeEntity.getAuthorId(), NotificationTypeEnum.COMMENT,commentEntity.getCommentId(),req.getComment());
notificationService.putNotifyCache(themeEntity.getAuthorId(),userId,NotificationTypeEnum.COMMENT);
// 评论同步转发并消息通知
if (req.getSyncForward() == BizConstant.SyncForwardType.SYNC_FORWARD) {
String themeId = themeService.commentSyncForward(req, userId);
// 消息通知
ThemeEntity formerTheme = themeService.queryByThemeId(req.getThemeId());
notificationService.insertForward(userId, formerTheme.getAuthorId(), formerTheme.getThemeId(),"", req.getComment(), themeEntity.getThemeId());
notificationService.putNotifyCache(formerTheme.getAuthorId(), userId, NotificationTypeEnum.FORWARD);
}
return commentQo;
}
......
......@@ -247,7 +247,7 @@ public class HomePageManager {
// 第一次关注才有消息通知
if (followRelService.addFollowRel(req.getFollowUserId(), followerId)) {
notificationService.insert(followerId, req.getFollowUserId(), NotificationTypeEnum.FOLLOW, req.getFollowUserId(), null);
notificationService.putNotifyCacheFollow(req.getFollowUserId(), followerId);
notificationService.putNotifyCache(req.getFollowUserId(), followerId,NotificationTypeEnum.FOLLOW);
}
} else if (OperationTypeEnum.CANCEL.getCode().equals(req.getType())) {
followRelService.deleteFollowRel(req.getFollowUserId(), followerId);
......
......@@ -32,6 +32,7 @@ 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.BizConstant;
import com.tanpu.community.api.enums.BlockTypeEnum;
import com.tanpu.community.api.enums.DeleteTagEnum;
import com.tanpu.community.api.enums.NotificationTypeEnum;
......@@ -205,11 +206,6 @@ public class ThemeManager {
// 校验参数
checkAttachment(req.getContent());
// 转播权限校验
// if (1 == req.getSyncToNewComm()) {
// liveRelayCheck(userId, req.getContent());
// }
// 保存主题表
ThemeEntity themeEntity = new ThemeEntity();
......@@ -414,8 +410,8 @@ 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(),themeEntity.getThemeId());
notificationService.putNotifyCache(formerTheme.getAuthorId(),userId,NotificationTypeEnum.FORWARD);
notificationService.insertForward(userId, formerTheme.getAuthorId(), formerTheme.getThemeId(), req.getTopicId(), req.getContent().get(0).getValue(), themeEntity.getThemeId());
notificationService.putNotifyCache(formerTheme.getAuthorId(), userId, NotificationTypeEnum.FORWARD);
} else {
// 修改
......@@ -423,6 +419,14 @@ public class ThemeManager {
themeEntity.setThemeId(req.getEditThemeId());
this.evictThemeCache(req.getEditThemeId());
}
// 转发同步评论并消息通知
if (req.getSyncComment() == BizConstant.SyncCommentType.SYNC_COMMENT) {
String commentId = commentService.forwardSyncComment(req, userId);
ThemeEntity formerTheme = themeService.queryByThemeId(req.getFormerThemeId());
notificationService.insert(userId, formerTheme.getAuthorId(), NotificationTypeEnum.COMMENT, commentId, req.getContent().get(0).getValue());
notificationService.putNotifyCache(formerTheme.getAuthorId(), userId, NotificationTypeEnum.COMMENT);
}
try {
esService.insertOrUpdateTheme(ConvertUtil.convert(themeEntity));
......@@ -671,7 +675,7 @@ public class ThemeManager {
ThemeEntity themeEntity = themeService.queryByThemeId(req.getThemeId());
// 消息通知
notificationService.insertLike(userId, themeEntity.getAuthorId(), req.getThemeId());
notificationService.putNotifyCache(themeEntity.getAuthorId(),userId,NotificationTypeEnum.LIKE);
notificationService.putNotifyCache(themeEntity.getAuthorId(), userId, NotificationTypeEnum.LIKE);
}
} else if (OperationTypeEnum.CANCEL.getCode().equals(req.getType())) {
......
......@@ -3,11 +3,15 @@ package com.tanpu.community.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tanpu.biz.common.enums.community.CollectionTypeEnum;
import com.tanpu.community.api.enums.DeleteTagEnum;
import com.tanpu.community.api.enums.NotificationTypeEnum;
import com.tanpu.community.dao.entity.community.CollectionEntity;
import com.tanpu.community.dao.entity.community.CommentEntity;
import com.tanpu.community.dao.entity.community.ThemeEntity;
import com.tanpu.community.dao.entity.community.TimesCountEntity;
import com.tanpu.community.dao.mapper.community.CollectionMapper;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
......@@ -26,15 +30,24 @@ public class CollectionService {
@Resource
private CollectionMapper collectionMapper;
@Autowired
private NotificationService notificationService;
@Autowired
private ThemeService themeService;
@Autowired
private CommentService commentService;
// 若不存在则新增,若存在则修改deleteTag
@Transactional
public boolean saveOrUpdate(String themeId, String userId, CollectionTypeEnum type) {
public boolean saveOrUpdate(String targetId, String userId, CollectionTypeEnum type) {
// 判断记录是否存在,无论是否删除
LambdaQueryWrapper<CollectionEntity> queryWrapper = new LambdaQueryWrapper<CollectionEntity>()
.eq(CollectionEntity::getCollectionType, type.getCode())
.eq(CollectionEntity::getUserId, userId)
.eq(CollectionEntity::getTargetId, themeId);
.eq(CollectionEntity::getTargetId, targetId);
CollectionEntity queryCollection = collectionMapper.selectOne(queryWrapper);
if (queryCollection != null) {
queryCollection.setDeleteTag(DeleteTagEnum.NOT_DELETED.getCode());
......@@ -45,11 +58,18 @@ public class CollectionService {
CollectionEntity entity = CollectionEntity.builder()
.collectionType(type.getCode())
.userId(userId)
.targetId(themeId)
.targetId(targetId)
.collectionTime(LocalDateTime.now())
.build();
collectionMapper.insert(entity);
CommentEntity commentEntity = commentService.queryByCommentId(targetId);
ThemeEntity themeEntity = themeService.queryByThemeId(commentEntity.getThemeId());
notificationService.insert(userId, themeEntity.getAuthorId(), NotificationTypeEnum.COMMENT_LIKE
, themeEntity.getThemeId(), targetId);
notificationService.putNotifyCache(themeEntity.getAuthorId(), userId, NotificationTypeEnum.COMMENT_LIKE);
return true;
}
}
......
......@@ -6,6 +6,7 @@ import com.tanpu.biz.common.enums.community.CommentTypeEnum;
import com.tanpu.biz.common.enums.community.ReportStatusEnum;
import com.tanpu.common.exception.BizException;
import com.tanpu.common.uuid.UuidGenHelper;
import com.tanpu.community.api.beans.req.theme.ForwardThemeReq;
import com.tanpu.community.api.enums.DeleteTagEnum;
import com.tanpu.community.cache.RedisCache;
import com.tanpu.community.dao.entity.community.CommentEntity;
......@@ -44,7 +45,6 @@ public class CommentService {
//失效缓存
evictThemeCache(commentEntity.getThemeId());
}
......@@ -163,4 +163,19 @@ public class CommentService {
public CommentEntity queryByCommentId(String commentId) {
return commentMapper.selectOne(new LambdaQueryWrapper<CommentEntity>().eq(CommentEntity::getCommentId,commentId));
}
public String forwardSyncComment(ForwardThemeReq req, String userId) {
CommentEntity commentEntity = CommentEntity.builder()
.themeId(req.getFormerThemeId())
.authorId(userId)
.content(req.getContent().get(0).getValue())
.commentType(CommentTypeEnum.THEME.getCode())
.build();
this.insertComment(commentEntity);
return commentEntity.getCommentId();
}
}
......@@ -182,17 +182,14 @@ 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);
if (NotificationTypeEnum.COMMENT_LIKE.equals(type)) {
redisCache.set(RedisKeyConstant.MESSAGE_NOTIFY_LAST_MSG + notifyUserId, userInfo.getNickName() + "点赞了你的评论", 60 * 60 * 24 * 30);
}else if (NotificationTypeEnum.FOLLOW.equals(type)) {
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);
} else {
redisCache.set(RedisKeyConstant.MESSAGE_NOTIFY_LAST_MSG + notifyUserId, userInfo.getNickName() + type.getType() + "了你的内容", 60 * 60 * 24 * 30);
}
}
......@@ -231,7 +228,7 @@ public class NotificationService {
// 处理更新数量
String lastTime = redisCache.get(RedisKeyConstant.MESSAGE_NOTIFY_QUERY_TIME + notifyUserId);
LocalDateTime lastQueryTime =StringUtils.isNotBlank(lastTime)?JsonUtil.toBean(lastTime,LocalDateTime.class):LocalDateTime.now();
LocalDateTime lastQueryTime = StringUtils.isNotBlank(lastTime) ? JsonUtil.toBean(lastTime, LocalDateTime.class) : LocalDateTime.now();
// 如果删除的评论时时间在红点提示时间内,则缓存数-1
if (StringUtils.isBlank(lastTime) || TimeUtils.lessThan(lastQueryTime, commentTime)) {
redisCache.decr(RedisKeyConstant.MESSAGE_NOTIFY_COUNT + notifyUserId);
......
......@@ -2,10 +2,14 @@ package com.tanpu.community.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.tanpu.biz.common.enums.RelTypeEnum;
import com.tanpu.biz.common.enums.community.ReportStatusEnum;
import com.tanpu.common.exception.BizException;
import com.tanpu.common.redis.RedisHelper;
import com.tanpu.common.util.JsonUtil;
import com.tanpu.common.uuid.UuidGenHelper;
import com.tanpu.community.api.beans.req.comment.CreateCommentReq;
import com.tanpu.community.api.beans.req.theme.ThemeContentReq;
import com.tanpu.community.api.enums.DeleteTagEnum;
import com.tanpu.community.api.enums.ThemeTypeEnum;
import com.tanpu.community.dao.entity.community.ThemeEntity;
......@@ -19,6 +23,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
......@@ -275,4 +280,19 @@ public class ThemeService {
.eq(ThemeEntity::getDeleteTag,DeleteTagEnum.NOT_DELETED.getCode())
.orderByAsc(ThemeEntity::getCreateTime));
}
public String commentSyncForward(CreateCommentReq req, String userId) {
// 评论构造theme content
List<ThemeContentReq> themeContentReqs = Arrays.asList(ThemeContentReq.builder().type(RelTypeEnum.TEXT.type).value(req.getComment()).build());
ThemeContentReq.builder().type(RelTypeEnum.TEXT.type).value(req.getComment()).build();
ThemeEntity themeEntity = ThemeEntity.builder()
.content(JsonUtil.toJson(themeContentReqs))
.topicId("")
.formerThemeId(req.getThemeId())
.authorId(userId)
.themeType(ThemeTypeEnum.FORWARD.getCode())
.build();
this.insertTheme(themeEntity);
return themeEntity.getThemeId();
}
}
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