| 
					
				 | 
			
			
				@@ -0,0 +1,61 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+package com.tzld.longarticle.recommend.server.service.score.strategy; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.tzld.longarticle.recommend.server.model.Content; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.tzld.longarticle.recommend.server.model.ContentHisPublishArticle; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.tzld.longarticle.recommend.server.service.AccountContentPoolConfigService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.tzld.longarticle.recommend.server.service.AccountIndexAvgViewCountService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+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.MathUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import lombok.extern.slf4j.Slf4j; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.springframework.beans.factory.annotation.Autowired; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.springframework.stereotype.Component; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.util.ArrayList; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.util.List; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+@Component 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+@Slf4j 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+public class ViewCountRateStrategy implements ScoreStrategy { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    AccountIndexAvgViewCountService accountIndexAvgViewCountService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private AccountContentPoolConfigService accountContentPoolConfigService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public List<Score> score(ScoreParam param) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<Score> scores = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        for (Content content: param.getContents()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            String[] contentPools = accountContentPoolConfigService.getContentPools(param.getAccountName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (!contentPools[0].equals(content.getContentPoolType())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                continue; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            double firstAvgViewCount = accountIndexAvgViewCountService.getAvgReadCount(param.getGhId(), 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            double showViewCountSum = 0D; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            double avgViewCountSum = 0D; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            for (ContentHisPublishArticle hisItem : content.getHisPublishArticleList()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (hisItem.isInnerAccount() && hisItem.getShowViewCount() > 0 && hisItem.getAvgViewCount() > 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    showViewCountSum += hisItem.getShowViewCount(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    avgViewCountSum += hisItem.getAvgViewCount(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            double viewCountRate = 0D; // 设置默认值 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (avgViewCountSum > 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                viewCountRate = showViewCountSum / avgViewCountSum; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            double viewCountRateW = MathUtils.sigmoid(avgViewCountSum, 0.0005, firstAvgViewCount); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            double viewCountRateScore = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (viewCountRate > 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                viewCountRateScore = (Math.min(viewCountRate, 5) - 1D) * viewCountRateW; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            Score score = new Score(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            score.setStrategy(this); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            score.setContentId(content.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            score.setScore(viewCountRateScore); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            scores.add(score); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return scores; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 |