Commit 647df1e7 authored by 刘基明's avatar 刘基明

递归删除评论的回复

parent 3c7b002a
......@@ -43,4 +43,5 @@ public interface ThemeMapper extends BaseMapper<ThemeEntity> {
@Param("pageStart") Integer pageStart, @Param("pageSize") Integer pageSize);
}
......@@ -104,10 +104,10 @@ public class CommentManager {
// 一级回复通知发帖人,二级回复通知一级评论人
if (StringUtils.isNotBlank(req.getReplyUserId())){
if (StringUtils.isNotBlank(req.getReplyUserId())) {
notificationService.insert(userId, req.getReplyUserId(), NotificationTypeEnum.COMMENT_REPLY, commentEntity.getCommentId(), req.getComment());
notificationService.putNotifyCache(req.getReplyUserId(), userId, NotificationTypeEnum.COMMENT_REPLY);
}else {
} else {
notificationService.insert(userId, themeEntity.getAuthorId(), NotificationTypeEnum.COMMENT, commentEntity.getCommentId(), req.getComment());
notificationService.putNotifyCache(themeEntity.getAuthorId(), userId, NotificationTypeEnum.COMMENT);
......@@ -233,10 +233,17 @@ public class CommentManager {
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());
// 循环删除二级评论的一级评论
while (StringUtils.isNotBlank(commentId)) {
// 逻辑删除comment
CommentEntity commentEntity = commentService.delete(commentId, userId);
// 删除站内信
ThemeEntity themeEntity = themeService.queryByThemeId(commentEntity.getThemeId());
notificationService.deleteCommentNotify(themeEntity.getAuthorId(), userId, commentId, commentEntity.getCreateTime());
// 递归
commentId = commentEntity.getReplyId();
userId = commentEntity.getReplyUserId();
}
}
......
......@@ -510,14 +510,15 @@ public class ThemeManager {
} else if (ThemeListTypeEnum.FOLLOW.getCode().equals(req.getType())) {
if (StringUtils.isEmpty(req.getUserId())) {
if (StringUtils.isEmpty(userId)) {
// 未登录情况下返回空数组
themes = Lists.newArrayListWithCapacity(0);
} else {
// 根据关注列表查询,按时间倒序
List<String> fansList = followRelService.queryIdolsByFansId(req.getUserId());
fansList.add(userId); // 保证fansList不为空
// 权限控制,筛选出当前用户有权限的话题
// 权限控制,筛选出当前用户关注的话题
Set<String> userPermitTopics = topicService.getUserPermitTopics(userId);
// 查库
......
......@@ -153,7 +153,7 @@ public class CommentService {
//删除评论
@Transactional
public void delete(String commentId, String userId) {
public CommentEntity delete(String commentId, String userId) {
CommentEntity commentEntity = this.queryByIdIncludeDelete(commentId);
if (commentEntity == null || !commentEntity.getAuthorId().equals(userId)) {
throw new BizException("删除评论与用户不匹配,commentId:" + commentId + ",userId:" + userId);
......@@ -162,6 +162,7 @@ public class CommentService {
commentMapper.updateById(commentEntity);
//失效缓存
evictThemeCache(commentEntity.getThemeId());
return commentEntity;
}
// 失效关联主题缓存
......
......@@ -227,7 +227,7 @@ public class ThemeService {
* @return
*/
public List<ThemeEntity> queryByUserIdsCreateDesc(List<String> userIds, Integer pageStart, Integer pageSize, Set<String> userPermitTopics) {
if (CollectionUtils.isEmpty(userIds)) {
if (CollectionUtils.isEmpty(userIds) && CollectionUtils.isEmpty(userPermitTopics)) {
return Collections.emptyList();
}
userPermitTopics.remove("");
......
......@@ -64,16 +64,21 @@
select
<include refid="Base_Column_List"/>
from theme
where delete_tag=0 and ((author_id in
<foreach item="item" index="index" collection="authorIdCollection"
open="(" separator="," close=")">
#{item}
</foreach>
and topic_id="") or topic_id in
<foreach item="item" index="index" collection="topicIdCollection"
open="(" separator="," close=")">
#{item}
</foreach>
where delete_tag=0 and (
<if test="authorIdCollection != null and authorIdCollection.size() > 0">
author_id in
<foreach item="item" index="index" collection="authorIdCollection"
open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="topicIdCollection != null and topicIdCollection.size() > 0">
or topic_id in
<foreach item="item" index="index" collection="topicIdCollection"
open="(" separator="," close=")">
#{item}
</foreach>
</if>
) order by create_time desc limit #{pageStart}, #{pageSize}
</select>
......
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