Authored by unknown

区分场景

package com.yoho.search.service.restapi.scene;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.yoho.search.service.servicenew.scene.BrandSceneService;
import com.yoho.search.service.utils.HttpServletRequestUtils;
import com.yoho.search.service.vo.SearchApiResult;
/**
* 品牌列表
*
* @author gufei.hu
*
*/
@Controller
public class BrandSceneController {
@Autowired
private BrandSceneService brandSceneService;
/**
* 品牌页列表
*
* @return
*/
@RequestMapping(method = RequestMethod.GET, value = "/brand/productList")
@ResponseBody
public SearchApiResult shopProductList(HttpServletRequest request) {
Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
return brandSceneService.productList(paramMap);
}
/**
* 品牌页筛选
*
* @return
*/
@RequestMapping(method = RequestMethod.GET, value = "/brand/aggregations")
@ResponseBody
public SearchApiResult shopAggregations(HttpServletRequest request) {
Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
return brandSceneService.aggregations(paramMap);
}
}
... ...
... ... @@ -17,15 +17,16 @@ import com.yoho.search.service.vo.SearchApiResult;
/**
* 商品池接口
*
* @author gufei.hu
*
*/
@Controller
public class ProductPoolSceneControoler {
@Autowired
private ProductPoolSceneService productPoolService;
/**
* 搜索商品池商品列表
*
... ... @@ -39,4 +40,30 @@ public class ProductPoolSceneControoler {
Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
return productPoolService.productPool(paramMap);
}
/**
* 商品池列表
*
* @param request
* @return
*/
@RequestMapping(method = RequestMethod.GET, value = "/pool/productList")
@ResponseBody
public SearchApiResult poolProductList(HttpServletRequest request) {
Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
return productPoolService.productList(paramMap);
}
/**
* 商品池筛选
*
* @param request
* @return
*/
@RequestMapping(method = RequestMethod.GET, value = "/pool/aggregations")
@ResponseBody
public SearchApiResult poolAggregations(HttpServletRequest request) {
Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
return productPoolService.aggregations(paramMap);
}
}
... ...
package com.yoho.search.service.servicenew.impl;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.aggregations.Aggregation;
import org.springframework.beans.factory.annotation.Autowired;
import com.alibaba.fastjson.JSONObject;
import com.yoho.search.base.utils.ConvertUtils;
import com.yoho.search.core.es.agg.IAggregation;
import com.yoho.search.service.service.helper.SearchParamHelper;
import com.yoho.search.service.service.helper.SearchSortHelper;
... ...
package com.yoho.search.service.servicenew.scene;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import com.yoho.search.base.utils.SearchPageIdDefine;
import com.yoho.search.service.servicenew.scene.common.AbstractSceneService;
import com.yoho.search.service.servicenew.scene.common.SceneProductListService;
import com.yoho.search.service.servicenew.scene.common.SceneSelectionsService;
import com.yoho.search.service.utils.SearchApiResultUtils;
import com.yoho.search.service.utils.SearchRequestParams;
import com.yoho.search.service.vo.SearchApiResult;
public class BrandSceneService extends AbstractSceneService {
private static final Logger logger = LoggerFactory.getLogger(BrandSceneService.class);
@Autowired
private SceneProductListService sceneProductListService;
@Autowired
private SceneSelectionsService sceneSelectionsService;
@Override
public String pageId() {
return SearchPageIdDefine.PAGE_ID_BRAND;
}
@Override
public void addParamsToParamMap(Map<String, String> paramMap) {
super.addDefaultParamsToParamMap(paramMap);
}
@Override
public SearchApiResult productList(Map<String, String> paramMap) {
try {
// 0、参数校验
if (StringUtils.isBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_BRAND))) {
return new SearchApiResult().setCode(400).setMessage("请传brand参数");
}
// 1、添加默认参数
this.addParamsToParamMap(paramMap);
// 2、返回商品列表
return sceneProductListService.productList(paramMap);
} catch (Exception e) {
logger.error("[func=BrandProductList][params=" + paramMap + "]", e);
return SearchApiResultUtils.errorSearchApiResult("BrandProductList", paramMap, e);
}
}
@Override
public SearchApiResult aggregations(Map<String, String> paramMap) {
try {
// 0、参数校验
if (StringUtils.isBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_BRAND))) {
return new SearchApiResult().setCode(400).setMessage("请传brand参数");
}
// 1、添加默认参数
this.addParamsToParamMap(paramMap);
// 2、返回聚合结果
return sceneSelectionsService.aggregations(paramMap);
} catch (Exception e) {
logger.error("[func=BrandAggregations][params=" + paramMap + "]", e);
return SearchApiResultUtils.errorSearchApiResult("BrandAggregations", paramMap, e);
}
}
}
... ...
... ... @@ -62,6 +62,10 @@ public class FuzzySceneService extends AbstractSceneService {
@Override
public SearchApiResult productList(Map<String, String> paramMap) {
try {
// 0、参数校验
if (StringUtils.isBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_QUERY))) {
return new SearchApiResult().setCode(400).setMessage("请传query参数");
}
// 1、添加默认参数
this.addParamsToParamMap(paramMap);
// 2、获取商品列表
... ... @@ -84,6 +88,10 @@ public class FuzzySceneService extends AbstractSceneService {
@Override
public SearchApiResult aggregations(Map<String, String> paramMap) {
try {
// 0、参数校验
if (StringUtils.isBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_QUERY))) {
return new SearchApiResult().setCode(400).setMessage("请传query参数");
}
// 1、添加默认参数
this.addParamsToParamMap(paramMap);
// 2、返回聚合结果
... ...
... ... @@ -8,17 +8,25 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yoho.search.base.utils.SearchPageIdDefine;
import com.yoho.search.service.servicenew.IProductListService;
import com.yoho.search.service.servicenew.scene.common.AbstractSceneService;
import com.yoho.search.service.servicenew.scene.common.SceneProductListService;
import com.yoho.search.service.servicenew.scene.common.SceneSelectionsService;
import com.yoho.search.service.utils.SearchApiResultUtils;
import com.yoho.search.service.vo.SearchApiResult;
@Service
public class ProductPoolSceneService {
public class ProductPoolSceneService extends AbstractSceneService {
private static final Logger logger = LoggerFactory.getLogger(ProductPoolSceneService.class);
@Autowired
private IProductListService productListService;
@Autowired
private SceneProductListService sceneProductListService;
@Autowired
private SceneSelectionsService sceneSelectionsService;
/**
* 将discount_score:desc 转为 pools.id:asc
... ... @@ -45,4 +53,56 @@ public class ProductPoolSceneService {
return SearchApiResultUtils.errorSearchApiResult("productPool", paramMap, e);
}
}
/**
* 将discount_score:desc 转为 pools.id:asc
*
* @param paramMap
* @return
*/
@Override
public void addParamsToParamMap(Map<String, String> paramMap) {
super.addDefaultParamsToParamMap(paramMap);
// 1)排序接口兼容【按商品池导入顺序排序】
String sortFields = paramMap.get("order");
if (!StringUtils.isBlank(sortFields) && sortFields.contains("discount_score")) {
paramMap.put("order", "pools.id:asc");
}
}
@Override
public String pageId() {
return SearchPageIdDefine.PAGE_ID_POOL;
}
public SearchApiResult productList(Map<String, String> paramMap) {
// 1)如果poolId为空返回
if (StringUtils.isBlank(paramMap.get("filter_poolId"))) {
return new SearchApiResult().setCode(400).setMessage("filter_poolId参数为空");
}
// 2)获取商品列表
try {
this.addParamsToParamMap(paramMap);
return sceneProductListService.productList(paramMap);
} catch (Exception e) {
logger.error("[func=PoolProductList][params=" + paramMap + "]", e);
return SearchApiResultUtils.errorSearchApiResult("PoolProductList", paramMap, e);
}
}
@Override
public SearchApiResult aggregations(Map<String, String> paramMap) {
// 1)如果poolId为空返回
if (StringUtils.isBlank(paramMap.get("filter_poolId"))) {
return new SearchApiResult().setCode(400).setMessage("filter_poolId参数为空");
}
// 2)获取商品池筛选项
try {
this.addParamsToParamMap(paramMap);
return sceneSelectionsService.aggregations(paramMap);
} catch (Exception e) {
logger.error("[func=PoolAggregations][params=" + paramMap + "]", e);
return SearchApiResultUtils.errorSearchApiResult("PoolAggregations", paramMap, e);
}
}
}
... ...
... ... @@ -2,6 +2,7 @@ package com.yoho.search.service.servicenew.scene;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -12,12 +13,13 @@ import com.yoho.search.service.servicenew.scene.common.AbstractSceneService;
import com.yoho.search.service.servicenew.scene.common.SceneProductListService;
import com.yoho.search.service.servicenew.scene.common.SceneSelectionsService;
import com.yoho.search.service.utils.SearchApiResultUtils;
import com.yoho.search.service.utils.SearchRequestParams;
import com.yoho.search.service.vo.SearchApiResult;
@Service
public class ShopSceneService extends AbstractSceneService {
private static final Logger logger = LoggerFactory.getLogger(NewArrivalSceneService.class);
private static final Logger logger = LoggerFactory.getLogger(ShopSceneService.class);
@Autowired
private SceneProductListService sceneProductListService;
... ... @@ -37,6 +39,10 @@ public class ShopSceneService extends AbstractSceneService {
@Override
public SearchApiResult productList(Map<String, String> paramMap) {
try {
// 0、参数校验
if (StringUtils.isBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_SHOP))) {
return new SearchApiResult().setCode(400).setMessage("请传shop参数");
}
// 1、添加默认参数
this.addParamsToParamMap(paramMap);
// 2、返回商品列表
... ... @@ -50,6 +56,10 @@ public class ShopSceneService extends AbstractSceneService {
@Override
public SearchApiResult aggregations(Map<String, String> paramMap) {
try {
// 0、参数校验
if (StringUtils.isBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_SHOP))) {
return new SearchApiResult().setCode(400).setMessage("请传shop参数");
}
// 1、添加默认参数
this.addParamsToParamMap(paramMap);
// 2、返回聚合结果
... ...
... ... @@ -55,6 +55,22 @@ public class SortSceneService extends AbstractSceneService {
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;
}
/**
* @特殊参数:
* @1、paramNum-获取规则数量的接口
... ... @@ -63,6 +79,10 @@ public class SortSceneService extends AbstractSceneService {
@Override
public SearchApiResult productList(Map<String, String> paramMap) {
try {
// 0、必传品类相关参数
if (!this.checkParam(paramMap)) {
return new SearchApiResult().setCode(400).setMessage("请传品类相关参数");
}
// 1、添加默认参数
this.addParamsToParamMap(paramMap);
// 2、获取商品列表
... ... @@ -93,6 +113,10 @@ public class SortSceneService extends AbstractSceneService {
@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、返回聚合结果
... ...
... ... @@ -2,6 +2,7 @@ package com.yoho.search.service.servicenew.scene;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -12,6 +13,7 @@ import com.yoho.search.service.servicenew.scene.common.AbstractSceneService;
import com.yoho.search.service.servicenew.scene.common.SceneProductListService;
import com.yoho.search.service.servicenew.scene.common.SceneSelectionsService;
import com.yoho.search.service.utils.SearchApiResultUtils;
import com.yoho.search.service.utils.SearchRequestParams;
import com.yoho.search.service.vo.SearchApiResult;
@Service
... ... @@ -28,7 +30,7 @@ public class ZqSceneService extends AbstractSceneService {
public String pageId() {
return SearchPageIdDefine.PAGE_ID_ZQ;
}
@Override
public void addParamsToParamMap(Map<String, String> paramMap) {
super.addDefaultParamsToParamMap(paramMap);
... ... @@ -37,6 +39,10 @@ public class ZqSceneService extends AbstractSceneService {
@Override
public SearchApiResult productList(Map<String, String> paramMap) {
try {
// 0、参数校验
if (StringUtils.isBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_ISPROMOTION))) {
return new SearchApiResult().setCode(400).setMessage("请传promotion参数");
}
// 1、添加默认参数
this.addParamsToParamMap(paramMap);
// 2、返回商品列表
... ... @@ -50,6 +56,10 @@ public class ZqSceneService extends AbstractSceneService {
@Override
public SearchApiResult aggregations(Map<String, String> paramMap) {
try {
// 0、参数校验
if (StringUtils.isBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_ISPROMOTION))) {
return new SearchApiResult().setCode(400).setMessage("请传promotion参数");
}
// 1、添加默认参数
this.addParamsToParamMap(paramMap);
// 2、返回聚合结果
... ...
... ... @@ -199,7 +199,7 @@ public class SceneSelectionsService extends BaseService {
return new JSONObject();
}
}
private JSONObject getFiltersResult(Map<String, String> paramMap, BoolQueryBuilder mustFilter) {
try {
SearchParam searchParam = searchParamHelper.buildWithMustFilter(paramMap, mustFilter);
... ...
... ... @@ -41,7 +41,7 @@ public class SearchRequestParams {
public static final String PARAM_SEARCH_SPECIALOFFER = "specialoffer"; // ◆是否为促销品
public static final String PARAM_SEARCH_ISSALES = "sales"; // ◆查询是否销售(有货不销售)
public static final String PARAM_SEARCH_ISPROMOTION = "promotion"; // 特价类型
public static final String PARAM_SEARCH_ISPROMOTION = "promotion"; // 专区id
public static final String PARAM_SEARCH_VIPDISCOUNTTYPE = "vdt"; // ◆VIP折扣类型
public static final String PARAM_SEARCH_PD = "p_d"; // ◆促销折扣浮点值(如0.7)
public static final String PARAM_SEARCH_PDINT = "p_d_int"; // ◆促销折扣整数值(如7)
... ...