| 
					
				 | 
			
			
				@@ -1,7 +1,9 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 package com.tzld.piaoquan.recommend.server.service.rank.processor; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.tzld.piaoquan.recommend.server.model.Video; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.tzld.piaoquan.recommend.server.service.rank.RankParam; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.tzld.piaoquan.recommend.server.util.DateUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.tzld.piaoquan.recommend.server.util.FestiveUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.tzld.piaoquan.recommend.server.util.ProbabilityCalculator; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import lombok.extern.slf4j.Slf4j; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.apache.commons.collections4.CollectionUtils; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -9,11 +11,10 @@ import org.apache.commons.collections4.MapUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.apache.commons.lang3.StringUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.math.BigDecimal; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.time.LocalDate; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.time.LocalDateTime; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import java.util.ArrayList; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import java.util.HashMap; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import java.util.List; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import java.util.Map; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.time.temporal.ChronoUnit; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.util.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  * 提权处理器 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -60,7 +61,7 @@ public class RankProcessorBoost { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public static void boostByMergeCate(List<Video> rovList, Map<String, List<Map<String, String>>> rulesMap) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if (CollectionUtils.isEmpty(rovList) || MapUtils.isEmpty(rulesMap)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (CollectionUtils.isEmpty(rovList) || MapUtils.isEmpty(rulesMap)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -73,9 +74,8 @@ public class RankProcessorBoost { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             for (String mergeCate : video.getMergeCateList()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 double reduceCoefficient = RankProcessorBoost.parseReduceCoefficient(mergeCate, rulesMap); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 double originScore = video.getScore(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 video.setScore(originScore * reduceCoefficient); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                video.setSortScore(originScore * reduceCoefficient); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 video.getScoresMap().put("reduceCoefficient", reduceCoefficient); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -85,6 +85,60 @@ public class RankProcessorBoost { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public static void boostByFestive(RankParam param, List<Video> rovList, Set<String> festiveRootSessionIdTails) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (CollectionUtils.isEmpty(param.getAbExpCodes()) || !param.getAbExpCodes().contains("747")){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        String rootSessionId = param.getRootSessionId(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (StringUtils.isBlank(rootSessionId) || CollectionUtils.isEmpty(festiveRootSessionIdTails)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        String tail = rootSessionId.substring(rootSessionId.length() - 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (!festiveRootSessionIdTails.contains(tail)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        String format = "yyyy-MM-dd"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        int nowHour = LocalDateTime.now().getHour(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        LocalDate now = LocalDate.now(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        for (Video video : rovList) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            String festiveName = video.getOtherParam().getOrDefault("fes_name", video.getOtherParam().getOrDefault("festive_label2", "")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (StringUtils.isBlank(festiveName)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                continue; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            List<String> festiveDateStrList = FestiveUtil.getDateByFestiveName(festiveName); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (CollectionUtils.isEmpty(festiveDateStrList)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                continue; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            for (String festiveDateStr : festiveDateStrList) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                LocalDate festiveDate = DateUtils.convertStrToLocalDate(festiveDateStr, format); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                // 计算今天与节日相差的天数,如果节日时间在之后,返回负数 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                long diffDay = ChronoUnit.DAYS.between(festiveDate, now); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (diffDay == 0 && nowHour >= 10) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    double reduceCoefficient = 0.2; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    double originScore = video.getScore(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    video.setScore(originScore * reduceCoefficient); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    video.setSortScore(originScore * reduceCoefficient); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    video.getScoresMap().put("festiveReduceCoefficient", reduceCoefficient); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } else if (diffDay >= 1 && diffDay <= 2) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    double reduceCoefficient = 0.2; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    double originScore = video.getScore(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    video.setScore(originScore * reduceCoefficient); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    video.setSortScore(originScore * reduceCoefficient); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    video.getScoresMap().put("festiveReduceCoefficient", reduceCoefficient); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        rovList.sort((o1, o2) -> Double.compare(o2.getSortScore(), o1.getSortScore())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private static double parseReduceCoefficient(String mergeCate2, Map<String, List<Map<String, String>>> reduceConfigMap) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (StringUtils.isBlank(mergeCate2) || MapUtils.isEmpty(reduceConfigMap)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             return 1d; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -102,7 +156,6 @@ public class RankProcessorBoost { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return 1d; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * 当前小时是否需要降权 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      */ 
			 |