feat(service): 增加评论屏蔽用户过滤逻辑

This commit is contained in:
2026-03-23 11:25:20 +08:00
parent 1fa24f7e34
commit eaf015fe48
3 changed files with 20 additions and 0 deletions

View File

@@ -18,4 +18,6 @@ public interface KeyboardCommentBlockRelationService extends IService<KeyboardCo
void unblockUser(Long blockerUserId, Long blockedUserId); void unblockUser(Long blockerUserId, Long blockedUserId);
List<CommentBlockedUserVO> listBlockedUsers(Long blockerUserId); List<CommentBlockedUserVO> listBlockedUsers(Long blockerUserId);
List<Long> listBlockedUserIds(Long blockerUserId);
} }

View File

@@ -13,6 +13,7 @@ import com.yolo.keyborad.model.entity.KeyboardUser;
import com.yolo.keyborad.model.vo.CommentVO; import com.yolo.keyborad.model.vo.CommentVO;
import com.yolo.keyborad.service.KeyboardAiCompanionCommentService; import com.yolo.keyborad.service.KeyboardAiCompanionCommentService;
import com.yolo.keyborad.service.KeyboardAiCompanionCommentLikeService; import com.yolo.keyborad.service.KeyboardAiCompanionCommentLikeService;
import com.yolo.keyborad.service.KeyboardCommentBlockRelationService;
import com.yolo.keyborad.service.UserService; import com.yolo.keyborad.service.UserService;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@@ -45,6 +46,9 @@ public class KeyboardAiCompanionCommentServiceImpl extends ServiceImpl<KeyboardA
@Resource @Resource
private KeyboardAiCompanionCommentLikeService commentLikeService; private KeyboardAiCompanionCommentLikeService commentLikeService;
@Resource
private KeyboardCommentBlockRelationService commentBlockRelationService;
@Override @Override
public Long addComment(Long userId, Long companionId, String content, Long parentId, Long rootId) { public Long addComment(Long userId, Long companionId, String content, Long parentId, Long rootId) {
KeyboardAiCompanionComment comment = new KeyboardAiCompanionComment(); KeyboardAiCompanionComment comment = new KeyboardAiCompanionComment();
@@ -102,11 +106,13 @@ public class KeyboardAiCompanionCommentServiceImpl extends ServiceImpl<KeyboardA
@Override @Override
public IPage<CommentVO> pageCommentsWithLikeStatus(Long userId, Long companionId, Integer pageNum, Integer pageSize) { public IPage<CommentVO> pageCommentsWithLikeStatus(Long userId, Long companionId, Integer pageNum, Integer pageSize) {
List<Long> blockedUserIds = commentBlockRelationService.listBlockedUserIds(userId);
Page<KeyboardAiCompanionComment> page = new Page<>(pageNum, pageSize); Page<KeyboardAiCompanionComment> page = new Page<>(pageNum, pageSize);
LambdaQueryWrapper<KeyboardAiCompanionComment> queryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<KeyboardAiCompanionComment> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(KeyboardAiCompanionComment::getCompanionId, companionId) queryWrapper.eq(KeyboardAiCompanionComment::getCompanionId, companionId)
.eq(KeyboardAiCompanionComment::getStatus, ACTIVE_STATUS) .eq(KeyboardAiCompanionComment::getStatus, ACTIVE_STATUS)
.isNull(KeyboardAiCompanionComment::getParentId) .isNull(KeyboardAiCompanionComment::getParentId)
.notIn(!blockedUserIds.isEmpty(), KeyboardAiCompanionComment::getUserId, blockedUserIds)
.orderByDesc(KeyboardAiCompanionComment::getCreatedAt); .orderByDesc(KeyboardAiCompanionComment::getCreatedAt);
IPage<KeyboardAiCompanionComment> entityPage = this.page(page, queryWrapper); IPage<KeyboardAiCompanionComment> entityPage = this.page(page, queryWrapper);
@@ -124,6 +130,7 @@ public class KeyboardAiCompanionCommentServiceImpl extends ServiceImpl<KeyboardA
LambdaQueryWrapper<KeyboardAiCompanionComment> replyWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<KeyboardAiCompanionComment> replyWrapper = new LambdaQueryWrapper<>();
replyWrapper.in(KeyboardAiCompanionComment::getRootId, topCommentIds) replyWrapper.in(KeyboardAiCompanionComment::getRootId, topCommentIds)
.eq(KeyboardAiCompanionComment::getStatus, ACTIVE_STATUS) .eq(KeyboardAiCompanionComment::getStatus, ACTIVE_STATUS)
.notIn(!blockedUserIds.isEmpty(), KeyboardAiCompanionComment::getUserId, blockedUserIds)
.orderByAsc(KeyboardAiCompanionComment::getCreatedAt); .orderByAsc(KeyboardAiCompanionComment::getCreatedAt);
allReplies = this.list(replyWrapper); allReplies = this.list(replyWrapper);

View File

@@ -84,6 +84,17 @@ public class KeyboardCommentBlockRelationServiceImpl extends ServiceImpl<Keyboar
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
@Override
public List<Long> listBlockedUserIds(Long blockerUserId) {
if (blockerUserId == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
return listActiveRelations(blockerUserId).stream()
.map(KeyboardCommentBlockRelation::getBlockedUserId)
.distinct()
.collect(Collectors.toList());
}
private void validateUserIds(Long blockerUserId, Long blockedUserId) { private void validateUserIds(Long blockerUserId, Long blockedUserId) {
if (blockerUserId == null || blockedUserId == null) { if (blockerUserId == null || blockedUserId == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR); throw new BusinessException(ErrorCode.PARAMS_ERROR);