Authored by unknown

搜索新增三个接口

1、最新降价列表
2.、最新降价筛选
3、老样式的店铺筛选项
... ... @@ -4,7 +4,6 @@ import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import com.yoho.search.service.service.IAggRecommendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
... ...
... ... @@ -26,7 +26,7 @@ public class NewArrivalSceneController {
private NewArrivalSceneService newArrivalService;
/**
* 店铺页列表
* 新品到着列表
*
* @return
*/
... ... @@ -38,7 +38,7 @@ public class NewArrivalSceneController {
}
/**
* 店铺页筛选
* 新品到着筛选项
*
* @return
*/
... ...
package com.yoho.search.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.common.utils.HttpServletRequestUtils;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.scene.ReducePriceSceneService;
/**
* 最新降价的场景
* @author gufei.hu
*/
@Controller
public class ReducePriceSceneController {
@Autowired
private ReducePriceSceneService reducePriceSceneService;
/**
* 最新降价的商品列表
*
* @return
*/
@RequestMapping(method = RequestMethod.GET, value = "/reducePrice/productList")
@ResponseBody
public SearchApiResult reducePriceProductList(HttpServletRequest request) {
Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
return reducePriceSceneService.productList(paramMap);
}
/**
* 最新降价的筛选项
*
* @return
*/
@RequestMapping(method = RequestMethod.GET, value = "/reducePrice/old/aggregations")
@ResponseBody
public SearchApiResult reducePriceAggregations(HttpServletRequest request) {
Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
return reducePriceSceneService.aggregations(paramMap);
}
}
... ...
... ... @@ -49,4 +49,16 @@ public class ShopSceneController {
Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
return shopSearchService.aggregations(paramMap);
}
/**
* 店铺页筛选-RN用
*
* @return
*/
@RequestMapping(method = RequestMethod.GET, value = "/shop/old/aggregations")
@ResponseBody
public SearchApiResult shopOldAggregations(HttpServletRequest request) {
Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
return shopSearchService.oldAggregations(paramMap);
}
}
... ...
package com.yoho.search.restapi.scene;
import com.yoho.search.common.utils.HttpServletRequestUtils;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.scene.SortSceneService;
import com.yoho.search.service.service.IAggRecommendService;
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 javax.servlet.http.HttpServletRequest;
import java.util.Map;
import com.yoho.search.common.utils.HttpServletRequestUtils;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.scene.SortSceneService;
/**
* 品类列表
... ...
package com.yoho.search.service.scene;
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yoho.search.base.utils.DateUtil;
import com.yoho.search.base.utils.SearchPageIdDefine;
import com.yoho.search.common.utils.SearchApiResultUtils;
import com.yoho.search.core.es.agg.IAggregation;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.base.SearchRequestParams;
import com.yoho.search.service.scene.common.AbstractSceneService;
import com.yoho.search.service.scene.common.SceneProductListService;
import com.yoho.search.service.scene.common.SceneSelectionsService;
@Service
public class ReducePriceSceneService extends AbstractSceneService {
private static final Logger logger = LoggerFactory.getLogger(ReducePriceSceneService.class);
@Autowired
private SceneProductListService sceneProductListService;
@Autowired
private SceneSelectionsService sceneSelectionsService;
@Override
public String pageId() {
return SearchPageIdDefine.PAGE_ID_REDUCE_PRICE;
}
@Override
public void addParamsToParamMap(Map<String, String> paramMap) {
super.addDefaultParamsToParamMap(paramMap);
// 默认打折
paramMap.put(SearchRequestParams.PARAM_SEARCH_ISDISCOUNT, "Y");
// 默认一周降价
long begin = DateUtil.getLastTimeSecond(new Date());
long end = DateUtil.getFirstTimeSecond(DateUtil.addDay(new Date(), -7));
paramMap.put(SearchRequestParams.PARAM_SEARCH_PRICE_UPDATE_TIME, begin + "," + end);
}
@Override
public SearchApiResult productList(Map<String, String> paramMap) {
try {
// 1、添加默认参数
this.addParamsToParamMap(paramMap);
// 2、返回商品列表
return sceneProductListService.productList(paramMap);
} catch (Exception e) {
logger.error("[func=NewArrivalProductList][params=" + paramMap + "]", e);
return SearchApiResultUtils.errorSearchApiResult("NewArrivalProductList", paramMap, e);
}
}
@Override
public SearchApiResult aggregations(Map<String, String> paramMap) {
try {
// 1、添加默认参数
this.addParamsToParamMap(paramMap);
// 2、返回聚合结果
List<IAggregation> aggregation = sceneSelectionsService.getReducePriceAggregations(paramMap);
return sceneSelectionsService.aggregations(paramMap, aggregation);
} catch (Exception e) {
logger.error("[func=NewArrivalAggregations][params=" + paramMap + "]", e);
return SearchApiResultUtils.errorSearchApiResult("NewArrivalAggregations", paramMap, e);
}
}
}
... ...
package com.yoho.search.service.scene;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
... ... @@ -10,6 +11,7 @@ import org.springframework.stereotype.Service;
import com.yoho.search.base.utils.SearchPageIdDefine;
import com.yoho.search.common.utils.SearchApiResultUtils;
import com.yoho.search.core.es.agg.IAggregation;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.base.SearchRequestParams;
import com.yoho.search.service.scene.common.AbstractSceneService;
... ... @@ -69,4 +71,21 @@ public class ShopSceneService extends AbstractSceneService {
return SearchApiResultUtils.errorSearchApiResult("ShopAggregations", paramMap, e);
}
}
public SearchApiResult oldAggregations(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、返回聚合结果
List<IAggregation> aggregations = sceneSelectionsService.getShopOldAggregations(paramMap);
return sceneSelectionsService.aggregations(paramMap, aggregations);
} catch (Exception e) {
logger.error("[func=ShopAggregations][params=" + paramMap + "]", e);
return SearchApiResultUtils.errorSearchApiResult("ShopAggregations", paramMap, e);
}
}
}
... ...
... ... @@ -28,7 +28,7 @@ public abstract class AbstractSceneService {
paramMap.put(SearchRequestParams.PARAM_SEARCH_AGG_WITH_PARAM_BRAND, "Y");// 聚合时使用参数中自带的参数
// paramMap.put("sale", "Y");// 没用的参数
}
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.common;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
import org.elasticsearch.search.aggregations.Aggregation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yoho.search.base.utils.ISearchConstants;
... ... @@ -13,21 +29,6 @@ import com.yoho.search.service.aggregations.impls.AggregationFactoryService;
import com.yoho.search.service.base.SearchCommonService;
import com.yoho.search.service.helper.SearchParamHelper;
import com.yoho.search.service.service.IAggRecommendService;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
import org.elasticsearch.search.aggregations.Aggregation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@Service
public class SceneSelectionsService extends AbstractCacheAbleService {
... ... @@ -43,7 +44,6 @@ public class SceneSelectionsService extends AbstractCacheAbleService {
@Autowired
private IAggRecommendService aggRecommendService;
@Override
public SearchCache getSearchCache() {
return searchCacheFactory.getSelectionsForAppCache();
... ... @@ -121,20 +121,46 @@ public class SceneSelectionsService extends AbstractCacheAbleService {
}
/**
* 店铺、新频到着的筛选项列表
* 最新降价的筛选项
*
* @param paramMap
* @return
*/
@SuppressWarnings("unused")
private List<IAggregation> getRNAggregations(Map<String, String> paramMap) {
public List<IAggregation> getReducePriceAggregations(Map<String, String> paramMap) {
List<IAggregation> aggregations = new ArrayList<>();
// 1)性别
aggregations.add(aggregationFactoryService.getGenderNewAggregation());
// 2)品类
// 2)品牌
aggregations.add(aggregationFactoryService.getBrandAggregation(paramMap));
// 3)品类
aggregations.add(aggregationFactoryService.getSortGroupAggregation(paramMap));
// 3)品牌
// 4)颜色
aggregations.add(aggregationFactoryService.getColorAggregation(paramMap));
// 5)尺码
aggregations.add(aggregationFactoryService.getSizeAggregation());
// 6)价格
aggregations.add(aggregationFactoryService.getPriceAggregation());
// 7)折扣
aggregations.add(aggregationFactoryService.getDiscountAggregation());
// 8)风格
aggregations.add(aggregationFactoryService.getStyleAggregation(paramMap));
return aggregations;
}
/**
* 老的店铺的筛选项
*
* @param paramMap
* @return
*/
public List<IAggregation> getShopOldAggregations(Map<String, String> paramMap) {
List<IAggregation> aggregations = new ArrayList<>();
// 1)性别
aggregations.add(aggregationFactoryService.getGenderNewAggregation());
// 2)品牌
aggregations.add(aggregationFactoryService.getBrandAggregation(paramMap));
// 3)品类
aggregations.add(aggregationFactoryService.getSortGroupAggregation(paramMap));
// 4)颜色
aggregations.add(aggregationFactoryService.getColorAggregation(paramMap));
// 5)尺码
... ... @@ -143,6 +169,8 @@ public class SceneSelectionsService extends AbstractCacheAbleService {
aggregations.add(aggregationFactoryService.getPriceAggregation());
// 7)折扣
aggregations.add(aggregationFactoryService.getDiscountAggregation());
// 8)风格
aggregations.add(aggregationFactoryService.getStyleAggregation(paramMap));
return aggregations;
}
... ... @@ -208,13 +236,13 @@ public class SceneSelectionsService extends AbstractCacheAbleService {
return new JSONObject();
}
}
private JSONArray getRecommendBrands(Map<String, String> paramMap, BoolQueryBuilder mustFilter) {
Map<String, String> newParamMap = new HashMap<String, String>(paramMap);
SearchApiResult searchApiResult = aggRecommendService.aggRecommendBrand(newParamMap, mustFilter);
return (JSONArray) searchApiResult.getData();
}
public SearchApiResult aggregations(Map<String, String> paramMap) throws Exception {
List<IAggregation> commonAggregations = this.getCommonAggregations(paramMap);
return this.aggregations(paramMap, commonAggregations, null);
... ...