|
|
package com.yoho.search.service.scene;
|
|
|
|
|
|
import java.util.Map;
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
import java.util.concurrent.Executors;
|
|
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.yoho.search.base.utils.SearchPageIdDefine;
|
|
|
import com.yoho.search.models.SearchApiResult;
|
...
|
...
|
@@ -22,136 +11,137 @@ import com.yoho.search.service.scene.common.AbstractSceneService; |
|
|
import com.yoho.search.service.scene.common.CommonSceneProductListService;
|
|
|
import com.yoho.search.service.scene.common.SceneSelectionsService;
|
|
|
import com.yoho.search.service.scene.recall.SortRecallSceneService;
|
|
|
import com.yoho.search.service.service.IAggRecommendService;
|
|
|
import com.yoho.search.service.service.IProductIndexService;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.Map;
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
import java.util.concurrent.Executors;
|
|
|
|
|
|
@Service
|
|
|
public class SortSceneService extends AbstractSceneService {
|
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(SortSceneService.class);
|
|
|
private static final Logger logger = LoggerFactory.getLogger(SortSceneService.class);
|
|
|
|
|
|
@Autowired
|
|
|
private CommonSceneProductListService sceneProductListService;
|
|
|
@Autowired
|
|
|
private SceneSelectionsService sceneSelectionsService;
|
|
|
@Autowired
|
|
|
private SearchCommonHelper searchCommonHelper;
|
|
|
@Autowired
|
|
|
private IProductIndexService productIndexService;
|
|
|
@Autowired
|
|
|
private IAggRecommendService aggRecommendService;
|
|
|
@Autowired
|
|
|
private SortRecallSceneService sortRecallSceneService;
|
|
|
@Autowired
|
|
|
private SearchDynamicConfigService searchDynamicConfigService;
|
|
|
@Autowired
|
|
|
private SceneAggregationsHelper sceneAggregationsHelper;
|
|
|
@Autowired
|
|
|
private CommonSceneProductListService sceneProductListService;
|
|
|
@Autowired
|
|
|
private SceneSelectionsService sceneSelectionsService;
|
|
|
@Autowired
|
|
|
private SearchCommonHelper searchCommonHelper;
|
|
|
@Autowired
|
|
|
private SortRecallSceneService sortRecallSceneService;
|
|
|
@Autowired
|
|
|
private SearchDynamicConfigService searchDynamicConfigService;
|
|
|
@Autowired
|
|
|
private SceneAggregationsHelper sceneAggregationsHelper;
|
|
|
|
|
|
@Override
|
|
|
public String pageId() {
|
|
|
return SearchPageIdDefine.PAGE_ID_SORT;
|
|
|
}
|
|
|
@Override
|
|
|
public String pageId() {
|
|
|
return SearchPageIdDefine.PAGE_ID_SORT;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void addParamsToParamMap(Map<String, String> paramMap) {
|
|
|
super.addDefaultParamsToParamMap(paramMap);
|
|
|
paramMap.put(SearchRequestParams.PARAM_SEARCH_CONTAIN_GLOBAL, "Y");// 包含全球购
|
|
|
}
|
|
|
@Override
|
|
|
public void addParamsToParamMap(Map<String, String> paramMap) {
|
|
|
super.addDefaultParamsToParamMap(paramMap);
|
|
|
paramMap.put(SearchRequestParams.PARAM_SEARCH_CONTAIN_GLOBAL, "Y");// 包含全球购
|
|
|
}
|
|
|
|
|
|
private ExecutorService executorService = Executors.newFixedThreadPool(100);
|
|
|
private ExecutorService executorService = Executors.newFixedThreadPool(100);
|
|
|
|
|
|
private boolean checkParam(Map<String, String> paramMap) {
|
|
|
if (StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_MAXSORT))) {
|
|
|
return true;
|
|
|
}
|
|
|
if (StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_MIDDLESORT))) {
|
|
|
return true;
|
|
|
}
|
|
|
if (StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_SMALLSORT))) {
|
|
|
return true;
|
|
|
}
|
|
|
if (StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_COMMONSORT))) {
|
|
|
return true;
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
private boolean checkParam(Map<String, String> paramMap) {
|
|
|
if (StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_MAXSORT))) {
|
|
|
return true;
|
|
|
}
|
|
|
if (StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_MIDDLESORT))) {
|
|
|
return true;
|
|
|
}
|
|
|
if (StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_SMALLSORT))) {
|
|
|
return true;
|
|
|
}
|
|
|
if (StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_COMMONSORT))) {
|
|
|
return true;
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @特殊参数:
|
|
|
* @1、paramNum-获取规则数量的接口
|
|
|
* @2、firstProductSkn-第一个展示的skn
|
|
|
*/
|
|
|
@Override
|
|
|
public SearchApiResult productList(Map<String, String> paramMap) {
|
|
|
try {
|
|
|
// 0、必传品类相关参数
|
|
|
if (!this.checkParam(paramMap)) {
|
|
|
return new SearchApiResult().setCode(400).setMessage("请传品类相关参数");
|
|
|
}
|
|
|
// 1、添加默认参数
|
|
|
this.addParamsToParamMap(paramMap);
|
|
|
CompletableFuture<SearchApiResult> productListFuture = null;
|
|
|
// 2、获取商品列表-是否使用召回策略
|
|
|
if (goToRecall(paramMap)) {
|
|
|
productListFuture = CompletableFuture.supplyAsync(() -> sortRecallSceneService.recallProductList(this.newParamMap(paramMap)), executorService);
|
|
|
} else {
|
|
|
productListFuture = CompletableFuture.supplyAsync(() -> sceneProductListService.productList(this.newParamMap(paramMap)), executorService);
|
|
|
}
|
|
|
// 3、获取聚合结果
|
|
|
CompletableFuture<SearchApiResult> standardsFuture = CompletableFuture.supplyAsync(() -> sceneAggregationsHelper.sceneAggStandard(this.newParamMap(paramMap)),
|
|
|
executorService);
|
|
|
CompletableFuture<SearchApiResult> customizeTagFuture = CompletableFuture.supplyAsync(() -> sceneAggregationsHelper.sceneAggCustomizeTag(this.newParamMap(paramMap)),
|
|
|
executorService);
|
|
|
CompletableFuture<SearchApiResult> promotionsFuture = CompletableFuture.supplyAsync(() -> sceneAggregationsHelper.sceneAggPromotion(this.newParamMap(paramMap)),
|
|
|
executorService);
|
|
|
// 4、组合结果
|
|
|
SearchApiResult productList = productListFuture.get();
|
|
|
SearchApiResult standards = standardsFuture.get();
|
|
|
SearchApiResult customizeTags = customizeTagFuture.get();
|
|
|
SearchApiResult promotions = promotionsFuture.get();
|
|
|
JSONObject jsonObject = (JSONObject) productList.getData();
|
|
|
jsonObject.put(STANDARD, standards.getData());
|
|
|
jsonObject.put(CUSTOMIZE_TAG_LIST, customizeTags.getData());
|
|
|
jsonObject.put(RECOMMEND_PROMOTION_LIST, sceneAggregationsHelper.subRecommendPromotions(promotions.getData(), this.getPage(paramMap), 1));
|
|
|
return productList;
|
|
|
} catch (Exception e) {
|
|
|
logger.error(e.getMessage(), e);
|
|
|
return new SearchApiResult().setData(null).setMessage("SortProductList Exception").setCode(500);
|
|
|
}
|
|
|
}
|
|
|
/**
|
|
|
* @特殊参数:
|
|
|
* @1、paramNum-获取规则数量的接口
|
|
|
* @2、firstProductSkn-第一个展示的skn
|
|
|
*/
|
|
|
@Override
|
|
|
public SearchApiResult productList(Map<String, String> paramMap) {
|
|
|
try {
|
|
|
// 0、必传品类相关参数
|
|
|
if (!this.checkParam(paramMap)) {
|
|
|
return new SearchApiResult().setCode(400).setMessage("请传品类相关参数");
|
|
|
}
|
|
|
// 1、添加默认参数
|
|
|
this.addParamsToParamMap(paramMap);
|
|
|
CompletableFuture<SearchApiResult> productListFuture = null;
|
|
|
// 2、获取商品列表-是否使用召回策略
|
|
|
if (goToRecall(paramMap)) {
|
|
|
productListFuture = CompletableFuture.supplyAsync(() -> sortRecallSceneService.recallProductList(this.newParamMap(paramMap)), executorService);
|
|
|
} else {
|
|
|
productListFuture = CompletableFuture.supplyAsync(() -> sceneProductListService.productList(this.newParamMap(paramMap)), executorService);
|
|
|
}
|
|
|
// 3、获取聚合结果
|
|
|
CompletableFuture<SearchApiResult> standardsFuture = CompletableFuture.supplyAsync(() -> sceneAggregationsHelper.sceneAggStandard(this.newParamMap(paramMap)),
|
|
|
executorService);
|
|
|
CompletableFuture<SearchApiResult> customizeTagFuture = CompletableFuture.supplyAsync(() -> sceneAggregationsHelper.sceneAggCustomizeTag(this.newParamMap(paramMap)),
|
|
|
executorService);
|
|
|
CompletableFuture<SearchApiResult> promotionsFuture = CompletableFuture.supplyAsync(() -> sceneAggregationsHelper.sceneAggPromotion(this.newParamMap(paramMap)),
|
|
|
executorService);
|
|
|
// 4、组合结果
|
|
|
SearchApiResult productList = productListFuture.get();
|
|
|
SearchApiResult standards = standardsFuture.get();
|
|
|
SearchApiResult customizeTags = customizeTagFuture.get();
|
|
|
SearchApiResult promotions = promotionsFuture.get();
|
|
|
JSONObject jsonObject = (JSONObject) productList.getData();
|
|
|
jsonObject.put(STANDARD, standards.getData());
|
|
|
jsonObject.put(CUSTOMIZE_TAG_LIST, customizeTags.getData());
|
|
|
jsonObject.put(RECOMMEND_PROMOTION_LIST, sceneAggregationsHelper.subRecommendPromotions(promotions.getData(), this.getPage(paramMap), 1));
|
|
|
return productList;
|
|
|
} catch (Exception e) {
|
|
|
logger.error(e.getMessage(), e);
|
|
|
return new SearchApiResult().setData(null).setMessage("SortProductList Exception").setCode(500);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private boolean goToRecall(Map<String, String> paramMap) {
|
|
|
if (!searchDynamicConfigService.isSortPageRecallOpen()) {
|
|
|
return false;
|
|
|
}
|
|
|
if (!searchCommonHelper.isOrderEmpty(paramMap)) {
|
|
|
return false;
|
|
|
}
|
|
|
// int uid = searchCommonHelper.getUid(paramMap);
|
|
|
// if (uid <= 0) {
|
|
|
// return false;
|
|
|
// }
|
|
|
// if (!searchDynamicConfigService.isGoToSortRecallUser(uid)) {
|
|
|
// return false;
|
|
|
// }
|
|
|
return true;
|
|
|
}
|
|
|
private boolean goToRecall(Map<String, String> paramMap) {
|
|
|
if (!searchDynamicConfigService.isSortPageRecallOpen()) {
|
|
|
return false;
|
|
|
}
|
|
|
if (!searchCommonHelper.isOrderEmpty(paramMap)) {
|
|
|
return false;
|
|
|
}
|
|
|
int uid = searchCommonHelper.getUid(paramMap);
|
|
|
if (uid <= 0) {
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public SearchApiResult aggregations(Map<String, String> paramMap) {
|
|
|
try {
|
|
|
// 0、必传品类相关参数
|
|
|
if (!this.checkParam(paramMap)) {
|
|
|
return new SearchApiResult().setCode(400).setMessage("请传品类相关参数");
|
|
|
}
|
|
|
// 1、添加默认参数
|
|
|
this.addParamsToParamMap(paramMap);
|
|
|
// 2、返回聚合结果
|
|
|
return sceneSelectionsService.aggregations(paramMap);
|
|
|
} catch (Exception e) {
|
|
|
logger.error(e.getMessage(), e);
|
|
|
return new SearchApiResult().setData(null).setMessage("SortAggregations Exception").setCode(500);
|
|
|
}
|
|
|
}
|
|
|
@Override
|
|
|
public SearchApiResult aggregations(Map<String, String> paramMap) {
|
|
|
try {
|
|
|
// 0、必传品类相关参数
|
|
|
if (!this.checkParam(paramMap)) {
|
|
|
return new SearchApiResult().setCode(400).setMessage("请传品类相关参数");
|
|
|
}
|
|
|
// 1、添加默认参数
|
|
|
this.addParamsToParamMap(paramMap);
|
|
|
// 2、返回聚合结果
|
|
|
return sceneSelectionsService.aggregations(paramMap);
|
|
|
} catch (Exception e) {
|
|
|
logger.error(e.getMessage(), e);
|
|
|
return new SearchApiResult().setData(null).setMessage("SortAggregations Exception").setCode(500);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|