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

递归删除评论的回复

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