BaseSceneService.java 2.89 KB
package com.yoho.search.common;

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) {
        Map<String, String> newMap = new HashMap<>();
        newMap.putAll(paramMap);
        return newMap;
    }

    /**
     * 场景化的默认参数
     *
     * @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(SearchRequestParams.PARAM_SEARCH_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_CONTAIN_UFO, "N");// 不支持UFO
        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;
    }

}