feat(favorites): 支持设备批量取消收藏
This commit is contained in:
1 parent
5d44ac239b
commit
23321a0b0c
8 files changed
+147
-6
No files matched your search
+23
-3
@@ -206,19 +206,39 @@ public class FavoriteService {
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void removeBatch(Long userId, List<Long> dramaIds) {
|
||||
public int removeBatch(Long userId, List<Long> dramaIds) {
|
||||
return removeBatchInternal(new InteractionIdentity(userId, ""), dramaIds);
|
||||
}
|
||||
|
||||
/** 登录账号或匿名设备在同一事务内批量取消收藏。 */
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int removeBatch(InteractionIdentity identity, List<Long> dramaIds) {
|
||||
return removeBatchInternal(identity, dramaIds);
|
||||
}
|
||||
|
||||
private int removeBatchInternal(
|
||||
InteractionIdentity identity, List<Long> dramaIds) {
|
||||
if (dramaIds == null || dramaIds.isEmpty()) {
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
Set<Long> normalized = new HashSet<>();
|
||||
for (Long dramaId : dramaIds) {
|
||||
if (dramaId == null) {
|
||||
continue;
|
||||
}
|
||||
int removed = favoriteMapper.physicalDelete(userId, dramaId);
|
||||
normalized.add(dramaId);
|
||||
}
|
||||
int deleted = 0;
|
||||
for (Long dramaId : normalized) {
|
||||
int removed = identity.authenticated()
|
||||
? favoriteMapper.physicalDelete(identity.userId(), dramaId)
|
||||
: favoriteMapper.physicalDeleteDevice(identity.deviceId(), dramaId);
|
||||
if (removed > 0) {
|
||||
dramaService.adjustFavoriteCount(dramaId, -1);
|
||||
deleted += removed;
|
||||
}
|
||||
}
|
||||
return deleted;
|
||||
}
|
||||
|
||||
/** 查询用户对某部剧最近一次收藏时间。 */
|
||||
|
||||
+6
-1
@@ -4,6 +4,7 @@ package com.fruitshorts.playback.vo;
|
||||
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import java.util.List;
|
||||
import lombok.Data;
|
||||
|
||||
@@ -11,6 +12,10 @@ import lombok.Data;
|
||||
@Data
|
||||
public class FavoriteRemoveReqVO {
|
||||
|
||||
@NotEmpty(message = "缺少 dramaIds")
|
||||
@NotEmpty(message = "dramaIds 不能为空")
|
||||
@Size(max = 200, message = "dramaIds 最多 200 条")
|
||||
private List<@NotNull Long> dramaIds;
|
||||
|
||||
/** 未登录且未携带 X-Device-Id 时的兜底设备号。 */
|
||||
private String deviceId;
|
||||
}
|
||||
Reference in new issue
Block a user