| 
					
				 | 
			
			
				@@ -9,20 +9,19 @@ import com.tzld.longarticle.recommend.server.service.AccountContentPoolConfigSer 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.tzld.longarticle.recommend.server.service.score.Score; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.tzld.longarticle.recommend.server.service.score.ScoreParam; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.tzld.longarticle.recommend.server.service.score.ScoreStrategy; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.tzld.longarticle.recommend.server.util.DateUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import lombok.extern.slf4j.Slf4j; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.beans.factory.annotation.Autowired; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.stereotype.Component; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.util.CollectionUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import java.util.ArrayList; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import java.util.List; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import java.util.Map; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.util.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.util.stream.Collectors; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 @Component 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 @Slf4j 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-public class ColdStartDecreaseStrategy implements ScoreStrategy { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+public class FlowCtlDecreaseStrategy implements ScoreStrategy { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private AccountContentPoolConfigService accountContentPoolConfigService; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -30,12 +29,12 @@ public class ColdStartDecreaseStrategy implements ScoreStrategy { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private PublishSortLogRepository publishSortLogRepository; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     // 账号score减少 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    @ApolloJsonValue("${accountColdStartScoreDecreaseConfig:{\"default\":-100}}") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    private Map<String, Integer> accountColdStartScoreDecreaseMap; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @ApolloJsonValue("${accountColdStartScoreDecreaseConfig:{\"default\":{\"3\":-100,\"1\":-100,\"2\":-100}}}") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private Map<String, Map<String, Integer>> accountColdStartScoreDecreaseMap; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     // 计算阅读均值base 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    @ApolloJsonValue("${totalAvgReadCountBase:{\"default\":100}}") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    private Map<String, Integer> totalAvgReadCountBaseMap; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @ApolloJsonValue("${totalAvgReadCountBase:{\"default\":{\"3\":100,\"1\":100,\"2\":100}}}") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private Map<String, Map<String, Integer>> totalAvgReadCountBaseMap; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public List<Score> score(ScoreParam param) { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -43,16 +42,12 @@ public class ColdStartDecreaseStrategy implements ScoreStrategy { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (CollectionUtils.isEmpty(param.getContents())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             return scores; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        String[] contentPools = accountContentPoolConfigService.getContentPools(param.getAccountName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        List<String> crawlerChannelContentIds = param.getContents().stream().map(Content::getCrawlerChannelContentId).collect(Collectors.toList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        // 获取历史已发布内容 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        List<PublishSortLog> hisPublishContentList = publishSortLogRepository.findByCrawlerChannelContentIdIn(crawlerChannelContentIds); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        Map<String, List<PublishSortLog>> hisPublishedContentMap = hisPublishContentList.stream().collect(Collectors.groupingBy(PublishSortLog::getCrawlerChannelContentId)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        String dateStr = DateUtils.getCurrentDateStr("yyyy-MM-dd"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<String> titles = param.getContents().stream().map(Content::getTitle).collect(Collectors.toList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 获取今日已发布内容 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<PublishSortLog> hisPublishContentList = publishSortLogRepository.findByDateStrAndTitleIn(dateStr, titles); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Map<String, List<PublishSortLog>> hisPublishedContentMap = hisPublishContentList.stream().collect(Collectors.groupingBy(PublishSortLog::getTitle)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         for (Content content : param.getContents()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            // 仅判断3-8条 冷启层 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if (!contentPools[2].equals(content.getContentPoolType())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                continue; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             Score score = new Score(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             score.setStrategy(this); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             score.setContentId(content.getId()); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -69,31 +64,44 @@ public class ColdStartDecreaseStrategy implements ScoreStrategy { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private Integer getContentScore(String accountName, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                     Map<String, List<PublishSortLog>> hisPublishedContentMap, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                     Content content) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        Integer weight = getColdStartScoreDecreaseWeight(accountName); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        Integer totalAvgReadCountBase = getAvgReadCountBase(accountName); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if (hisPublishedContentMap.containsKey(content.getCrawlerChannelContentId())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            List<PublishSortLog> publishContents = hisPublishedContentMap.get(content.getCrawlerChannelContentId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            double sumViewCount = publishContents.stream().mapToDouble(PublishSortLog::getIndexAvgCount).sum(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        String[] contentPools = accountContentPoolConfigService.getContentPools(accountName); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        int index = 3; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        for (int i = 0; i < contentPools.length; i++) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (contentPools[i].equals(content.getContentPoolType())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                index = i + 1; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Map<String, Integer> indexWeight = getColdStartScoreDecreaseWeight(accountName); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Map<String, Integer> indexTotalAvgReadCountBase = getAvgReadCountBase(accountName); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (Objects.isNull(indexWeight) || Objects.isNull(indexTotalAvgReadCountBase)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (hisPublishedContentMap.containsKey(content.getTitle())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            List<PublishSortLog> publishContents = hisPublishedContentMap.get(content.getTitle()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            int finalIndex = index; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            double sumViewCount = publishContents.stream().filter(o -> (o.getIndex() / 3) == (finalIndex / 3)).mapToDouble(PublishSortLog::getIndexAvgCount).sum(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             int hisViewCountSum = content.getHisPublishArticleList().stream().filter(ContentHisPublishArticle::isInnerAccount) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     .mapToInt(ContentHisPublishArticle::getAvgViewCount).sum(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if ((sumViewCount + hisViewCountSum) > totalAvgReadCountBase) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                return weight; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if ((sumViewCount + hisViewCountSum) > indexTotalAvgReadCountBase.get(String.valueOf(index))) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                return indexWeight.get(String.valueOf(index)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    public Integer getColdStartScoreDecreaseWeight(String accountName) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public Map<String, Integer> getColdStartScoreDecreaseWeight(String accountName) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (accountColdStartScoreDecreaseMap.containsKey(accountName)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             return accountColdStartScoreDecreaseMap.get(accountName); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return accountColdStartScoreDecreaseMap.get("default"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    public Integer getAvgReadCountBase(String accountName) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public Map<String, Integer> getAvgReadCountBase(String accountName) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (totalAvgReadCountBaseMap.containsKey(accountName)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             return totalAvgReadCountBaseMap.get(accountName); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return totalAvgReadCountBaseMap.get("default"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 |