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

Merge branch 'dev' into 'master'

Dev

See merge request !14
parents 2bd52d5b a750e6d6
......@@ -49,6 +49,8 @@ public class ThemeNotifyQo {
public String topicTitle;
@ApiModelProperty(value = "评论/转发内容")
private String content;
@ApiModelProperty(value = "评论Id")
private String commentId;
@ApiModelProperty(value = "转发类型-主题id")
private String forwardThemeId;
......
......@@ -24,4 +24,7 @@ public class CreateCommentReq {
@ApiModelProperty(value = "评论内容")
private String comment;
@ApiModelProperty(value = "同步转发,1 同步 ,0 不同步(默认)")
private int syncForward = 0;
}
package com.tanpu.community.api.beans.req.notification;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
......@@ -14,7 +13,7 @@ import lombok.NoArgsConstructor;
@AllArgsConstructor
public class NotifyQueryReq {
@ApiModelProperty(value = "1:转发 2:点赞 3:评论 4:关注 0:全部")
@ApiModelProperty(value = "1:转发 2:点赞(主题点赞+评论点赞) 3:评论 4:关注 0:全部")
private Integer type;
@ApiModelProperty(value = "最后一条通知")
......
......@@ -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;
......
......@@ -4,12 +4,14 @@ import com.tanpu.biz.common.enums.community.CollectionTypeEnum;
import com.tanpu.biz.common.enums.community.CommentTypeEnum;
import com.tanpu.biz.common.enums.community.ReportTypeEnum;
import com.tanpu.common.api.CommonResp;
import com.tanpu.common.constant.ErrorCodeConstant;
import com.tanpu.common.exception.BizException;
import com.tanpu.community.api.beans.qo.CommentQo;
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;
......@@ -67,7 +69,7 @@ public class CommentManager {
if (StringUtils.isEmpty(req.getComment())) {
throw new IllegalArgumentException("评论内容不能为空");
}
if (req.getComment().length()>500){
if (req.getComment().length() > 500) {
throw new IllegalArgumentException("评论内容不能超过500字");
}
......@@ -86,11 +88,25 @@ public class CommentManager {
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 (themeEntity == null) {
throw new BizException(ErrorCodeConstant.UNREACHABLE);
}
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 commentTheme = themeService.queryByThemeId(req.getThemeId());
notificationService.insertForward(userId, commentTheme.getAuthorId(), commentTheme.getThemeId(), "", req.getComment(), themeId);
notificationService.putNotifyCache(commentTheme.getAuthorId(), userId, NotificationTypeEnum.FORWARD);
}
return commentQo;
}
......@@ -122,7 +138,7 @@ public class CommentManager {
private void buildUserInfo(CommentQo commentQo) {
String authorId = commentQo.getAuthorId();
UserInfoResp userInfo = redisCache.getObject(StringUtils.joinWith("_", CACHE_FEIGN_USER_INFO, authorId),
60, () ->this.getUserInfo(authorId) , UserInfoResp.class);
60, () -> this.getUserInfo(authorId), UserInfoResp.class);
if (userInfo != null) {
commentQo.setUserImg(userInfo.getHeadImageUrl());
commentQo.setNickName(userInfo.getNickName());
......@@ -136,7 +152,7 @@ public class CommentManager {
commentQo.setLikeCount(0);
}
private UserInfoResp getUserInfo(String authorId){
private UserInfoResp getUserInfo(String authorId) {
CommonResp<UserInfoResp> userInfoNewCommonResp = feignClientForFatools.queryUserInfoNew(authorId);
if (userInfoNewCommonResp.isNotSuccess()) {
throw new BizException("内部接口调用失败");
......@@ -147,7 +163,12 @@ public class CommentManager {
//点赞评论/取消点赞
public void likeComment(LikeCommentReq req, String userId) {
if (OperationTypeEnum.CONFIRM.getCode().equals(req.getType())) {
collectionService.saveOrUpdate(req.getCommentId(), userId, CollectionTypeEnum.LIKE_COMMENT);
boolean b = collectionService.saveOrUpdate(req.getCommentId(), userId, CollectionTypeEnum.LIKE_COMMENT);
if (b) {
CommentEntity commentEntity = commentService.queryByCommentId(req.getCommentId());
notificationService.insertLikeComment(userId, commentEntity.getAuthorId(), req.getCommentId());
notificationService.putNotifyCache(commentEntity.getAuthorId(), userId, NotificationTypeEnum.COMMENT_LIKE);
}
} else if (OperationTypeEnum.CANCEL.getCode().equals(req.getType())) {
collectionService.delete(req.getCommentId(), userId, CollectionTypeEnum.LIKE_COMMENT);
......@@ -168,11 +189,13 @@ public class CommentManager {
//删除评论
public void delete(String commentId, String userId) {
commentService.delete(commentId,userId);
if (StringUtils.isBlank(commentId)){
throw new BizException("commentId不能为空");
}
commentService.delete(commentId, userId);
CommentEntity commentEntity = commentService.queryByIdIncludeDelete(commentId);
ThemeEntity themeEntity = themeService.queryByThemeId(commentEntity.getThemeId());
notificationService.deleteCommentNotify(themeEntity.getAuthorId(),userId,commentId,commentEntity.getCreateTime());
notificationService.deleteCommentNotify(themeEntity.getAuthorId(), userId, commentId, commentEntity.getCreateTime());
}
......
......@@ -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);
......
......@@ -79,7 +79,7 @@ public class NotificationManager {
List<ThemeNotifyQo> themeNotifyQos = ConvertUtil.notificationEntitiy2ThemeQos(query);
UserInfoResp currentUser = redisCache.getObject(StringUtils.joinWith("_", CACHE_FEIGN_USER_INFO, userId),
60, () -> this.getUserInfo(userId), UserInfoResp.class);
Set<String> followUserIds= followRelService.queryIdolsByFansId(userId).stream().collect(Collectors.toSet());
Set<String> followUserIds = followRelService.queryIdolsByFansId(userId).stream().collect(Collectors.toSet());
for (ThemeNotifyQo themeNotifyQo : themeNotifyQos) {
// 用户信息
......@@ -93,18 +93,28 @@ public class NotificationManager {
themeNotifyQo.setUserInvestorType(userInfo.getUserInvestorType());
themeNotifyQo.setBelongUserOrgId(userInfo.getBelongUserOrgId());
themeNotifyQo.setBelongUserOrgName(userInfo.getBelongUserOrgName());
// 封装引用对象
if (StringUtils.isNotEmpty(themeNotifyQo.getFormerThemeId())) {
if (NotificationTypeEnum.COMMENT.getCode().equals(themeNotifyQo.getMessageType())){
// 评论类型将commentId替换为themeId
CommentEntity commentEntity = commentService.queryByCommentId(themeNotifyQo.getFormerThemeId());
// 评论根据commentEntity找到ThemeId
if (NotificationTypeEnum.COMMENT.getCode().equals(themeNotifyQo.getMessageType()) ||
NotificationTypeEnum.COMMENT_LIKE.getCode().equals(themeNotifyQo.getMessageType())) {
// 评论类型将commentId替换为themeId
CommentEntity commentEntity = commentService.queryByCommentId(themeNotifyQo.getCommentId());
if (commentEntity != null) {
themeNotifyQo.setFormerThemeId(commentEntity.getThemeId());
if (NotificationTypeEnum.COMMENT_LIKE.getCode().equals(themeNotifyQo.getMessageType())) {
themeNotifyQo.setContent(commentEntity.getContent());
}
}
ThemeEntity former = themeService.queryByThemeId(themeNotifyQo.getFormerThemeId());
}
// 封装引用对象
if (StringUtils.isNotEmpty(themeNotifyQo.getFormerThemeId())) {
ThemeEntity former = themeService.queryByThemeId(themeNotifyQo.getFormerThemeId());
if (former != null) {
themeNotifyQo.setFormerUserName(currentUser.getNickName());
if (StringUtils.isNotBlank(former.getTopicId())){
if (StringUtils.isNotBlank(former.getTopicId())) {
// 内部话题
themeNotifyQo.setFormerTopicId(former.getTopicId());
themeNotifyQo.setFormerTopicTitle(topicService.queryTitleById(former.getTopicId()));
......@@ -113,11 +123,10 @@ public class NotificationManager {
List<ThemeContentQo> themeContentQos = JsonUtil.toBean(former.getContent(), new TypeReference<List<ThemeContentQo>>() {
});
themeNotifyQo.setFormerContent(themeContentQos.get(0).getValue());
}
if (ThemeTypeEnum.LONG_TEXT.getCode().equals(former.getThemeType())) {
} else if (ThemeTypeEnum.LONG_TEXT.getCode().equals(former.getThemeType())) {
themeNotifyQo.setFormerContent(former.getTitle());
}
}else {
} else {
// 引用主题已被删除
themeNotifyQo.setFormerThemeId(null);
}
......@@ -127,7 +136,7 @@ public class NotificationManager {
themeNotifyQo.setTopicTitle(topicService.queryTitleById(themeNotifyQo.getTopicId()));
}
// 点赞聚合
if (themeNotifyQo.getLikeUserCount()!=null && themeNotifyQo.getLikeUserCount()>1) {
if (themeNotifyQo.getLikeUserCount() != null && themeNotifyQo.getLikeUserCount() > 1) {
List<UserBriefInfoQO> likeUsers = themeNotifyQo.getLikeUsers();
for (UserBriefInfoQO likeUser : likeUsers) {
UserInfoResp luser = redisCache.getObject(StringUtils.joinWith("_", CACHE_FEIGN_USER_INFO, likeUser.getUserId()),
......@@ -143,7 +152,7 @@ public class NotificationManager {
redisCache.evict(RedisKeyConstant.MESSAGE_NOTIFY_COUNT + userId);
// 更新查询时间,用于删除评论
redisCache.set(RedisKeyConstant.MESSAGE_NOTIFY_QUERY_TIME + userId,
JsonUtil.toJson(LocalDateTime.now()),60 * 60 * 24 * 30);
JsonUtil.toJson(LocalDateTime.now()), 60 * 60 * 24 * 30);
return themeNotifyQos;
}
......@@ -166,7 +175,7 @@ public class NotificationManager {
notificationService.insert(followRelEntity.getFansId(), followRelEntity.getIdolId(), NotificationTypeEnum.FOLLOW
, followRelEntity.getFansId(), "", followRelEntity.getUpdateTime());
notificationService.putNotifyCacheFollow(followRelEntity.getIdolId(), followRelEntity.getFansId(),followRelEntity.getUpdateTime());
notificationService.putNotifyCacheFollow(followRelEntity.getIdolId(), followRelEntity.getFansId(), followRelEntity.getUpdateTime());
}
// 转发
List<ThemeEntity> themeEntities = themeService.queryAllForward();
......@@ -184,7 +193,7 @@ public class NotificationManager {
.topicId(themeEntity.getTopicId()).build();
notificationService.insert(themeEntity.getAuthorId(), former.getAuthorId(), NotificationTypeEnum.FORWARD
, themeEntity.getFormerThemeId(), JsonUtil.toJson(content), themeEntity.getUpdateTime());
notificationService.putNotifyCache(former.getAuthorId(), themeEntity.getAuthorId(), NotificationTypeEnum.FORWARD,themeEntity.getUpdateTime());
notificationService.putNotifyCache(former.getAuthorId(), themeEntity.getAuthorId(), NotificationTypeEnum.FORWARD, themeEntity.getUpdateTime());
}
// 评论
List<CommentEntity> commentEntities = commentService.queryAll();
......@@ -227,7 +236,6 @@ public class NotificationManager {
}
private UserInfoResp getUserInfo(String authorId) {
CommonResp<UserInfoResp> userInfoNewCommonResp = feignClientForFatools.queryUserInfoNew(authorId);
if (userInfoNewCommonResp.isNotSuccess()) {
......
......@@ -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,11 @@ 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);
if (formerTheme != null) {
notificationService.insertForward(userId, formerTheme.getAuthorId(), req.getFormerThemeId(), req.getTopicId(), req.getContent().get(0).getValue(), themeEntity.getThemeId());
notificationService.putNotifyCache(formerTheme.getAuthorId(), userId, NotificationTypeEnum.FORWARD);
}
} else {
// 修改
......@@ -423,6 +422,17 @@ 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());
if (formerTheme != null) {
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 +681,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())) {
......
......@@ -27,14 +27,15 @@ public class CollectionService {
private CollectionMapper collectionMapper;
// 若不存在则新增,若存在则修改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 +46,12 @@ public class CollectionService {
CollectionEntity entity = CollectionEntity.builder()
.collectionType(type.getCode())
.userId(userId)
.targetId(themeId)
.targetId(targetId)
.collectionTime(LocalDateTime.now())
.build();
collectionMapper.insert(entity);
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();
}
}
......@@ -23,6 +23,7 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;
@Service
......@@ -84,7 +85,7 @@ public class NotificationService {
}
@Transactional
public void insertLike(String operatorId, String notifierId, String targetId) {
NotificationEntity entity = notificationMapper.selectOne(new LambdaQueryWrapper<NotificationEntity>()
.eq(NotificationEntity::getMessageType, NotificationTypeEnum.LIKE.getCode())
......@@ -112,6 +113,34 @@ public class NotificationService {
}
@Transactional
public void insertLikeComment(String operatorId, String notifierId, String targetId) {
NotificationEntity entity = notificationMapper.selectOne(new LambdaQueryWrapper<NotificationEntity>()
.eq(NotificationEntity::getMessageType, NotificationTypeEnum.COMMENT_LIKE.getCode())
.eq(NotificationEntity::getTargetId, targetId)
.eq(NotificationEntity::getNotifiedUserId, notifierId));
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();
notificationLikeDO.addItem(operatorId);
NotificationEntity build = NotificationEntity.builder().operatorId(operatorId)
.notificationId(uuidGenHelper.getUuidStr())
.messageType(NotificationTypeEnum.COMMENT_LIKE.getCode())
.notifiedUserId(notifierId)
.content(JsonUtil.toJson(notificationLikeDO))
.targetId(targetId)
.operatorId(operatorId)
.build();
insert(build);
}
}
@Transactional
public void insert(NotificationEntity entity) {
notificationMapper.insert(entity);
......@@ -136,8 +165,12 @@ public class NotificationService {
.eq(NotificationEntity::getNotificationId, lastId));
queryWrapper.lt(NotificationEntity::getUpdateTime, lastOne.getCreateTime());
}
if (!NotificationTypeEnum.ALL.getCode().equals(type)) {
if (!NotificationTypeEnum.ALL.getCode().equals(type) && !NotificationTypeEnum.LIKE.getCode().equals(type)) {
queryWrapper.eq(NotificationEntity::getMessageType, type);
} else if (NotificationTypeEnum.LIKE.getCode().equals(type)) {
// 类型2点赞返回评论点赞和主题点赞
queryWrapper.in(NotificationEntity::getMessageType,
Arrays.asList(NotificationTypeEnum.LIKE.getCode(), NotificationTypeEnum.COMMENT_LIKE.getCode()));
}
return notificationMapper.selectList(queryWrapper);
}
......@@ -182,28 +215,31 @@ 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);
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);
} else {
redisCache.set(RedisKeyConstant.MESSAGE_NOTIFY_LAST_MSG + notifyUserId, userInfo.getNickName() + type.getType() + "了你的内容", 60 * 60 * 24 * 30);
}
}
// 删除评论及缓存
// 删除评论通知及缓存,并更新
public void deleteCommentNotify(String notifyUserId, String operatorId, String commentId, LocalDateTime commentTime) {
// 物理删除
NotificationEntity commentNotify = notificationMapper.selectOne(new LambdaQueryWrapper<NotificationEntity>().eq(NotificationEntity::getTargetId, commentId));
NotificationEntity commentNotify = notificationMapper.selectOne(new LambdaQueryWrapper<NotificationEntity>()
.eq(NotificationEntity::getTargetId, commentId)
.eq(NotificationEntity::getOperatorId, operatorId)
.eq(NotificationEntity::getNotifiedUserId, notifyUserId)
.eq(NotificationEntity::getMessageType, NotificationTypeEnum.COMMENT.getCode()));
NotificationEntity last = notificationMapper.selectOne(new LambdaQueryWrapper<NotificationEntity>().eq(NotificationEntity::getNotifiedUserId, notifyUserId)
.orderByDesc(NotificationEntity::getUpdateTime)
.last("limit 1"));
if (commentNotify==null || last==null){
return;
}
notificationMapper.deleteById(commentNotify.getId());
// 如果删除的评论是最後一條通知,则需要从库中再找一条最新的
if (last.getNotificationId().equals(commentNotify.getNotificationId())) {
......@@ -231,7 +267,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();
}
}
......@@ -250,6 +250,12 @@ public class ConvertUtil {
) {
themeNotifyQo.setFormerThemeId(entity.getTargetId());
}
// 评、点赞评论 评论Id
if (entity.getMessageType().equals(NotificationTypeEnum.COMMENT_LIKE.getCode()) ||
entity.getMessageType().equals(NotificationTypeEnum.COMMENT.getCode())
) {
themeNotifyQo.setCommentId(entity.getTargetId());
}
// 转发有话题信息
if (entity.getMessageType().equals(NotificationTypeEnum.FORWARD.getCode())) {
themeNotifyQo.setFormerThemeId(entity.getTargetId());
......@@ -266,7 +272,8 @@ public class ConvertUtil {
}
}
// 点赞需要聚合头像和人数
if (entity.getMessageType().equals(NotificationTypeEnum.LIKE.getCode())) {
if (entity.getMessageType().equals(NotificationTypeEnum.LIKE.getCode()) ||
entity.getMessageType().equals(NotificationTypeEnum.COMMENT_LIKE.getCode())) {
if (!StringUtils.isEmpty(entity.getContent())) {
try {
......@@ -280,8 +287,6 @@ public class ConvertUtil {
}
}
}
return themeNotifyQo;
}
......
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