|
|
package com.yoho.search.service.servicenew.scene;
|
|
|
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
import java.util.concurrent.Executors;
|
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
...
|
...
|
@@ -10,7 +11,6 @@ import org.springframework.stereotype.Service; |
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.yoho.search.base.utils.SearchPageIdDefine;
|
|
|
import com.yoho.search.core.es.agg.IAggregation;
|
|
|
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;
|
...
|
...
|
@@ -18,7 +18,7 @@ import com.yoho.search.service.utils.SearchApiResultUtils; |
|
|
import com.yoho.search.service.vo.SearchApiResult;
|
|
|
|
|
|
@Service
|
|
|
public class CouponSceneService extends AbstractSceneService{
|
|
|
public class CouponSceneService extends AbstractSceneService {
|
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(CouponSceneService.class);
|
|
|
|
...
|
...
|
@@ -26,13 +26,23 @@ public class CouponSceneService extends AbstractSceneService{ |
|
|
private SceneProductListService splitProductListService;
|
|
|
@Autowired
|
|
|
private SceneSelectionsService splitSelectionsService;
|
|
|
|
|
|
|
|
|
@Override
|
|
|
public String pageId() {
|
|
|
return SearchPageIdDefine.PAGE_ID_COUPON;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void addParamsToParamMap(Map<String, String> paramMap) {
|
|
|
super.addDefaultParamsToParamMap(paramMap);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void setExecutorService() {
|
|
|
this.executorService = Executors.newFixedThreadPool(50);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public SearchApiResult productList(Map<String, String> paramMap) {
|
|
|
try {
|
|
|
return splitProductListService.productList(paramMap);
|
...
|
...
|
@@ -41,20 +51,33 @@ public class CouponSceneService extends AbstractSceneService{ |
|
|
return SearchApiResultUtils.errorSearchApiResult("couponProductList", paramMap, e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public SearchApiResult aggregations(Map<String, String> paramMap) {
|
|
|
// 1、获取优惠券页面的筛选结果
|
|
|
List<IAggregation> couponAggregations = splitSelectionsService.getCouponAggregations(paramMap);
|
|
|
JSONObject filterResults = splitSelectionsService.getFiltersResults(paramMap,couponAggregations);
|
|
|
Map<String, Object> result = new JSONObject();
|
|
|
result.put("filter", filterResults);
|
|
|
return new SearchApiResult().setData(result);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void addParamsToParamMap(Map<String, String> paramMap) {
|
|
|
// TODO Auto-generated method stub
|
|
|
public SearchApiResult aggregations(Map<String, String> paramMap) {
|
|
|
try {
|
|
|
// 0、添加默认参数
|
|
|
this.addParamsToParamMap(paramMap);
|
|
|
// 1、获取通用筛选项
|
|
|
CompletableFuture<JSONObject> commonFiltersFuture = CompletableFuture.supplyAsync(() -> {
|
|
|
return splitSelectionsService.getCommonFilters(paramMap);
|
|
|
}, executorService);
|
|
|
// 2、获取推荐的品牌
|
|
|
CompletableFuture<Object> recommendBrandFuture = CompletableFuture.supplyAsync(() -> {
|
|
|
return splitSelectionsService.getRecommendBrands(paramMap);
|
|
|
}, executorService);
|
|
|
// 3、组合
|
|
|
JSONObject commonFilters = commonFiltersFuture.get();
|
|
|
Object recommendBrand = recommendBrandFuture.get();
|
|
|
if (recommendBrand != null) {
|
|
|
commonFilters.put("recommendBrand", recommendBrand);
|
|
|
}
|
|
|
// 4、返回最终结果
|
|
|
Map<String, Object> result = new JSONObject();
|
|
|
result.put("filter", commonFilters);
|
|
|
return new SearchApiResult().setData(result);
|
|
|
} catch (Exception e) {
|
|
|
logger.error(e.getMessage(), e);
|
|
|
return new SearchApiResult().setData(null).setMessage("FuzzyAggregations Exception").setCode(500);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|