Authored by hugufei

fix bug

1 package com.yoho.search.service.scene.pages; 1 package com.yoho.search.service.scene.pages;
2 2
  3 +import com.alibaba.fastjson.JSONObject;
3 import com.yoho.search.base.utils.SearchPageIdDefine; 4 import com.yoho.search.base.utils.SearchPageIdDefine;
4 import com.yoho.search.common.utils.SearchApiResultUtils; 5 import com.yoho.search.common.utils.SearchApiResultUtils;
5 import com.yoho.search.models.SearchApiResult; 6 import com.yoho.search.models.SearchApiResult;
6 import com.yoho.search.service.scene.pages.entrance.ProductListSwitchService; 7 import com.yoho.search.service.scene.pages.entrance.ProductListSwitchService;
  8 +import com.yoho.search.service.scene.pages.selections.PageAggregationHelper;
7 import com.yoho.search.service.scene.pages.selections.PageSelectionsBrandsService; 9 import com.yoho.search.service.scene.pages.selections.PageSelectionsBrandsService;
8 import com.yoho.search.service.scene.pages.selections.PageSelectionsService; 10 import com.yoho.search.service.scene.pages.selections.PageSelectionsService;
9 import org.slf4j.Logger; 11 import org.slf4j.Logger;
@@ -12,6 +14,9 @@ import org.springframework.beans.factory.annotation.Autowired; @@ -12,6 +14,9 @@ import org.springframework.beans.factory.annotation.Autowired;
12 import org.springframework.stereotype.Service; 14 import org.springframework.stereotype.Service;
13 15
14 import java.util.Map; 16 import java.util.Map;
  17 +import java.util.concurrent.CompletableFuture;
  18 +import java.util.concurrent.ExecutorService;
  19 +import java.util.concurrent.Executors;
15 20
16 @Service 21 @Service
17 public class CommonPageSceneService extends AbstractPageSceneService { 22 public class CommonPageSceneService extends AbstractPageSceneService {
@@ -24,6 +29,10 @@ public class CommonPageSceneService extends AbstractPageSceneService { @@ -24,6 +29,10 @@ public class CommonPageSceneService extends AbstractPageSceneService {
24 private PageSelectionsService pageSelectionsService; 29 private PageSelectionsService pageSelectionsService;
25 @Autowired 30 @Autowired
26 private PageSelectionsBrandsService scenePageSelectionsBrandsService; 31 private PageSelectionsBrandsService scenePageSelectionsBrandsService;
  32 + @Autowired
  33 + private PageAggregationHelper pageAggregationHelper;
  34 +
  35 + private ExecutorService executorService = Executors.newFixedThreadPool(20);
27 36
28 @Override 37 @Override
29 public String pageId() { 38 public String pageId() {
@@ -41,7 +50,14 @@ public class CommonPageSceneService extends AbstractPageSceneService { @@ -41,7 +50,14 @@ public class CommonPageSceneService extends AbstractPageSceneService {
41 // 1、添加默认参数 50 // 1、添加默认参数
42 this.addParamsToParamMap(paramMap); 51 this.addParamsToParamMap(paramMap);
43 // 2、返回商品列表 52 // 2、返回商品列表
44 - return sceneProductListService.productList(paramMap); 53 + CompletableFuture<SearchApiResult> productListFuture = CompletableFuture.supplyAsync(() -> sceneProductListService.productList(this.newParamMap(paramMap)), executorService);
  54 + CompletableFuture<SearchApiResult> customizeTagFuture = CompletableFuture.supplyAsync(() -> pageAggregationHelper.sceneAggCustomizeTag(this.newParamMap(paramMap)),
  55 + executorService);
  56 + SearchApiResult productList = productListFuture.get();
  57 + SearchApiResult customizeTags = customizeTagFuture.get();
  58 + JSONObject jsonObject = (JSONObject) productList.getData();
  59 + jsonObject.put(CUSTOMIZE_TAG_LIST, customizeTags.getData());
  60 + return productList;
45 } catch (Exception e) { 61 } catch (Exception e) {
46 return SearchApiResultUtils.errorSearchApiResult(logger, paramMap, e); 62 return SearchApiResultUtils.errorSearchApiResult(logger, paramMap, e);
47 } 63 }
@@ -44,7 +44,7 @@ public class SortPageSceneService extends AbstractPageSceneService { @@ -44,7 +44,7 @@ public class SortPageSceneService extends AbstractPageSceneService {
44 paramMap.put(SearchRequestParams.PARAM_SEARCH_CONTAIN_GLOBAL, "Y");// 包含全球购 44 paramMap.put(SearchRequestParams.PARAM_SEARCH_CONTAIN_GLOBAL, "Y");// 包含全球购
45 } 45 }
46 46
47 - private ExecutorService executorService = Executors.newFixedThreadPool(100); 47 + private ExecutorService executorService = Executors.newFixedThreadPool(20);
48 48
49 private boolean checkParam(Map<String, String> paramMap) { 49 private boolean checkParam(Map<String, String> paramMap) {
50 if (StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_MAXSORT))) { 50 if (StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_MAXSORT))) {