feat(interaction): 新增分集计数统计接口
This commit is contained in:
1 parent
15b540cdd6
commit
2fe24b9db7
10 files changed
+299
-2
No files matched your search
+26
@@ -18,7 +18,10 @@ import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 点赞。关系表是事实来源,计数同步更新在目标行上。
|
||||
@@ -86,6 +89,29 @@ public class LikeService {
|
||||
return comment == null || comment.getLikeCount() == null ? 0L : comment.getLikeCount();
|
||||
}
|
||||
|
||||
/** 批量判断用户是否已点赞,一次查询覆盖多个目标。 */
|
||||
public Set<Long> likedTargetIds(Long userId, String type, Collection<Long> targetIds) {
|
||||
if (userId == null || targetIds == null || targetIds.isEmpty()) {
|
||||
return Set.of();
|
||||
}
|
||||
Set<Long> normalized = new HashSet<>();
|
||||
for (Long targetId : targetIds) {
|
||||
if (targetId != null) {
|
||||
normalized.add(targetId);
|
||||
}
|
||||
}
|
||||
if (normalized.isEmpty()) {
|
||||
return Set.of();
|
||||
}
|
||||
return likeMapper.selectList(Wrappers.<ContentLike>lambdaQuery()
|
||||
.eq(ContentLike::getUserId, userId)
|
||||
.eq(ContentLike::getTargetType, type)
|
||||
.in(ContentLike::getTargetId, normalized))
|
||||
.stream()
|
||||
.map(ContentLike::getTargetId)
|
||||
.collect(java.util.stream.Collectors.toSet());
|
||||
}
|
||||
|
||||
private void adjustCount(String type, Long targetId, int delta) {
|
||||
if (TYPE_DRAMA.equals(type)) {
|
||||
dramaService.adjustLikeCount(targetId, delta);
|
||||
|
||||
Reference in new issue
Block a user