diff --git a/src/main/java/com/youlai/boot/mini/controller/StrayAnimalNoteCommentController.java b/src/main/java/com/youlai/boot/mini/controller/StrayAnimalNoteCommentController.java index cac7ac4..99fca9b 100644 --- a/src/main/java/com/youlai/boot/mini/controller/StrayAnimalNoteCommentController.java +++ b/src/main/java/com/youlai/boot/mini/controller/StrayAnimalNoteCommentController.java @@ -10,7 +10,9 @@ import com.youlai.boot.framework.security.util.SecurityUtils; import com.youlai.boot.mini.model.form.DeleteStrayAnimalNoteCommentForm; import com.youlai.boot.mini.model.form.StrayAnimalNoteCommentForm; import com.youlai.boot.mini.model.query.AnimalNoteFirstLevelCommentQueryParam; +import com.youlai.boot.mini.model.query.AnimalNoteSecondLevelCommentQueryParam; import com.youlai.boot.mini.model.vo.AnimalNoteFirstLevelCommentVO; +import com.youlai.boot.mini.model.vo.AnimalNoteSecondLevelCommentVO; import com.youlai.boot.mini.model.vo.StrayAnimalNoteCommentVO; import com.youlai.boot.mini.service.StrayAnimalNoteCommentService; import io.swagger.v3.oas.annotations.Operation; @@ -63,4 +65,15 @@ public class StrayAnimalNoteCommentController { return Result.success(result); } + @Operation(summary = "分页查询笔记二级评论列表接口") + @PostMapping(value = "secondLevel/list") + @Log(module = LogModuleEnum.STRAY_ANIMAL_NOTE_COMMENT, value = ActionTypeEnum.LIST) + public Result> getSecondLevelCommentList( + @Valid @RequestBody AnimalNoteSecondLevelCommentQueryParam queryParam + ) { + Long userId = SecurityUtils.getUserId(); + IPage result = strayAnimalNoteCommentService.getSecondLevelCommentList(queryParam, userId); + return Result.success(result); + } + } diff --git a/src/main/java/com/youlai/boot/mini/mapper/MiniStrayAnimalNoteCommentMapper.java b/src/main/java/com/youlai/boot/mini/mapper/MiniStrayAnimalNoteCommentMapper.java index c53c594..ebdcb6b 100644 --- a/src/main/java/com/youlai/boot/mini/mapper/MiniStrayAnimalNoteCommentMapper.java +++ b/src/main/java/com/youlai/boot/mini/mapper/MiniStrayAnimalNoteCommentMapper.java @@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.youlai.boot.mini.model.entity.MiniStrayAnimalNoteComment; import com.youlai.boot.mini.model.entity.MiniStrayAnimalNoteCommentLike; import com.youlai.boot.mini.model.query.AnimalNoteFirstLevelCommentQueryParam; +import com.youlai.boot.mini.model.query.AnimalNoteSecondLevelCommentQueryParam; import com.youlai.boot.mini.model.vo.AnimalNoteFirstLevelCommentVO; import com.youlai.boot.mini.model.vo.AnimalNoteSecondLevelCommentVO; import org.apache.ibatis.annotations.Param; @@ -32,6 +33,8 @@ public interface MiniStrayAnimalNoteCommentMapper extends BaseMapper getFirstLevelComment(IPage page, @Param("query") AnimalNoteFirstLevelCommentQueryParam query); + IPage getSecondLevelComment(IPage page, @Param("query") AnimalNoteSecondLevelCommentQueryParam query); + List batchGetUserCommentLikes(@Param("noteCommentIds") List noteCommentIds, @Param("appUserId") Long appUserId); } diff --git a/src/main/java/com/youlai/boot/mini/model/query/AnimalNoteFirstLevelCommentQueryParam.java b/src/main/java/com/youlai/boot/mini/model/query/AnimalNoteFirstLevelCommentQueryParam.java index 0990e8b..f6e8ebd 100644 --- a/src/main/java/com/youlai/boot/mini/model/query/AnimalNoteFirstLevelCommentQueryParam.java +++ b/src/main/java/com/youlai/boot/mini/model/query/AnimalNoteFirstLevelCommentQueryParam.java @@ -12,7 +12,7 @@ import lombok.EqualsAndHashCode; @Schema(description = "动物笔记一级评论分页查询参数") public class AnimalNoteFirstLevelCommentQueryParam extends BaseQuery { - @NotBlank(message = "笔记UUID不能为空") - @Schema(description = "动物笔记UUID", requiredMode = Schema.RequiredMode.REQUIRED, example = "0677d62d63ec693bf1bd6dab8a877dc1") - private String noteUUId; + @NotBlank(message = "笔记uuid不能为空") + @Schema(description = "动物笔记uuid", requiredMode = Schema.RequiredMode.REQUIRED, example = "0677d62d63ec693bf1bd6dab8a877dc1") + private String noteUuId; } diff --git a/src/main/java/com/youlai/boot/mini/model/query/AnimalNoteSecondLevelCommentQueryParam.java b/src/main/java/com/youlai/boot/mini/model/query/AnimalNoteSecondLevelCommentQueryParam.java new file mode 100644 index 0000000..7b6143e --- /dev/null +++ b/src/main/java/com/youlai/boot/mini/model/query/AnimalNoteSecondLevelCommentQueryParam.java @@ -0,0 +1,21 @@ +package com.youlai.boot.mini.model.query; + +import com.youlai.boot.common.base.BaseQuery; +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotBlank; +import lombok.Data; +import lombok.EqualsAndHashCode; + +@Data +@EqualsAndHashCode(callSuper = true) +@Schema(description = "动物笔记二级评论分页查询参数") +public class AnimalNoteSecondLevelCommentQueryParam extends BaseQuery { + + @NotBlank(message = "笔记uuid不能为空") + @Schema(description = "动物笔记uuid", requiredMode = Schema.RequiredMode.REQUIRED, example = "0677d62d63ec693bf1bd6dab8a877dc1") + private String noteUuId; + + @NotBlank(message = "一级评论uuid不能为空") + @Schema(description = "一级评论uuid", requiredMode = Schema.RequiredMode.REQUIRED, example = "a1b2c3d4e5f6g7h8i9j0") + private String rootUuid; +} diff --git a/src/main/java/com/youlai/boot/mini/model/vo/AnimalNoteSecondLevelCommentVO.java b/src/main/java/com/youlai/boot/mini/model/vo/AnimalNoteSecondLevelCommentVO.java index 37479ca..62aad59 100644 --- a/src/main/java/com/youlai/boot/mini/model/vo/AnimalNoteSecondLevelCommentVO.java +++ b/src/main/java/com/youlai/boot/mini/model/vo/AnimalNoteSecondLevelCommentVO.java @@ -1,6 +1,7 @@ package com.youlai.boot.mini.model.vo; import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonIgnore; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; @@ -17,8 +18,12 @@ public class AnimalNoteSecondLevelCommentVO { @Schema(description = "动物笔记评论uuid") private String uuid; - @Schema(description = "评论用户uuid") - private String miniUserUuId; + @JsonIgnore + @Schema(hidden = true) + private Long commentId; + + @Schema(description = "评论用户UUID") + private String appUserId; @Schema(description = "评论用户头像") private String avatarUrl; @@ -29,11 +34,8 @@ public class AnimalNoteSecondLevelCommentVO { @Schema(description = "评论内容") private String content; - @Schema(description = "父评论ID,0为一级评论") - private Long parentId; - - @Schema(description = "根评论ID,一级评论为自身ID,二级及以上为所属一级评论ID") - private Long rootId; + @Schema(description = "父评论UUID") + private String parentUuId; @Schema(description = "被回复的用户ID") private Long replyToUserId; @@ -45,7 +47,7 @@ public class AnimalNoteSecondLevelCommentVO { private String replyToNickname; @Schema(description = "点赞数") - private Integer likeCount; + private Long likeCount; @Schema(description = "创建时间戳") private Long createTimestamp; diff --git a/src/main/java/com/youlai/boot/mini/service/StrayAnimalNoteCommentService.java b/src/main/java/com/youlai/boot/mini/service/StrayAnimalNoteCommentService.java index 7df1a60..192805a 100644 --- a/src/main/java/com/youlai/boot/mini/service/StrayAnimalNoteCommentService.java +++ b/src/main/java/com/youlai/boot/mini/service/StrayAnimalNoteCommentService.java @@ -6,7 +6,9 @@ import com.youlai.boot.mini.model.entity.MiniStrayAnimalNoteComment; import com.youlai.boot.mini.model.form.DeleteStrayAnimalNoteCommentForm; import com.youlai.boot.mini.model.form.StrayAnimalNoteCommentForm; import com.youlai.boot.mini.model.query.AnimalNoteFirstLevelCommentQueryParam; +import com.youlai.boot.mini.model.query.AnimalNoteSecondLevelCommentQueryParam; import com.youlai.boot.mini.model.vo.AnimalNoteFirstLevelCommentVO; +import com.youlai.boot.mini.model.vo.AnimalNoteSecondLevelCommentVO; import com.youlai.boot.mini.model.vo.StrayAnimalNoteCommentVO; import jakarta.validation.Valid; @@ -18,4 +20,6 @@ public interface StrayAnimalNoteCommentService extends IService getFirstLevelCommentList(AnimalNoteFirstLevelCommentQueryParam queryParam, Long userId); + IPage getSecondLevelCommentList(AnimalNoteSecondLevelCommentQueryParam queryParam, Long userId); + } diff --git a/src/main/java/com/youlai/boot/mini/service/impl/StrayAnimalNoteCommentServiceImpl.java b/src/main/java/com/youlai/boot/mini/service/impl/StrayAnimalNoteCommentServiceImpl.java index 0570f4b..6093d84 100644 --- a/src/main/java/com/youlai/boot/mini/service/impl/StrayAnimalNoteCommentServiceImpl.java +++ b/src/main/java/com/youlai/boot/mini/service/impl/StrayAnimalNoteCommentServiceImpl.java @@ -18,6 +18,7 @@ import com.youlai.boot.mini.model.entity.MiniStrayAnimalNoteCommentLike; import com.youlai.boot.mini.model.form.DeleteStrayAnimalNoteCommentForm; import com.youlai.boot.mini.model.form.StrayAnimalNoteCommentForm; import com.youlai.boot.mini.model.query.AnimalNoteFirstLevelCommentQueryParam; +import com.youlai.boot.mini.model.query.AnimalNoteSecondLevelCommentQueryParam; import com.youlai.boot.mini.model.vo.AnimalNoteFirstLevelCommentVO; import com.youlai.boot.mini.model.vo.AnimalNoteSecondLevelCommentVO; import com.youlai.boot.mini.model.vo.StrayAnimalNoteCommentVO; @@ -239,4 +240,45 @@ public class StrayAnimalNoteCommentServiceImpl extends ServiceImpl getSecondLevelCommentList(AnimalNoteSecondLevelCommentQueryParam queryParam, Long userId) { + // 1. 构造分页参数,默认值兼容 + Page page = new Page<>(queryParam.getPageNum(), queryParam.getPageSize()); + + // 2. 查询二级评论分页 + IPage result = baseMapper.getSecondLevelComment(page, queryParam); + List commentList = result.getRecords(); + if (commentList.isEmpty() || userId == null) { + return result; + } + + // 3. 提取二级评论内部主键ID(用于查询点赞状态) + List secondLevelCommentIds = commentList.stream() + .map(AnimalNoteSecondLevelCommentVO::getCommentId) + .collect(Collectors.toList()); + + // 4. 批量查询登录用户的点赞状态 + Map likeStatusMap = Collections.emptyMap(); + try { + List likeList = baseMapper.batchGetUserCommentLikes(secondLevelCommentIds, userId); + likeStatusMap = likeList.stream() + .collect(Collectors.toMap( + MiniStrayAnimalNoteCommentLike::getNoteCommentId, + like -> Boolean.TRUE, + (v1, v2) -> v1 + )); + } catch (Exception e) { + log.error("批量查询二级评论点赞状态失败,用户ID:{}", userId, e); + } + + // 5. 给每个评论设置点赞状态 + for (AnimalNoteSecondLevelCommentVO comment : commentList) { + Boolean isLiked = likeStatusMap.get(comment.getCommentId()); + comment.setIsLiked(Boolean.TRUE.equals(isLiked)); + } + + return result; + } + } diff --git a/src/main/resources/mapper/mini/MiniStrayAnimalNoteCommentMapper.xml b/src/main/resources/mapper/mini/MiniStrayAnimalNoteCommentMapper.xml index 12fed01..11ddb82 100644 --- a/src/main/resources/mapper/mini/MiniStrayAnimalNoteCommentMapper.xml +++ b/src/main/resources/mapper/mini/MiniStrayAnimalNoteCommentMapper.xml @@ -110,7 +110,7 @@ AND sc.is_deleted = 0 ) AS secondLevelCount FROM mini_stray_animal_note_comment sanc - INNER JOIN mini_stray_animal_note note ON sanc.note_id = note.id AND note.uuid = #{query.noteUUId} AND note.is_deleted = 0 + INNER JOIN mini_stray_animal_note note ON sanc.note_id = note.id AND note.uuid = #{query.noteUuId} AND note.is_deleted = 0 LEFT JOIN sys_user au ON sanc.mini_user_id = au.id AND au.is_deleted = 0 WHERE sanc.parent_id = 0 AND sanc.is_deleted = 0 @@ -118,6 +118,35 @@ ORDER BY sanc.like_count DESC, sanc.create_timestamp DESC + + +