|  | @@ -6,7 +6,6 @@ import com.tzld.longarticle.recommend.server.service.AccountContentPoolConfigSer
 | 
	
		
			
				|  |  |  import com.tzld.longarticle.recommend.server.service.score.ScoreParam;
 | 
	
		
			
				|  |  |  import com.tzld.longarticle.recommend.server.service.score.ScoreResult;
 | 
	
		
			
				|  |  |  import com.tzld.longarticle.recommend.server.service.score.ScoreService;
 | 
	
		
			
				|  |  | -import com.tzld.longarticle.recommend.server.service.score.strategy.ContentPoolStrategy;
 | 
	
		
			
				|  |  |  import com.tzld.longarticle.recommend.server.service.score.strategy.SimilarityStrategy;
 | 
	
		
			
				|  |  |  import com.tzld.longarticle.recommend.server.service.score.strategy.ViewCountStrategy;
 | 
	
		
			
				|  |  |  import com.tzld.longarticle.recommend.server.util.CommonCollectionUtils;
 | 
	
	
		
			
				|  | @@ -15,6 +14,7 @@ import com.tzld.longarticle.recommend.server.util.TitleSimilarCheckUtil;
 | 
	
		
			
				|  |  |  import lombok.extern.slf4j.Slf4j;
 | 
	
		
			
				|  |  |  import org.apache.commons.collections4.CollectionUtils;
 | 
	
		
			
				|  |  |  import org.apache.commons.lang3.RandomUtils;
 | 
	
		
			
				|  |  | +import org.apache.commons.lang3.StringUtils;
 | 
	
		
			
				|  |  |  import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  |  import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -47,45 +47,49 @@ public class RankService {
 | 
	
		
			
				|  |  |              return item;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          });
 | 
	
		
			
				|  |  | -        Collections.sort(items, (o1, o2) -> {
 | 
	
		
			
				|  |  | -            int contentPoolComparison = Double.compare(
 | 
	
		
			
				|  |  | -                    o1.getScore(ContentPoolStrategy.class.getSimpleName()),
 | 
	
		
			
				|  |  | -                    o2.getScore(ContentPoolStrategy.class.getSimpleName())
 | 
	
		
			
				|  |  | -            );
 | 
	
		
			
				|  |  | -            if (contentPoolComparison != 0) {
 | 
	
		
			
				|  |  | -                return -contentPoolComparison; // 降序
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -            int similarityComparison = Double.compare(
 | 
	
		
			
				|  |  | -                    o1.getScore(SimilarityStrategy.class.getSimpleName()),
 | 
	
		
			
				|  |  | -                    o2.getScore(SimilarityStrategy.class.getSimpleName())
 | 
	
		
			
				|  |  | -            );
 | 
	
		
			
				|  |  | -            if (similarityComparison != 0) {
 | 
	
		
			
				|  |  | -                return -similarityComparison; // 降序
 | 
	
		
			
				|  |  | +        // 1 排序
 | 
	
		
			
				|  |  | +        String[] contentPools = accountContentPoolConfigService.getContentPools(param.getAccountName());
 | 
	
		
			
				|  |  | +        Map<String, List<RankItem>> itemMap = new HashMap<>();
 | 
	
		
			
				|  |  | +        for (RankItem c : items) {
 | 
	
		
			
				|  |  | +            List<RankItem> data = itemMap.computeIfAbsent(c.getContent().getContentPoolType(), k -> new ArrayList<>());
 | 
	
		
			
				|  |  | +            data.add(c);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        for (Map.Entry<String, List<RankItem>> e : itemMap.entrySet()) {
 | 
	
		
			
				|  |  | +            if (StringUtils.equals(contentPools[1], e.getKey())) {
 | 
	
		
			
				|  |  | +                // 播放量排序
 | 
	
		
			
				|  |  | +                Collections.sort(e.getValue(), (o1, o2) -> -Double.compare(
 | 
	
		
			
				|  |  | +                        o1.getScore(ViewCountStrategy.class.getSimpleName()),
 | 
	
		
			
				|  |  | +                        o2.getScore(ViewCountStrategy.class.getSimpleName())));
 | 
	
		
			
				|  |  | +            } else {
 | 
	
		
			
				|  |  | +                // 相似排序
 | 
	
		
			
				|  |  | +                Collections.sort(e.getValue(), (o1, o2) -> -Double.compare(
 | 
	
		
			
				|  |  | +                        o1.getScore(SimilarityStrategy.class.getSimpleName()),
 | 
	
		
			
				|  |  | +                        o2.getScore(SimilarityStrategy.class.getSimpleName())));
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -            return Double.compare(
 | 
	
		
			
				|  |  | -                    o1.getScore(ViewCountStrategy.class.getSimpleName()),
 | 
	
		
			
				|  |  | -                    o2.getScore(ViewCountStrategy.class.getSimpleName())
 | 
	
		
			
				|  |  | -            );
 | 
	
		
			
				|  |  | -        });
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        log.info("RankItem sort {}", JSONUtils.toJson(items));
 | 
	
		
			
				|  |  | +        List<RankItem> sortedItems = new ArrayList<>();
 | 
	
		
			
				|  |  | +        for (String pool : contentPools) {
 | 
	
		
			
				|  |  | +            sortedItems.addAll(itemMap.get(pool));
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        List<Content> contents = CommonCollectionUtils.toList(sortedItems, RankItem::getContent);
 | 
	
		
			
				|  |  | +        log.info("Sort result {}", JSONUtils.toJson(contents));
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        List<Content> contents = CommonCollectionUtils.toList(items, RankItem::getContent);
 | 
	
		
			
				|  |  | -        // 1 相似去重
 | 
	
		
			
				|  |  | +        // 3 相似去重
 | 
	
		
			
				|  |  |          contents = deduplication(contents);
 | 
	
		
			
				|  |  |          log.info("Deduplication {}", JSONUtils.toJson(contents));
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        // 2 文章按照内容池分组
 | 
	
		
			
				|  |  | +        // 4 文章按照内容池分组
 | 
	
		
			
				|  |  |          Map<String, List<Content>> contentMap = new HashMap<>();
 | 
	
		
			
				|  |  |          for (Content c : contents) {
 | 
	
		
			
				|  |  |              List<Content> data = contentMap.computeIfAbsent(c.getContentPoolType(), k -> new ArrayList<>());
 | 
	
		
			
				|  |  |              data.add(c);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -        // 3 按位置选文章
 | 
	
		
			
				|  |  | +        log.info("ContentMap {}", JSONUtils.toJson(contentMap));
 | 
	
		
			
				|  |  | +        // 5 按位置选文章
 | 
	
		
			
				|  |  |          List<Content> result = new ArrayList<>();
 | 
	
		
			
				|  |  | -        String[] contentPools = accountContentPoolConfigService.getContentPools(param.getAccountName());
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          // 头
 | 
	
		
			
				|  |  |          List<Content> pool = contentMap.get(contentPools[0]);
 |