feat(kv): 新增批量查询评论内容功能
- 新增 BatchFindCommentContentReqDTO 用于批量查询请求参数校验 - 新增 FindCommentContentReqDTO 和 FindCommentContentRspDTO 用于查询参数与响应封装 - 在 CommentContentController 中添加 /comment/content/batchFind 接口 - 实现 CommentContentRepository 的批量查询方法 - 在 CommentContentServiceImpl 中完成批量查询逻辑,包括参数解析与数据转换 - 更新 gateApi.http 添加批量查询接口测试用例
This commit is contained in:
@@ -4,6 +4,7 @@ import com.hanserwei.framework.biz.operationlog.aspect.ApiOperationLog;
|
||||
import com.hanserwei.framework.common.response.Response;
|
||||
import com.hanserwei.hannote.kv.biz.service.CommentContentService;
|
||||
import com.hanserwei.hannote.kv.dto.req.BatchAddCommentContentReqDTO;
|
||||
import com.hanserwei.hannote.kv.dto.req.BatchFindCommentContentReqDTO;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
@@ -26,4 +27,10 @@ public class CommentContentController {
|
||||
return commentContentService.batchAddCommentContent(batchAddCommentContentReqDTO);
|
||||
}
|
||||
|
||||
@PostMapping(value = "/comment/content/batchFind")
|
||||
@ApiOperationLog(description = "批量查询评论内容")
|
||||
public Response<?> batchFindCommentContent(@Validated @RequestBody BatchFindCommentContentReqDTO batchFindCommentContentReqDTO) {
|
||||
return commentContentService.batchFindCommentContent(batchFindCommentContentReqDTO);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.hanserwei.hannote.kv.biz.domain.repository;
|
||||
|
||||
import com.hanserwei.hannote.kv.biz.domain.dataobject.CommentContentDO;
|
||||
import com.hanserwei.hannote.kv.biz.domain.dataobject.CommentContentPrimaryKey;
|
||||
import org.springframework.data.cassandra.repository.CassandraRepository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public interface CommentContentRepository extends CassandraRepository<CommentContentDO, CommentContentPrimaryKey> {
|
||||
|
||||
/**
|
||||
* 批量查询评论内容
|
||||
*
|
||||
* @param noteId 笔记ID
|
||||
* @param yearMonths 年月
|
||||
* @param contentIds 评论 ID列表
|
||||
* @return 评论内容
|
||||
*/
|
||||
List<CommentContentDO> findByPrimaryKeyNoteIdAndPrimaryKeyYearMonthInAndPrimaryKeyContentIdIn(
|
||||
Long noteId, List<String> yearMonths, List<UUID> contentIds
|
||||
);
|
||||
}
|
||||
@@ -2,8 +2,23 @@ package com.hanserwei.hannote.kv.biz.service;
|
||||
|
||||
import com.hanserwei.framework.common.response.Response;
|
||||
import com.hanserwei.hannote.kv.dto.req.BatchAddCommentContentReqDTO;
|
||||
import com.hanserwei.hannote.kv.dto.req.BatchFindCommentContentReqDTO;
|
||||
|
||||
public interface CommentContentService {
|
||||
|
||||
/**
|
||||
* 批量添加评论内容
|
||||
*
|
||||
* @param batchAddCommentContentReqDTO 批量添加评论内容请求参数
|
||||
* @return 批量添加结果
|
||||
*/
|
||||
Response<?> batchAddCommentContent(BatchAddCommentContentReqDTO batchAddCommentContentReqDTO);
|
||||
|
||||
/**
|
||||
* 批量查询评论内容
|
||||
*
|
||||
* @param batchFindCommentContentReqDTO 批量查询评论内容请求参数
|
||||
* @return 批量查询结果
|
||||
*/
|
||||
Response<?> batchFindCommentContent(BatchFindCommentContentReqDTO batchFindCommentContentReqDTO);
|
||||
}
|
||||
|
||||
@@ -1,12 +1,19 @@
|
||||
package com.hanserwei.hannote.kv.biz.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.hanserwei.framework.common.response.Response;
|
||||
import com.hanserwei.hannote.kv.biz.domain.dataobject.CommentContentDO;
|
||||
import com.hanserwei.hannote.kv.biz.domain.dataobject.CommentContentPrimaryKey;
|
||||
import com.hanserwei.hannote.kv.biz.domain.repository.CommentContentRepository;
|
||||
import com.hanserwei.hannote.kv.biz.service.CommentContentService;
|
||||
import com.hanserwei.hannote.kv.dto.req.BatchAddCommentContentReqDTO;
|
||||
import com.hanserwei.hannote.kv.dto.req.BatchFindCommentContentReqDTO;
|
||||
import com.hanserwei.hannote.kv.dto.req.CommentContentReqDTO;
|
||||
import com.hanserwei.hannote.kv.dto.req.FindCommentContentReqDTO;
|
||||
import com.hanserwei.hannote.kv.dto.resp.FindCommentContentRspDTO;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import org.springframework.data.cassandra.core.CassandraTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -18,6 +25,8 @@ public class CommentContentServiceImpl implements CommentContentService {
|
||||
|
||||
@Resource
|
||||
private CassandraTemplate cassandraTemplate;
|
||||
@Resource
|
||||
private CommentContentRepository commentContentRepository;
|
||||
|
||||
@Override
|
||||
public Response<?> batchAddCommentContent(BatchAddCommentContentReqDTO batchAddCommentContentReqDTO) {
|
||||
@@ -47,4 +56,39 @@ public class CommentContentServiceImpl implements CommentContentService {
|
||||
.execute();
|
||||
return Response.success();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<?> batchFindCommentContent(BatchFindCommentContentReqDTO batchFindCommentContentReqDTO) {
|
||||
// 归属的笔记ID
|
||||
Long noteId = batchFindCommentContentReqDTO.getNoteId();
|
||||
// 查询评论的发布年月、内容 UUID
|
||||
List<FindCommentContentReqDTO> commentContentKeys = batchFindCommentContentReqDTO.getCommentContentKeys();
|
||||
|
||||
// 过滤出年月
|
||||
List<@NotBlank(message = "发布年月不能为空") String> yearMonths = commentContentKeys.stream()
|
||||
.map(FindCommentContentReqDTO::getYearMonth)
|
||||
.distinct()
|
||||
.toList();
|
||||
// 过滤出内容 UUID
|
||||
List<UUID> contentIds = commentContentKeys.stream()
|
||||
.map(r -> UUID.fromString(r.getContentId()))
|
||||
.distinct()
|
||||
.toList();
|
||||
// 批量查询 Cassandra
|
||||
List<CommentContentDO> commentContentDOS = commentContentRepository
|
||||
.findByPrimaryKeyNoteIdAndPrimaryKeyYearMonthInAndPrimaryKeyContentIdIn(noteId, yearMonths, contentIds);
|
||||
|
||||
// DO 转 DTO
|
||||
List<FindCommentContentRspDTO> findCommentContentRspDTOS = Lists.newArrayList();
|
||||
if (CollUtil.isNotEmpty(commentContentDOS)) {
|
||||
findCommentContentRspDTOS = commentContentDOS.stream()
|
||||
.map(commentContentDO -> FindCommentContentRspDTO.builder()
|
||||
.contentId(String.valueOf(commentContentDO.getPrimaryKey().getContentId()))
|
||||
.content(commentContentDO.getContent())
|
||||
.build())
|
||||
.toList();
|
||||
}
|
||||
|
||||
return Response.success(findCommentContentRspDTOS);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user