feat(content): 列表卡片与后台返回收藏点赞评论数

This commit is contained in:
Zhou Weidong committed 2026-10-21 11:14:18 +08:00
1 parent f90336963b
commit 256821b824
13 files changed
+324 -50

No files matched your search

@@ -10,8 +10,9 @@ import com.fruitshorts.content.vo.DramaPageReqVO;
import com.fruitshorts.content.vo.DramaRespVO;
import com.fruitshorts.content.vo.DramaSaveReqVO;
import com.fruitshorts.content.vo.DramaStatusReqVO;
import com.fruitshorts.framework.security.SecurityUtils;
import com.fruitshorts.framework.log.OperationLog;
import com.fruitshorts.framework.security.SecurityUtils;
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;
@@ -27,6 +28,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;
@Tag(name = "后台-短剧管理")
@RestController
@@ -35,19 +37,24 @@ import java.util.List;
public class DramaController {
private final DramaService dramaService;
private final CommentService commentService;
@Operation(summary = "短剧分页查询")
@GetMapping("/page")
@PreAuthorize("@ss.hasPermission('drama:list')")
public Result<PageResult<DramaRespVO>> page(DramaPageReqVO req) {
return Result.ok(dramaService.page(req));
PageResult<DramaRespVO> page = dramaService.page(req);
fillCommentCounts(page.getList());
return Result.ok(page);
}
@Operation(summary = "短剧详情")
@GetMapping("/{id}")
@PreAuthorize("@ss.hasPermission('drama:list')")
public Result<DramaRespVO> get(@PathVariable Long id) {
return Result.ok(dramaService.get(id));
DramaRespVO drama = dramaService.get(id);
fillCommentCounts(List.of(drama));
return Result.ok(drama);
}
@Operation(summary = "新建短剧")
@@ -133,4 +140,13 @@ public class DramaController {
dramaService.changeStatus(id, action, req == null ? null : req.getReason(),
SecurityUtils.getUserId(), SecurityUtils.getUsername());
}
private void fillCommentCounts(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)));
}
}