|
|
@@ -637,18 +637,90 @@ public class ContentPlatformPlanServiceImpl implements ContentPlatformPlanServic
|
|
|
* 单一来源分页:从对应候选池取最多 N 条,按候选池顺序分页。
|
|
|
*/
|
|
|
private Page<VideoContentItemVO> getSingleSourcePage(VideoContentListParam param, ContentPlatformAccount user, String source) {
|
|
|
- List<VideoContentItemVO> candidates;
|
|
|
- if (SOURCE_PRIOR.equals(source)) {
|
|
|
- candidates = fetchPriorCandidates(user, RECOMMEND_CANDIDATE_LIMIT);
|
|
|
- } else if (SOURCE_POSTERIOR.equals(source)) {
|
|
|
- candidates = fetchPosteriorCandidates(user, RECOMMEND_CANDIDATE_LIMIT);
|
|
|
- } else {
|
|
|
- candidates = fetchHotCandidates(param, user, RECOMMEND_CANDIDATE_LIMIT);
|
|
|
+ if (SOURCE_HOT.equals(source)) {
|
|
|
+ return getHotSourcePaged(param, user);
|
|
|
+ }
|
|
|
+ String demandStrategy = SOURCE_PRIOR.equals(source) ? DEMAND_STRATEGY_PRIOR : DEMAND_STRATEGY_POSTERIOR;
|
|
|
+ return getDemandSourcePaged(param, user, source, demandStrategy);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 单源 prior/posterior:SQL OFFSET/LIMIT 真分页,totalSize 来自 COUNT(*)。
|
|
|
+ * 信任离线侧 (crowd_segment, strategy) 内 video_id 已去重的约定。
|
|
|
+ */
|
|
|
+ private Page<VideoContentItemVO> getDemandSourcePaged(VideoContentListParam param, ContentPlatformAccount user,
|
|
|
+ String source, String demandStrategy) {
|
|
|
+ int pageSize = param.getPageSize();
|
|
|
+ int pageNum = param.getPageNum();
|
|
|
+ Page<VideoContentItemVO> result = new Page<>(pageNum, pageSize);
|
|
|
+ String dt = demandVideoMapperExt.getMaxDt();
|
|
|
+ if (!StringUtils.hasText(dt)) {
|
|
|
+ result.setTotalSize(0);
|
|
|
+ result.setObjs(new ArrayList<>());
|
|
|
+ return result;
|
|
|
}
|
|
|
- for (VideoContentItemVO v : candidates) {
|
|
|
+ String crowdSegment = user.getChannel();
|
|
|
+ boolean excludeSelfTitle = DEMAND_STRATEGY_POSTERIOR.equals(demandStrategy);
|
|
|
+ int count = demandVideoMapperExt.countForRecommend(dt, crowdSegment, demandStrategy, excludeSelfTitle);
|
|
|
+ result.setTotalSize(count);
|
|
|
+ if (count == 0) {
|
|
|
+ result.setObjs(new ArrayList<>());
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ int offset = (pageNum - 1) * pageSize;
|
|
|
+ if (offset >= count) {
|
|
|
+ result.setObjs(new ArrayList<>());
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ List<ContentPlatformDemandVideo> rows = demandVideoMapperExt.selectForRecommendPaged(dt, crowdSegment, demandStrategy, offset, pageSize, excludeSelfTitle);
|
|
|
+ List<VideoContentItemVO> list = buildDemandVideoContentItemVOList(rows);
|
|
|
+ for (VideoContentItemVO v : list) {
|
|
|
v.setSource(source);
|
|
|
}
|
|
|
- return paginateCandidates(param, candidates);
|
|
|
+ result.setObjs(list);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 单源 hot:复用原 planMapperExt.getVideoCount + getVideoList 真分页链路。
|
|
|
+ */
|
|
|
+ private Page<VideoContentItemVO> getHotSourcePaged(VideoContentListParam param, ContentPlatformAccount user) {
|
|
|
+ int pageSize = param.getPageSize();
|
|
|
+ int pageNum = param.getPageNum();
|
|
|
+ Page<VideoContentItemVO> result = new Page<>(pageNum, pageSize);
|
|
|
+ String dt = planMapperExt.getVideoMaxDt();
|
|
|
+ String datastatDt = planMapperExt.getVideoDatastatMaxDt();
|
|
|
+ if (!StringUtils.hasText(dt)) {
|
|
|
+ result.setTotalSize(0);
|
|
|
+ result.setObjs(new ArrayList<>());
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ int count = planMapperExt.getVideoCount(param, dt, videoMinScore);
|
|
|
+ result.setTotalSize(count);
|
|
|
+ if (count == 0) {
|
|
|
+ result.setObjs(new ArrayList<>());
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ int offset = (pageNum - 1) * pageSize;
|
|
|
+ if (offset >= count) {
|
|
|
+ result.setObjs(new ArrayList<>());
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ String sort = getVideoContentListSort(param.getSort());
|
|
|
+ String type = getVideoContentListType(param.getType());
|
|
|
+ String channel = getVideoContentListChannel(param.getSort(), user.getChannel());
|
|
|
+ String strategy = param.getSort() == 3 ? "recommend" : "normal";
|
|
|
+ List<ContentPlatformVideo> videoList = planMapperExt.getVideoList(param, dt, datastatDt, type, channel, strategy,
|
|
|
+ videoMinScore, offset, pageSize, sort);
|
|
|
+ List<VideoContentItemVO> list = buildVideoContentItemVOList(videoList, type, "sum", user.getChannel(), datastatDt);
|
|
|
+ if (list == null) {
|
|
|
+ list = new ArrayList<>();
|
|
|
+ }
|
|
|
+ for (VideoContentItemVO v : list) {
|
|
|
+ v.setSource(SOURCE_HOT);
|
|
|
+ }
|
|
|
+ result.setObjs(list);
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -720,8 +792,9 @@ public class ContentPlatformPlanServiceImpl implements ContentPlatformPlanServic
|
|
|
return new ArrayList<>();
|
|
|
}
|
|
|
String crowdSegment = user.getChannel();
|
|
|
+ boolean excludeSelfTitle = DEMAND_STRATEGY_POSTERIOR.equals(demandStrategy);
|
|
|
// 超量拉取,再按 video_id 去重保留首条(即得分最高的一条)
|
|
|
- List<ContentPlatformDemandVideo> rows = demandVideoMapperExt.selectForRecommend(dt, crowdSegment, demandStrategy, limit * 3);
|
|
|
+ List<ContentPlatformDemandVideo> rows = demandVideoMapperExt.selectForRecommend(dt, crowdSegment, demandStrategy, limit * 3, excludeSelfTitle);
|
|
|
if (CollectionUtils.isEmpty(rows)) {
|
|
|
return new ArrayList<>();
|
|
|
}
|