Authored by hugufei

优化AbstractSceneService

package com.yoho.search.service.scene.common;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import com.yoho.search.common.utils.SearchKeyWordUtils;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.common.SearchRequestParams;
import com.yoho.search.models.SearchApiResult;
public abstract class AbstractSceneService {
import java.util.Map;
public abstract class AbstractSceneService extends BaseSceneService{
protected static final String RECOMMEND_PROMOTION_LIST = "recommend_promotion_list";
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<>(paramMap);
}
/**
* 去除非正常商品的显示
* @param paramMap
*/
protected void filterNotNormalToMap(Map<String, String> paramMap) {
paramMap.put(SearchRequestParams.PARAM_SEARCH_ISLIMITED, "N");// 不支持限定
paramMap.put(SearchRequestParams.PARAM_SEARCH_CONTAIN_SECKILL, "N");// 不支持秒杀
paramMap.put(SearchRequestParams.PARAM_SEARCH_CONTAIN_GLOBAL, "N");// 不支持全球购
paramMap.put(SearchRequestParams.PARAM_SEARCH_ISADVANCE, "N");// 不支持预售
paramMap.put(SearchRequestParams.PARAM_SEARCH_BUNDLETYPE, "0");// 不支持套餐
paramMap.put(SearchRequestParams.PARAM_SEARCH_ISLIMITEDBUY, "N");// 不支持限购
paramMap.put(SearchRequestParams.PARAM_SEARCH_ISDESPOSITADVANCE, "N");// 不支持定金预售
paramMap.put(SearchRequestParams.PARAM_SEARCH_ISLIMITTIMEADVANCE, "N");// 不支持定金促销
}
/**
* 场景化的默认参数
*
* @param paramMap
*/
protected void addDefaultParamsToParamMap(Map<String, String> paramMap) {
super.addDefaultParamsToParamMap(paramMap);
paramMap.put(SearchRequestParams.PARAM_SEARCH_PAGEID, this.pageId());// 根据场景划分的页面id
paramMap.put(SearchRequestParams.PARAM_SEARCH_GLOBAL_FILTER_BRAND, "Y");// 页面屏蔽
paramMap.put(SearchRequestParams.PARAM_SEARCH_STATUS, "1");// 上架
paramMap.put(SearchRequestParams.PARAM_SEARCH_STOCKNUM, "1");// 有库存
paramMap.put(SearchRequestParams.PARAM_SEARCH_SHOWSOLDOUT, "1");// 显示延期显示的商品
paramMap.put(SearchRequestParams.PARAM_SEARCH_ISOUTLETS, "2");// 非奥莱
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)) {
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;
}
public abstract void addParamsToParamMap(Map<String, String> paramMap);
... ...
package com.yoho.search.service.scene.common;
import com.yoho.search.common.SearchRequestParams;
import com.yoho.search.common.utils.SearchKeyWordUtils;
import org.apache.commons.lang.StringUtils;
import java.util.HashMap;
import java.util.Map;
public class BaseSceneService {
protected Map<String, String> newParamMap(Map<String, String> paramMap) {
return new HashMap<>(paramMap);
}
/**
* 场景化的默认参数
*
* @param paramMap
*/
protected void addDefaultParamsToParamMap(Map<String, String> paramMap) {
paramMap.put(SearchRequestParams.PARAM_SEARCH_GLOBAL_FILTER_BRAND, "Y");// 页面屏蔽
paramMap.put(SearchRequestParams.PARAM_SEARCH_STATUS, "1");// 上架
paramMap.put(SearchRequestParams.PARAM_SEARCH_STOCKNUM, "1");// 有库存
paramMap.put(SearchRequestParams.PARAM_SEARCH_SHOWSOLDOUT, "1");// 显示延期显示的商品
paramMap.put(SearchRequestParams.PARAM_SEARCH_ISOUTLETS, "2");// 非奥莱
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)) {
paramMap.put(SearchRequestParams.PARAM_SEARCH_QUERY, keyword);
paramMap.put("is_encode", "0");
}
}
/**
* 去除非正常商品的显示
*
* @param paramMap
*/
protected void filterNotNormalToMap(Map<String, String> paramMap) {
paramMap.put(SearchRequestParams.PARAM_SEARCH_ISLIMITED, "N");// 不支持限定
paramMap.put(SearchRequestParams.PARAM_SEARCH_CONTAIN_SECKILL, "N");// 不支持秒杀
paramMap.put(SearchRequestParams.PARAM_SEARCH_CONTAIN_GLOBAL, "N");// 不支持全球购
paramMap.put(SearchRequestParams.PARAM_SEARCH_ISADVANCE, "N");// 不支持预售
paramMap.put(SearchRequestParams.PARAM_SEARCH_BUNDLETYPE, "0");// 不支持套餐
paramMap.put(SearchRequestParams.PARAM_SEARCH_ISLIMITEDBUY, "N");// 不支持限购
paramMap.put(SearchRequestParams.PARAM_SEARCH_ISDESPOSITADVANCE, "N");// 不支持定金预售
paramMap.put(SearchRequestParams.PARAM_SEARCH_ISLIMITTIMEADVANCE, "N");// 不支持定金促销
}
protected int getPage(Map<String, String> paramMap) {
int page = StringUtils.isBlank(paramMap.get("page")) ? 1 : Integer.parseInt(paramMap.get("page"));
return page;
}
}
... ...
package com.yoho.search.service.scene.hongren;
import com.alibaba.fastjson.JSONObject;
import com.yoho.search.common.utils.SearchApiResultUtils;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.cache.beans.SearchCacheService;
import com.yoho.search.common.SearchRequestParams;
import com.yoho.search.common.utils.SearchApiResultUtils;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.helper.SearchCommonHelper;
import com.yoho.search.service.helper.SearchKeyWordHelper;
import com.yoho.search.service.scene.list.ProductListSwitchService;
import com.yoho.search.service.scene.common.AbstractSceneService;
import com.yoho.search.service.scene.aggregations.AggregationService;
import com.yoho.search.service.scene.common.BaseSceneService;
import com.yoho.search.service.scene.list.ProductListSwitchService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
... ... @@ -17,7 +17,7 @@ import org.springframework.stereotype.Service;
import java.util.Map;
@Service
public class SearchHongRenService extends AbstractSceneService {
public class SearchHongRenService extends BaseSceneService {
@Autowired
protected SearchCacheService searchCacheService;
... ... @@ -50,12 +50,10 @@ public class SearchHongRenService extends AbstractSceneService {
return searchApiResult;
}
public SearchApiResult productList(Map<String, String> paramMap) {
try {
// 1、添加默认参数
addParamsToParamMap(paramMap);
this.addDefaultParamsToParamMap(paramMap);
return productListSwitchService.productList(newParamMap(paramMap));
} catch (Exception e) {
return new SearchApiResult().setData(null).setMessage("hrSortProductList Exception").setCode(500);
... ... @@ -69,7 +67,7 @@ public class SearchHongRenService extends AbstractSceneService {
return new SearchApiResult().setCode(400).setMessage("请传query参数");
}
// 2、添加默认参数
this.addParamsToParamMap(paramMap);
this.addDefaultParamsToParamMap(paramMap);
// 3、获取商品列表
SearchApiResult productListResult = productListSwitchService.fuzzyProductList(this.newParamMap(paramMap));
// 7、模糊搜索页记录关键字对应的查询结果
... ... @@ -84,20 +82,5 @@ public class SearchHongRenService extends AbstractSceneService {
}
}
@Override
public void addParamsToParamMap(Map<String, String> paramMap) {
super.addDefaultParamsToParamMap(paramMap);
}
@Override
public String pageId() {
return null;
}
@Override
public SearchApiResult aggregations(Map<String, String> paramMap) {
return null;
}
}
... ...