feat(api): 加C端分类频道和剧单详情接口

This commit is contained in:
Zhou Weidong authored and trae-solo-agent committed 2026-10-23 16:45:28 +08:00
1 parent 4f80a691d1
commit 45cf405285
8 files changed
+178 -4

No files matched your search

@@ -27,6 +27,7 @@ import org.springframework.util.StringUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 运营分类服务。分类是独立于「短剧类型(drama_category)」的一套概念,
@@ -190,6 +191,37 @@ public class DramaClassificationService {
}
}
// ========== C 端只读视图 ==========
/** C 端:只返回已启用(status=1)的分类,按 sort 升序。 */
public List<DramaClassification> listEnabled() {
return classificationMapper.selectList(Wrappers.<DramaClassification>lambdaQuery()
.eq(DramaClassification::getStatus, 1)
.orderByAsc(DramaClassification::getSort)
.orderByAsc(DramaClassification::getId));
}
/** C 端:校验分类存在且启用。 */
public DramaClassification getEnabledById(Long id) {
DramaClassification entity = getExisting(id);
if (entity.getStatus() != 1) {
throw new ServiceException(ErrorCode.DATA_NOT_FOUND, "分类不存在或已下架");
}
return entity;
}
/** C 端:分类下关联的全部 dramaId(按关联创建时间 desc)。 */
public List<Long> listDramaIdsByClassification(Long classificationId) {
return classificationDramaMapper.selectList(
Wrappers.<DramaClassificationDrama>lambdaQuery()
.eq(DramaClassificationDrama::getClassificationId, classificationId)
.orderByDesc(DramaClassificationDrama::getCreatedAt)
.orderByDesc(DramaClassificationDrama::getId))
.stream()
.map(DramaClassificationDrama::getDramaId)
.collect(Collectors.toList());
}
private DramaBriefVO toBrief(Drama drama) {
DramaBriefVO vo = new DramaBriefVO();
vo.setId(drama.getId());
@@ -27,6 +27,7 @@ import org.springframework.util.StringUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 剧单分类服务:分类直接关联短剧,没有「剧单」这一层。
@@ -177,6 +178,26 @@ public class DramaPlaylistCategoryService {
return counts;
}
/** C 端用:只返回已启用(status=1)的剧单。 */
public DramaPlaylistCategory getEnabledById(Long id) {
DramaPlaylistCategory entity = getExisting(id);
if (entity.getStatus() == null || entity.getStatus() != 1) {
throw new ServiceException(ErrorCode.DATA_NOT_FOUND, "剧单不存在或已下架");
}
return entity;
}
/** C 端用:剧单下关联的全部 dramaId(按 created_at desc)。 */
public List<Long> listDramaIdsByCategory(Long categoryId) {
return categoryDramaMapper.selectList(Wrappers.<DramaPlaylistCategoryDrama>lambdaQuery()
.eq(DramaPlaylistCategoryDrama::getCategoryId, categoryId)
.orderByDesc(DramaPlaylistCategoryDrama::getCreatedAt)
.orderByDesc(DramaPlaylistCategoryDrama::getId))
.stream()
.map(DramaPlaylistCategoryDrama::getDramaId)
.collect(Collectors.toList());
}
private DramaPlaylistCategory getExisting(Long id) {
DramaPlaylistCategory entity = id == null ? null : categoryMapper.selectById(id);
if (entity == null) {
@@ -226,6 +226,22 @@ public class DramaService {
return dramaMapper.selectPage(page, wrapper).getRecords();
}
/** C 端分类频道:按分类分页查已上线短剧,含 total。 */
public PageResult<Drama> pagePublishedByCategory(Long categoryId, int pageIndex, int pageSize) {
int safeIndex = Math.max(1, pageIndex);
int safeSize = Math.max(1, Math.min(pageSize, 50));
Page<Drama> page = new Page<>(safeIndex, safeSize);
LambdaQueryWrapper<Drama> wrapper = Wrappers.<Drama>lambdaQuery()
.eq(Drama::getStatus, ContentStatus.PUBLISHED.getCode());
if (categoryId != null && categoryId > 0) {
DramaMultiTagSupport.applyCategoryIdTokens(wrapper, List.of(categoryId));
}
wrapper.orderByDesc(Drama::getSort).orderByDesc(Drama::getViewCount)
.orderByDesc(Drama::getId);
IPage<Drama> result = dramaMapper.selectPage(page, wrapper);
return new PageResult<>(result.getTotal(), result.getRecords());
}
/** 已上线短剧,按上线时间倒序 */
public List<Drama> listPublishedLatest(long limit) {
Page<Drama> page = new Page<>(1, Math.max(1, limit));