|
|
package com.yoho.search.service.scene.common;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.yoho.search.common.utils.SearchKeyWordUtils;
|
|
|
import com.yoho.search.models.SearchApiResult;
|
|
|
import com.yoho.search.service.base.SearchRequestParams;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
|
|
|
import org.apache.commons.collections.MapUtils;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
import java.util.concurrent.Executor;
|
|
|
import java.util.function.Supplier;
|
|
|
import com.yoho.search.common.utils.SearchKeyWordUtils;
|
|
|
import com.yoho.search.models.SearchApiResult;
|
|
|
import com.yoho.search.service.base.SearchRequestParams;
|
|
|
|
|
|
public abstract class AbstractSceneService {
|
|
|
|
|
|
|
|
|
protected static final String RECOMMEND_PROMOTION_LIST = "recommend_promotion_list";
|
|
|
protected static final String CUSTOMIZE_TAG_LIST = "customize_tag";
|
|
|
|
|
|
protected Map<String, String> newParamMap(Map<String, String> paramMap) {
|
|
|
protected static final String CUSTOMIZE_TAG_LIST = "customize_tag";
|
|
|
protected static final String STANDARD = "standard";
|
|
|
|
|
|
protected Map<String, String> newParamMap(Map<String, String> paramMap) {
|
|
|
return new HashMap<String, String>(paramMap);
|
|
|
}
|
|
|
|
|
|
protected CompletableFuture<?> getFuture(Supplier<?> supplier,Executor executor){
|
|
|
return CompletableFuture.supplyAsync(() -> supplier,executor);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 场景化的默认参数
|
|
|
*
|
...
|
...
|
@@ -42,45 +35,19 @@ public abstract class AbstractSceneService { |
|
|
paramMap.put(SearchRequestParams.PARAM_SEARCH_ATTRIBUTE_NOT, "2");// 非赠品
|
|
|
paramMap.put(SearchRequestParams.PARAM_SEARCH_NEEDSMALLSORT, "1");// 品类聚合时带上小分类
|
|
|
paramMap.put(SearchRequestParams.PARAM_SEARCH_AGG_WITH_PARAM_BRAND, "Y");// 聚合时使用参数中自带的参数
|
|
|
//关键词反转码
|
|
|
String keyword = SearchKeyWordUtils.getParamKeyword(paramMap, SearchRequestParams.PARAM_SEARCH_QUERY);//转码
|
|
|
if(!StringUtils.isBlank(keyword)){
|
|
|
// 关键词反转码
|
|
|
String keyword = SearchKeyWordUtils.getParamKeyword(paramMap, SearchRequestParams.PARAM_SEARCH_QUERY);// 转码
|
|
|
if (!StringUtils.isBlank(keyword)) {
|
|
|
paramMap.put(SearchRequestParams.PARAM_SEARCH_QUERY, keyword);
|
|
|
paramMap.put("is_encode", "0");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
protected int getPage(Map<String, String> paramMap) {
|
|
|
int page = StringUtils.isBlank(paramMap.get("page")) ? 1 : Integer.parseInt(paramMap.get("page"));
|
|
|
return page;
|
|
|
}
|
|
|
|
|
|
protected List<Object> subList(Object source, int page, int count) {
|
|
|
try {
|
|
|
JSONArray sourceList = (JSONArray)source;
|
|
|
if (sourceList != null && !sourceList.isEmpty()) {
|
|
|
int totalCount = sourceList.size();
|
|
|
int start = (page - 1) * count;
|
|
|
int end = start + count;
|
|
|
if (start >= totalCount) {
|
|
|
return Collections.emptyList();
|
|
|
}
|
|
|
if (end > totalCount) {
|
|
|
end = totalCount;
|
|
|
}
|
|
|
List<Object> subList = sourceList.subList(start, end);
|
|
|
subList.forEach(e -> {
|
|
|
JSONObject jsonObject = (JSONObject)e;
|
|
|
jsonObject.put("totalCount", totalCount);
|
|
|
});
|
|
|
return subList;
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
return Collections.emptyList();
|
|
|
}
|
|
|
return Collections.emptyList();
|
|
|
}
|
|
|
|
|
|
protected String getuid(Map<String, String> paramMap) {
|
|
|
return MapUtils.getString(paramMap, "uid", "0");
|
|
|
}
|
...
|
...
|
|