|
|
@ -13,9 +13,14 @@ import org.springframework.stereotype.Service;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
|
|
|
|
|
import java.util.concurrent.ExecutionException;
|
|
|
|
|
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
|
|
|
|
|
import java.util.concurrent.Executors;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 热搜服务实现
|
|
|
|
* 热搜服务实现
|
|
|
|
|
|
|
|
*
|
|
|
|
* @author xiejs
|
|
|
|
* @author xiejs
|
|
|
|
* @since 2022-01-22
|
|
|
|
* @since 2022-01-22
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -45,25 +50,52 @@ public class TopSearchServiceImpl implements TopSearchService {
|
|
|
|
private ApiTopsearchWeiboService apiTopsearchWeiboService;
|
|
|
|
private ApiTopsearchWeiboService apiTopsearchWeiboService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private ExecutorService executor = Executors.newFixedThreadPool(5);
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Map<String, List> getAllTopSearch() {
|
|
|
|
public Map<String, List> getAllTopSearch() throws ExecutionException, InterruptedException {
|
|
|
|
|
|
|
|
long start = System.currentTimeMillis();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CompletableFuture<List<ApiTopsearchAllnetwork>> future1 = CompletableFuture.supplyAsync(() -> {
|
|
|
|
//获取全网热搜
|
|
|
|
//获取全网热搜
|
|
|
|
List<ApiTopsearchAllnetwork> allnetworkList = tianXingTopsearchAllnetworkFactory.topSearchApi();
|
|
|
|
return tianXingTopsearchAllnetworkFactory.topSearchApi();
|
|
|
|
|
|
|
|
}, executor);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CompletableFuture<List<ApiTopsearchWeibo>> future2 = CompletableFuture.supplyAsync(() -> {
|
|
|
|
//获取微博热搜
|
|
|
|
//获取微博热搜
|
|
|
|
List<ApiTopsearchWeibo> weiboList = tianXingTopsearchWeiboFactory.topSearchApi();
|
|
|
|
return tianXingTopsearchWeiboFactory.topSearchApi();
|
|
|
|
|
|
|
|
}, executor);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CompletableFuture<List<ApiTopsearchDouyin>> future3 = CompletableFuture.supplyAsync(() -> {
|
|
|
|
//获取抖音热搜
|
|
|
|
//获取抖音热搜
|
|
|
|
List<ApiTopsearchDouyin> douyinList = tianXingTopsearchDouyinFactory.topSearchApi();
|
|
|
|
return tianXingTopsearchDouyinFactory.topSearchApi();
|
|
|
|
|
|
|
|
}, executor);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CompletableFuture<List<ApiTopsearchWechat>> future4 = CompletableFuture.supplyAsync(() -> {
|
|
|
|
//获取微信热搜
|
|
|
|
//获取微信热搜
|
|
|
|
List<ApiTopsearchWechat> wechatList = tianXingTopsearchWechatFactory.topSearchApi();
|
|
|
|
return tianXingTopsearchWechatFactory.topSearchApi();
|
|
|
|
|
|
|
|
}, executor);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CompletableFuture<List<ApiTopsearchBaidu>> future5 = CompletableFuture.supplyAsync(() -> {
|
|
|
|
//获取百度热搜
|
|
|
|
//获取百度热搜
|
|
|
|
List<ApiTopsearchBaidu> baiduList = tianXingTopsearchBaiduFactory.topSearchApi();
|
|
|
|
return tianXingTopsearchBaiduFactory.topSearchApi();
|
|
|
|
|
|
|
|
}, executor);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 必须等待所有异步任务执行完成才能返回结果
|
|
|
|
|
|
|
|
CompletableFuture.allOf(future1, future2, future3, future4, future5).get();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
long end = System.currentTimeMillis();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
long count = end - start;
|
|
|
|
|
|
|
|
log.info("异步获取热搜榜耗费时间:{}ms",count);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, List> listHashMap = new HashMap<>();
|
|
|
|
Map<String, List> listHashMap = new HashMap<>();
|
|
|
|
listHashMap.put("allnetworkList", allnetworkList);
|
|
|
|
listHashMap.put("allnetworkList", future1.get());
|
|
|
|
listHashMap.put("wechatList", wechatList);
|
|
|
|
listHashMap.put("wechatList", future2.get());
|
|
|
|
listHashMap.put("baiduList", baiduList);
|
|
|
|
listHashMap.put("baiduList", future3.get());
|
|
|
|
listHashMap.put("weiboList", weiboList);
|
|
|
|
listHashMap.put("weiboList", future4.get());
|
|
|
|
listHashMap.put("douyinList", douyinList);
|
|
|
|
listHashMap.put("douyinList", future5.get());
|
|
|
|
return listHashMap;
|
|
|
|
return listHashMap;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|