feat(interaction): 点赞与评论按集统计

This commit is contained in:
Zhou Weidong committed 2026-10-21 15:56:26 +08:00
1 parent c7ff729f84
commit c6f729fb27
28 files changed
+683 -41

No files matched your search

@@ -6,6 +6,7 @@ import com.fruitshorts.common.pojo.PageResult;
import com.fruitshorts.common.pojo.Result;
import com.fruitshorts.content.dal.entity.DramaReviewRecord;
import com.fruitshorts.content.service.DramaService;
import com.fruitshorts.content.service.EpisodeService;
import com.fruitshorts.content.vo.DramaPageReqVO;
import com.fruitshorts.content.vo.DramaRespVO;
import com.fruitshorts.content.vo.DramaSaveReqVO;
@@ -38,13 +39,14 @@ public class DramaController {
private final DramaService dramaService;
private final CommentService commentService;
private final EpisodeService episodeService;
@Operation(summary = "短剧分页查询")
@GetMapping("/page")
@PreAuthorize("@ss.hasPermission('drama:list')")
public Result<PageResult<DramaRespVO>> page(DramaPageReqVO req) {
PageResult<DramaRespVO> page = dramaService.page(req);
fillCommentCounts(page.getList());
fillInteractionCounts(page.getList());
return Result.ok(page);
}
@@ -53,7 +55,7 @@ public class DramaController {
@PreAuthorize("@ss.hasPermission('drama:list')")
public Result<DramaRespVO> get(@PathVariable Long id) {
DramaRespVO drama = dramaService.get(id);
fillCommentCounts(List.of(drama));
fillInteractionCounts(List.of(drama));
return Result.ok(drama);
}
@@ -141,12 +143,16 @@ public class DramaController {
SecurityUtils.getUserId(), SecurityUtils.getUsername());
}
private void fillCommentCounts(List<DramaRespVO> dramas) {
private void fillInteractionCounts(List<DramaRespVO> dramas) {
if (dramas == null || dramas.isEmpty()) {
return;
}
List<Long> ids = dramas.stream().map(DramaRespVO::getId).toList();
Map<Long, Long> counts = commentService.countByDramas(ids);
dramas.forEach(drama -> drama.setCommentCount(counts.getOrDefault(drama.getId(), 0L)));
Map<Long, Long> likeCounts = episodeService.sumLikeCountsByDramas(ids);
Map<Long, Long> commentCounts = commentService.countByDramas(ids);
dramas.forEach(drama -> {
drama.setLikeCount(likeCounts.getOrDefault(drama.getId(), 0L));
drama.setCommentCount(commentCounts.getOrDefault(drama.getId(), 0L));
});
}
}
@@ -3,11 +3,14 @@
package com.fruitshorts.admin.controller;
import com.fruitshorts.common.pojo.Result;
import com.fruitshorts.content.dal.entity.Drama;
import com.fruitshorts.content.service.DramaService;
import com.fruitshorts.content.service.EpisodeService;
import com.fruitshorts.content.vo.EpisodeRespVO;
import com.fruitshorts.content.vo.EpisodeSaveReqVO;
import com.fruitshorts.content.vo.EpisodeSortReqVO;
import com.fruitshorts.framework.log.OperationLog;
import com.fruitshorts.interaction.service.CommentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
@@ -24,6 +27,7 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;
@Tag(name = "后台-剧集管理")
@RestController
@@ -32,13 +36,24 @@ import java.util.List;
public class EpisodeController {
private final EpisodeService episodeService;
private final CommentService commentService;
private final DramaService dramaService;
@Operation(summary = "剧集列表")
@GetMapping
@PreAuthorize("@ss.hasPermission('episode:list')")
public Result<List<EpisodeRespVO>> list(@RequestParam Long dramaId,
@RequestParam(required = false) String status) {
return Result.ok(episodeService.listByDrama(dramaId, status));
List<EpisodeRespVO> episodes = episodeService.listByDrama(dramaId, status);
Map<Long, Long> commentCounts = commentService.countByEpisodes(
episodes.stream().map(EpisodeRespVO::getId).toList());
Drama drama = dramaService.getExisting(dramaId);
episodes.forEach(episode -> {
episode.setCommentCount(commentCounts.getOrDefault(episode.getId(), 0L));
episode.setFavoriteCount(drama.getFavoriteCount());
episode.setHeat(drama.getViewCount());
});
return Result.ok(episodes);
}
@Operation(summary = "新建剧集")