| 
					
				 | 
			
			
				@@ -3,27 +3,33 @@ package com.tzld.piaoquan.recommend.server.service; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.alibaba.fastjson.JSONObject; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.aliyun.odps.data.Record; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.tzld.piaoquan.recommend.server.common.base.Constant; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.tzld.piaoquan.recommend.server.util.ODPSManager; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.tzld.piaoquan.recommend.server.service.odps.ODPSManager; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import lombok.extern.slf4j.Slf4j; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.springframework.beans.factory.annotation.Autowired; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.data.redis.core.RedisTemplate; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.springframework.scheduling.annotation.Scheduled; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.stereotype.Component; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.util.CollectionUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import javax.annotation.Resource; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.util.List; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.util.concurrent.TimeUnit; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.util.stream.Collectors; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  * @author sunxy 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 @Component 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+@Slf4j 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 public class SyncFlowPoolRecentTopVideoJob { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    @Resource 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private ODPSManager odpsManager; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    @Resource 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    private RedisTemplate<String, Object> redisTemplate; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private RedisTemplate<String, String> redisTemplate; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // 每个小时的20分执行 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Scheduled(cron = "0 20 * * * ? ") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public void syncFlowPoolRecentTopVideo() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         // 执行 ODPS Sql,获取数据 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         List<Long> videoIds = queryTopVideoIdsByLast6Hour(100); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -31,12 +37,13 @@ public class SyncFlowPoolRecentTopVideoJob { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         // 将数据写入 Redis 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        redisTemplate.opsForValue().set(Constant.FLOW_POOL_RECENT_TOP_VIDEO_REDIS_KEY, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                JSONObject.toJSONString(videoIds)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        redisTemplate.opsForValue().set(Constant.FLOW_POOL_LAST_24_HOUR_VIDEO_REDIS_KEY, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                JSONObject.toJSONString(videoIds), 2, TimeUnit.DAYS); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private List<Long> queryTopVideoIdsByLast6Hour(Integer topNum) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         String sql = "SELECT videoid FROM loghubods.flow_pool_video_info_per_hour " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                "WHERE dt = '" + odpsManager.getNowHour() + "' " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 "ORDER BY 1d_return_cnt DESC LIMIT " + topNum + ";"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         List<Record> records = odpsManager.query(sql); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (records == null || records.size() == 0) { 
			 |