| 
					
				 | 
			
			
				@@ -2,8 +2,11 @@ package com.tzld.piaoquan.recommend.server.service.rank.processor; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.tzld.piaoquan.recommend.server.model.Video; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.apache.commons.collections4.CollectionUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.apache.commons.lang3.StringUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.math.BigDecimal; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.time.LocalDateTime; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.time.format.DateTimeFormatter; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.util.HashMap; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.util.List; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.util.Map; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -19,26 +22,60 @@ public class RankProcessorBoost { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (CollectionUtils.isEmpty(rovList) || rulesMap == null || rulesMap.isEmpty()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        Map<String, Double> densityRules = new HashMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Map<String, String> densityRules = new HashMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Map<String, String> dateMap = new HashMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         for (Map.Entry<String, Map<String, String>> entry : rulesMap.entrySet()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             String key = entry.getKey(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             Map<String, String> value = entry.getValue(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             if (value.containsKey("boost")) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                densityRules.put(key, Double.valueOf(value.get("boost"))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                densityRules.put(key, value.get("boost")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (value.containsKey("boost_date")) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                dateMap.put(key, value.get("boost_date")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        for (Map.Entry<String, Double> entry : densityRules.entrySet()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            rovList.stream().filter(video -> video.getTags().contains(entry.getKey())) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    .forEach(video -> video.setSortScore( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                            BigDecimal.valueOf(video.getSortScore()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                                    .multiply(BigDecimal.valueOf(entry.getValue())) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                                    .doubleValue())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        for (Map.Entry<String, String> entry : densityRules.entrySet()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            String dateRange = dateMap.get(entry.getKey()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (StringUtils.isNotBlank(dateRange)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                String[] dateRangeArray = dateRange.split("-"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (dateRangeArray.length != 2) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    continue; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                String start = dateRangeArray[0]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                String end = dateRangeArray[1]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                String nowHour = DateTimeFormatter.ofPattern("yyyyMMddHH").format(LocalDateTime.now()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (!ifFilter(start, end, nowHour)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    continue; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                String value = entry.getValue(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                String[] boostArray = value.split("-"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (boostArray.length != 2) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    continue; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                double min = Double.parseDouble(boostArray[0]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                double max = Double.parseDouble(boostArray[1]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                // 生成min到max之间的随机数 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                double randomValue = min + (Math.random() * (max - min)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                rovList.stream().filter(video -> video.getTags().contains(entry.getKey())) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        .forEach(video -> video.setSortScore( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                BigDecimal.valueOf(video.getSortScore()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                        .multiply(BigDecimal.valueOf(randomValue)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                        .doubleValue())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } catch (Exception ignored) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         rovList.sort((o1, o2) -> Double.compare(o2.getSortScore(), o1.getSortScore())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public static boolean ifFilter(String start, String end, String dateHour) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (StringUtils.isBlank(start) || StringUtils.isBlank(end) || StringUtils.isBlank(dateHour)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return dateHour.compareTo(start) >= 0 && dateHour.compareTo(end) < 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 |