feat(content): 列表卡片与后台返回收藏点赞评论数
This commit is contained in:
1 parent
f90336963b
commit
256821b824
13 files changed
+324
-50
No files matched your search
+46
@@ -3,6 +3,7 @@
|
||||
package com.fruitshorts.interaction.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
@@ -32,10 +33,12 @@ import org.springframework.util.StringUtils;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@@ -48,6 +51,9 @@ import java.util.Set;
|
||||
@RequiredArgsConstructor
|
||||
public class CommentService {
|
||||
|
||||
private static final String DRAMA_ID_COLUMN = "drama_id";
|
||||
private static final String COMMENT_COUNT_COLUMN = "comment_count";
|
||||
|
||||
public static final String STATUS_PENDING = "pending";
|
||||
public static final String STATUS_PUBLISHED = "published";
|
||||
public static final String STATUS_REJECTED = "rejected";
|
||||
@@ -185,6 +191,46 @@ public class CommentService {
|
||||
return count == null ? 0L : count;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量统计多部剧的未删除评论数,按 drama_id 分组,避免逐剧查询。
|
||||
*/
|
||||
public Map<Long, Long> countByDramas(Collection<Long> dramaIds) {
|
||||
if (dramaIds == null || dramaIds.isEmpty()) {
|
||||
return Map.of();
|
||||
}
|
||||
List<Long> ids = dramaIds.stream().filter(Objects::nonNull).distinct().toList();
|
||||
if (ids.isEmpty()) {
|
||||
return Map.of();
|
||||
}
|
||||
QueryWrapper<ContentComment> wrapper = Wrappers.query();
|
||||
wrapper.select(DRAMA_ID_COLUMN, "COUNT(*) AS " + COMMENT_COUNT_COLUMN)
|
||||
.in(DRAMA_ID_COLUMN, ids)
|
||||
.eq("deleted", 0)
|
||||
.ne("status", STATUS_DELETED)
|
||||
.groupBy(DRAMA_ID_COLUMN);
|
||||
List<Map<String, Object>> rows = commentMapper.selectMaps(wrapper);
|
||||
if (rows == null || rows.isEmpty()) {
|
||||
return Map.of();
|
||||
}
|
||||
Map<Long, Long> counts = new HashMap<>();
|
||||
for (Map<String, Object> row : rows) {
|
||||
Long dramaId = asLong(row.get(DRAMA_ID_COLUMN));
|
||||
if (dramaId != null) {
|
||||
counts.put(dramaId, asLong(row.get(COMMENT_COUNT_COLUMN), 0L));
|
||||
}
|
||||
}
|
||||
return counts;
|
||||
}
|
||||
|
||||
private Long asLong(Object value) {
|
||||
return value instanceof Number number ? number.longValue() : null;
|
||||
}
|
||||
|
||||
private long asLong(Object value, long defaultValue) {
|
||||
Long number = asLong(value);
|
||||
return number == null ? defaultValue : number;
|
||||
}
|
||||
|
||||
// ---------------- 后台 ----------------
|
||||
|
||||
public PageResult<CommentRespVO> adminPage(CommentQueryReqVO req) {
|
||||
|
||||
Reference in new issue
Block a user