| 
					
				 | 
			
			
				@@ -1,18 +1,19 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-package com.tzld.longarticle.recommend.server.service.filter.strategy; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+package com.tzld.longarticle.recommend.server.service.score.strategy; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.google.common.reflect.TypeToken; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.tzld.longarticle.recommend.server.model.Content; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.tzld.longarticle.recommend.server.repository.entity.crawler.ArticlePreDistributeAccount; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.tzld.longarticle.recommend.server.repository.crawler.ArticlePreDistributeAccountRepository; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.tzld.longarticle.recommend.server.repository.entity.crawler.ArticlePreDistributeAccount; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.tzld.longarticle.recommend.server.service.AccountContentPoolConfigService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.tzld.longarticle.recommend.server.service.filter.FilterParam; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.tzld.longarticle.recommend.server.service.filter.FilterResult; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.tzld.longarticle.recommend.server.service.filter.FilterStrategy; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+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.JSONUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import lombok.extern.slf4j.Slf4j; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import org.apache.commons.lang3.StringUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.beans.factory.annotation.Autowired; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.stereotype.Component; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.springframework.util.StringUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.util.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -21,25 +22,27 @@ import java.util.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 @Component 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 @Slf4j 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-public class AccountPreDistributeStrategy implements FilterStrategy { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+public class AccountPreDistributeStrategy implements ScoreStrategy { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private AccountContentPoolConfigService accountContentPoolConfigService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private ArticlePreDistributeAccountRepository articlePreDistributeAccountRepository; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @ApolloJsonValue("${accountPreDistributeWeightConfig:{}}") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private Map<String, Integer> accountPreDistributeWeightMap; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    public FilterResult filter(FilterParam param) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public List<Score> score(ScoreParam param) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         long start = System.currentTimeMillis(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        FilterResult filterResult = new FilterResult(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        List<String> result = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<Score> scores = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         List<Content> contents = param.getContents(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        List<Content> filterContents = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         Set<String> articles = new HashSet<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         String[] pools = accountContentPoolConfigService.getContentPools(param.getAccountName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (pools.length >= 3) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 ArticlePreDistributeAccount optional = articlePreDistributeAccountRepository.findFirstByGhIdOrderByDateDesc(param.getGhId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                if (optional != null && StringUtils.isNotEmpty(optional.getArticleList())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (optional != null && StringUtils.hasText(optional.getArticleList())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     List<String[]> list = JSONUtils.fromJson(optional.getArticleList(), new TypeToken<List<String[]>>() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     }, Collections.emptyList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     for (String[] s : list) { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -50,20 +53,32 @@ public class AccountPreDistributeStrategy implements FilterStrategy { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 e.printStackTrace(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Integer weight = getPreDistributeWeight(param.getAccountName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         for (Content content : contents) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if (StringUtils.equals(pools[2], content.getContentPoolType())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            Score score = new Score(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            score.setStrategy(this); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (pools[2].equals(content.getContentPoolType())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 if (articles.contains(content.getCrawlerChannelContentId())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    result.add(content.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    score.setContentId(content.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    score.setScore(weight); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                result.add(content.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                score.setContentId(content.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                score.setScore(weight); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (StringUtils.hasText(score.getContentId())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                scores.add(score); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        filterResult.setContentIds(result); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        filterResult.setFilterContent(filterContents); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         log.info("AccountPreDistributeStrategy cost:{}", System.currentTimeMillis() - start); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        return filterResult; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return scores; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public Integer getPreDistributeWeight(String accountName) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (accountPreDistributeWeightMap.containsKey(accountName)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return accountPreDistributeWeightMap.get(accountName); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return accountPreDistributeWeightMap.get("default"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 |