Authored by unknown

拆分优惠券接口

package com.yoho.search.service.restapi.split;
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.split.ICouponSearchService;
import com.yoho.search.service.utils.HttpServletRequestUtils;
import com.yoho.search.service.vo.SearchApiResult;
/**
* 优惠券列表接口
*
* @author gufei.hu
*
*/
@Controller
public class CouponSearchController {
@Autowired
private ICouponSearchService couponSearchService;
/**
* 优惠券商品列表
*
* @return
*/
@RequestMapping(method = RequestMethod.GET, value = "/coupon/productList")
@ResponseBody
public SearchApiResult couponProductList(HttpServletRequest request) {
Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
return couponSearchService.couponProductList(paramMap);
}
/**
* 优惠券商品列表筛选项
*
* @return
*/
@RequestMapping(method = RequestMethod.GET, value = "/coupon/aggregations")
@ResponseBody
public SearchApiResult couponAggregations(HttpServletRequest request) {
Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
return couponSearchService.couponAggregations(paramMap);
}
}
... ...
... ... @@ -103,14 +103,6 @@ public class BaseService {
return page;
}
protected List<AbstractAggregationBuilder> getAggregationBuilders(List<IAggregation> aggregations) {
List<AbstractAggregationBuilder> builders = new ArrayList<>();
for (IAggregation aggregation : aggregations) {
builders.add(aggregation.getBuilder());
}
return builders;
}
protected SearchParam buildProductListSearchParam(Map<String, String> paramMap) throws Exception {
// 1)验证查询条数
int pageSize = StringUtils.isBlank(paramMap.get("viewNum")) ? 10 : Integer.parseInt(paramMap.get("viewNum"));
... ...
package com.yoho.search.service.split;
import java.util.Map;
import com.yoho.search.service.vo.SearchApiResult;
public interface ICouponSearchService {
/**
* 优惠券商品列表
*
* @param paramMap
* @return
*/
public SearchApiResult couponProductList(Map<String, String> paramMap);
/**
* 优惠券筛选项
*
* @param paramMap
* @return
*/
public SearchApiResult couponAggregations(Map<String, String> paramMap);
}
... ...
... ... @@ -6,6 +6,7 @@ import java.util.Map;
import javax.annotation.PostConstruct;
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
import org.elasticsearch.search.aggregations.Aggregation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -69,6 +70,14 @@ public class SplitSelectionsService extends BaseService {
aggregationSearchCache = searchCacheFactory.getSelectionsForAppCache();
}
private List<AbstractAggregationBuilder> getAggregationBuilders(List<IAggregation> aggregations) {
List<AbstractAggregationBuilder> builders = new ArrayList<>();
for (IAggregation aggregation : aggregations) {
builders.add(aggregation.getBuilder());
}
return builders;
}
/**
* @聚合选项:
* @1、全球购
... ... @@ -83,12 +92,17 @@ public class SplitSelectionsService extends BaseService {
* @10、尺码
* @11、风格
*/
public JSONObject getCommonFilters(Map<String, String> paramMap) {
List<IAggregation> aggregations = this.getCommonAggregations(paramMap);
return this.getCommonFilters(paramMap, aggregations);
}
public JSONObject getCommonFilters(Map<String, String> paramMap, List<IAggregation> aggregations) {
try {
// 1)构造搜索参数
SearchParam searchParam = searchParamHelper.buildDefault(paramMap);
// 2)构造聚合报文
List<IAggregation> aggregations = this.getCommonFilterAggregations(paramMap);
searchParam.setAggregationBuilders(this.getAggregationBuilders(aggregations));
// 3)构造其他参数
final String productIndexName = ISearchConstants.INDEX_NAME_PRODUCT_INDEX;
... ... @@ -122,7 +136,7 @@ public class SplitSelectionsService extends BaseService {
}
}
private List<IAggregation> getCommonFilterAggregations(Map<String, String> paramMap) {
public List<IAggregation> getCommonAggregations(Map<String, String> paramMap) {
List<IAggregation> aggregations = new ArrayList<>();
// 1)促销
aggregations.add(aggregationFactoryService.getPromotionAggregation(1000));
... ... @@ -149,9 +163,32 @@ public class SplitSelectionsService extends BaseService {
return aggregations;
}
public List<IAggregation> getCouponAggregations(Map<String, String> paramMap) {
List<IAggregation> aggregations = new ArrayList<>();
// 1)性别
aggregations.add(aggregationFactoryService.getGenderNewAggregation());
// 2)品牌
aggregations.add(aggregationFactoryService.getBrandAggregation(paramMap));
// 3)人群
aggregations.add(aggregationFactoryService.getAgeLevelAggregation());
// 4)品类
aggregations.add(aggregationFactoryService.getSortGroupAggregation(paramMap));
// 5)颜色
aggregations.add(aggregationFactoryService.getColorAggregation(paramMap));
// 6)尺码
aggregations.add(aggregationFactoryService.getSizeAggregation());
// 7)价格
aggregations.add(aggregationFactoryService.getPriceAggregation());
// 8)折扣
aggregations.add(aggregationFactoryService.getDiscountAggregation());
// 9)风格
aggregations.add(aggregationFactoryService.getStyleAggregation(paramMap));
return aggregations;
}
public JSONArray getRecommendBrands(Map<String, String> paramMap) {
SearchApiResult searchApiResult = aggRecommendService.aggRecommendBrand(paramMap);
return (JSONArray)searchApiResult.getData();
return (JSONArray) searchApiResult.getData();
}
}
... ...
package com.yoho.search.service.split.impl;
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.alibaba.fastjson.JSONObject;
import com.yoho.search.core.es.agg.IAggregation;
import com.yoho.search.service.split.ICouponSearchService;
import com.yoho.search.service.split.common.SplitProductListService;
import com.yoho.search.service.split.common.SplitSelectionsService;
import com.yoho.search.service.utils.SearchApiResultUtils;
import com.yoho.search.service.vo.SearchApiResult;
@Service
public class CouponSearchServiceImpl implements ICouponSearchService{
private static final Logger logger = LoggerFactory.getLogger(CouponSearchServiceImpl.class);
@Autowired
private SplitProductListService splitProductListService;
@Autowired
private SplitSelectionsService splitSelectionsService;
@Override
public SearchApiResult couponProductList(Map<String, String> paramMap) {
try {
return splitProductListService.productList(paramMap);
} catch (Exception e) {
logger.error("[func=couponProductList][params=" + paramMap + "]", e);
return SearchApiResultUtils.errorSearchApiResult("couponProductList", paramMap, e);
}
}
@Override
public SearchApiResult couponAggregations(Map<String, String> paramMap) {
// 1、获取优惠券页面的筛选结果
List<IAggregation> couponAggregations = splitSelectionsService.getCouponAggregations(paramMap);
JSONObject couponFilters = splitSelectionsService.getCommonFilters(paramMap,couponAggregations);
Map<String, Object> result = new JSONObject();
result.put("filter", couponFilters);
return new SearchApiResult().setData(result);
}
}
... ...