Authored by unknown

断码区区分场景

@@ -12,7 +12,6 @@ import org.springframework.web.bind.annotation.ResponseBody; @@ -12,7 +12,6 @@ import org.springframework.web.bind.annotation.ResponseBody;
12 12
13 import com.yoho.search.service.downgrade.aop.DownGradeAble; 13 import com.yoho.search.service.downgrade.aop.DownGradeAble;
14 import com.yoho.search.service.service.SearchProductsServiceNew; 14 import com.yoho.search.service.service.SearchProductsServiceNew;
15 -import com.yoho.search.service.servicenew.IBreakSizeNewService;  
16 import com.yoho.search.service.servicenew.IDiscountService; 15 import com.yoho.search.service.servicenew.IDiscountService;
17 import com.yoho.search.service.servicenew.IProductCountService; 16 import com.yoho.search.service.servicenew.IProductCountService;
18 import com.yoho.search.service.servicenew.IRecentService; 17 import com.yoho.search.service.servicenew.IRecentService;
@@ -30,8 +29,6 @@ public class SearchNewController { @@ -30,8 +29,6 @@ public class SearchNewController {
30 @Autowired 29 @Autowired
31 private IDiscountService discountService; 30 private IDiscountService discountService;
32 @Autowired 31 @Autowired
33 - private IBreakSizeNewService breakSizeNewService;  
34 - @Autowired  
35 private SearchProductsServiceNew searchProductsServiceNew; 32 private SearchProductsServiceNew searchProductsServiceNew;
36 @Autowired 33 @Autowired
37 private IProductCountService productCountService; 34 private IProductCountService productCountService;
@@ -104,28 +101,4 @@ public class SearchNewController { @@ -104,28 +101,4 @@ public class SearchNewController {
104 } 101 }
105 102
106 103
107 -  
108 -  
109 - @DownGradeAble(key = "sort_sizes")  
110 - @RequestMapping(method = RequestMethod.GET, value = "/sort_sizes")  
111 - @ResponseBody  
112 - public SearchApiResult sort_sizes(HttpServletRequest request) {  
113 - Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);  
114 - return breakSizeNewService.sortSizes(paramMap);  
115 - }  
116 -  
117 - /**  
118 - * 【断码区】按分类和型号获取商品(with storage_sku)  
119 - *  
120 - * @param request  
121 - * @return  
122 - */  
123 - @DownGradeAble(key = "sort_size_products")  
124 - @RequestMapping(method = RequestMethod.GET, value = "/sort_size_products")  
125 - @ResponseBody  
126 - public SearchApiResult sort_size_products(HttpServletRequest request) {  
127 - Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);  
128 - return breakSizeNewService.sort_size_products(paramMap);  
129 - }  
130 -  
131 } 104 }
  1 +package com.yoho.search.service.restapi.scene;
  2 +
  3 +import java.util.Map;
  4 +
  5 +import javax.servlet.http.HttpServletRequest;
  6 +
  7 +import org.springframework.beans.factory.annotation.Autowired;
  8 +import org.springframework.stereotype.Controller;
  9 +import org.springframework.web.bind.annotation.RequestMapping;
  10 +import org.springframework.web.bind.annotation.RequestMethod;
  11 +import org.springframework.web.bind.annotation.ResponseBody;
  12 +
  13 +import com.yoho.search.service.downgrade.aop.DownGradeAble;
  14 +import com.yoho.search.service.servicenew.scene.BreakSizeSceneService;
  15 +import com.yoho.search.service.utils.HttpServletRequestUtils;
  16 +import com.yoho.search.service.vo.SearchApiResult;
  17 +
  18 +/**
  19 + * 断码区场景接口
  20 + *
  21 + * @author gufei.hu
  22 + *
  23 + */
  24 +@Controller
  25 +public class BreakSizeSceneController {
  26 +
  27 + @Autowired
  28 + private BreakSizeSceneService breakSizeSceneService;
  29 +
  30 + /**
  31 + * 【断码区】商品列表
  32 + *
  33 + * @param request
  34 + * @return
  35 + */
  36 + @RequestMapping(method = RequestMethod.GET, value = "/break/productList")
  37 + @ResponseBody
  38 + public SearchApiResult breakProductList(HttpServletRequest request) {
  39 + Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
  40 + return breakSizeSceneService.productList(paramMap);
  41 + }
  42 +
  43 + /**
  44 + * 【断码区】筛选项【无分类和尺码】
  45 + *
  46 + * @param request
  47 + * @return
  48 + */
  49 + @RequestMapping(method = RequestMethod.GET, value = "/break/aggregations")
  50 + @ResponseBody
  51 + public SearchApiResult breakAggregations(HttpServletRequest request) {
  52 + Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
  53 + return breakSizeSceneService.productList(paramMap);
  54 + }
  55 +
  56 + /**
  57 + * 【断码区】分类和尺码的聚合结果
  58 + *
  59 + * @param request
  60 + * @return
  61 + */
  62 + @DownGradeAble(key = "sort_sizes")
  63 + @RequestMapping(method = RequestMethod.GET, value = "/sort_sizes")
  64 + @ResponseBody
  65 + public SearchApiResult sort_sizes(HttpServletRequest request) {
  66 + Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
  67 + return breakSizeSceneService.sortSizes(paramMap);
  68 + }
  69 +
  70 + /**
  71 + * 【断码区】按分类和型号获取商品
  72 + *
  73 + * @param request
  74 + * @return
  75 + */
  76 + @DownGradeAble(key = "sort_size_products")
  77 + @RequestMapping(method = RequestMethod.GET, value = "/sort_size_products")
  78 + @ResponseBody
  79 + public SearchApiResult sort_size_products(HttpServletRequest request) {
  80 + Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
  81 + return breakSizeSceneService.productList(paramMap);
  82 + }
  83 +
  84 +}
1 -package com.yoho.search.service.servicenew;  
2 -  
3 -import java.util.Map;  
4 -  
5 -import com.yoho.search.service.vo.SearchApiResult;  
6 -  
7 -public interface IBreakSizeNewService {  
8 -  
9 - /**  
10 - * 获取断码区的品类和尺码信息  
11 - *  
12 - * @param sizeSortReqBO  
13 - * @return  
14 - */  
15 - public SearchApiResult sortSizes(Map<String, String> paramMap);  
16 -  
17 - /**  
18 - * 获取断码区的商品列表【支持聚合】[使用本地缓存]  
19 - *  
20 - * @param paramMap  
21 - * @return  
22 - */  
23 - public SearchApiResult sort_size_products(Map<String, String> paramMap);  
24 -  
25 -}  
1 -package com.yoho.search.service.servicenew.impl; 1 +package com.yoho.search.service.servicenew.scene;
2 2
3 import java.util.ArrayList; 3 import java.util.ArrayList;
4 import java.util.Collection; 4 import java.util.Collection;
@@ -29,6 +29,8 @@ import org.springframework.stereotype.Service; @@ -29,6 +29,8 @@ import org.springframework.stereotype.Service;
29 29
30 import com.alibaba.fastjson.JSONObject; 30 import com.alibaba.fastjson.JSONObject;
31 import com.yoho.search.base.utils.ISearchConstants; 31 import com.yoho.search.base.utils.ISearchConstants;
  32 +import com.yoho.search.base.utils.SearchPageIdDefine;
  33 +import com.yoho.search.core.es.agg.IAggregation;
32 import com.yoho.search.core.es.model.SearchParam; 34 import com.yoho.search.core.es.model.SearchParam;
33 import com.yoho.search.core.es.model.SearchResult; 35 import com.yoho.search.core.es.model.SearchResult;
34 import com.yoho.search.service.cache.SearchCacheFactory; 36 import com.yoho.search.service.cache.SearchCacheFactory;
@@ -38,8 +40,9 @@ import com.yoho.search.service.service.SearchCommonService; @@ -38,8 +40,9 @@ import com.yoho.search.service.service.SearchCommonService;
38 import com.yoho.search.service.service.base.SizeIndexBaseService; 40 import com.yoho.search.service.service.base.SizeIndexBaseService;
39 import com.yoho.search.service.service.helper.SearchCommonHelper; 41 import com.yoho.search.service.service.helper.SearchCommonHelper;
40 import com.yoho.search.service.service.helper.SearchParamHelper; 42 import com.yoho.search.service.service.helper.SearchParamHelper;
41 -import com.yoho.search.service.servicenew.IBreakSizeNewService;  
42 -import com.yoho.search.service.servicenew.IProductListService; 43 +import com.yoho.search.service.servicenew.scene.common.AbstractSceneService;
  44 +import com.yoho.search.service.servicenew.scene.common.SceneProductListService;
  45 +import com.yoho.search.service.servicenew.scene.common.SceneSelectionsService;
43 import com.yoho.search.service.utils.SearchApiResultUtils; 46 import com.yoho.search.service.utils.SearchApiResultUtils;
44 import com.yoho.search.service.utils.SearchRequestParams; 47 import com.yoho.search.service.utils.SearchRequestParams;
45 import com.yoho.search.service.vo.SearchApiResult; 48 import com.yoho.search.service.vo.SearchApiResult;
@@ -47,13 +50,11 @@ import com.yoho.search.service.vo.SizeInfoVO; @@ -47,13 +50,11 @@ import com.yoho.search.service.vo.SizeInfoVO;
47 import com.yoho.search.service.vo.SortWithSizesVO; 50 import com.yoho.search.service.vo.SortWithSizesVO;
48 51
49 @Service 52 @Service
50 -public class BreakSizeNewServiceImpl implements IBreakSizeNewService { 53 +public class BreakSizeSceneService extends AbstractSceneService {
51 54
52 - private static final Logger logger = LoggerFactory.getLogger(BreakSizeNewServiceImpl.class); 55 + private static final Logger logger = LoggerFactory.getLogger(BreakSizeSceneService.class);
53 56
54 @Autowired 57 @Autowired
55 - private IProductListService productListService;  
56 - @Autowired  
57 private SearchCommonService searchCommonService; 58 private SearchCommonService searchCommonService;
58 @Autowired 59 @Autowired
59 private SizeIndexBaseService sizeIndexBaseService; 60 private SizeIndexBaseService sizeIndexBaseService;
@@ -65,6 +66,10 @@ public class BreakSizeNewServiceImpl implements IBreakSizeNewService { @@ -65,6 +66,10 @@ public class BreakSizeNewServiceImpl implements IBreakSizeNewService {
65 private SearchCacheFactory searchCacheFactory; 66 private SearchCacheFactory searchCacheFactory;
66 @Autowired 67 @Autowired
67 private SearchParamHelper searchParamHelper; 68 private SearchParamHelper searchParamHelper;
  69 + @Autowired
  70 + private SceneProductListService sceneProductListService;
  71 + @Autowired
  72 + private SceneSelectionsService sceneSelectionsService;
68 73
69 private SearchCache aggregationSearchCache; 74 private SearchCache aggregationSearchCache;
70 75
@@ -78,18 +83,52 @@ public class BreakSizeNewServiceImpl implements IBreakSizeNewService { @@ -78,18 +83,52 @@ public class BreakSizeNewServiceImpl implements IBreakSizeNewService {
78 * 83 *
79 * @param paramMap 84 * @param paramMap
80 */ 85 */
81 - private void dealDefaultBreakParamMap(Map<String, String> paramMap) {  
82 - // 获取过滤条件  
83 - paramMap.put(SearchRequestParams.PARAM_SEARCH_BREAKING, "1");  
84 - paramMap.put(SearchRequestParams.PARAM_SEARCH_STATUS, "1");  
85 - paramMap.put(SearchRequestParams.PARAM_SEARCH_STATUS, "1");  
86 - paramMap.put(SearchRequestParams.PARAM_SEARCH_STOCKNUM, "1");  
87 - paramMap.put("attribute_not", "2"); 86 + @Override
  87 + public void addParamsToParamMap(Map<String, String> paramMap) {
  88 + super.addDefaultParamsToParamMap(paramMap);
  89 + paramMap.put(SearchRequestParams.PARAM_SEARCH_BREAKING, "1");// 断码区商品
88 } 90 }
89 91
90 @Override 92 @Override
  93 + public String pageId() {
  94 + return SearchPageIdDefine.PAGE_ID_BREAKSIZE;
  95 + }
  96 +
  97 + @Override
  98 + public SearchApiResult productList(Map<String, String> paramMap) {
  99 + try {
  100 + // 1、添加默认参数
  101 + this.addParamsToParamMap(paramMap);
  102 + // 2、返回商品列表
  103 + return sceneProductListService.productList(paramMap);
  104 + } catch (Exception e) {
  105 + logger.error("[func=CouponProductList][params=" + paramMap + "]", e);
  106 + return SearchApiResultUtils.errorSearchApiResult("CouponProductList", paramMap, e);
  107 + }
  108 + }
  109 +
  110 + @Override
  111 + public SearchApiResult aggregations(Map<String, String> paramMap) {
  112 + try {
  113 + // 1、添加默认参数
  114 + this.addParamsToParamMap(paramMap);
  115 + // 2、返回聚合结果
  116 + List<IAggregation> aggregation = sceneSelectionsService.getBreakSizeAggregations(paramMap);
  117 + return sceneSelectionsService.aggregations(paramMap, aggregation);
  118 + } catch (Exception e) {
  119 + logger.error("[func=Couponaggregations][params=" + paramMap + "]", e);
  120 + return SearchApiResultUtils.errorSearchApiResult("Couponaggregations", paramMap, e);
  121 + }
  122 + }
  123 +
  124 + /**
  125 + * 1、获取断码区的品类和尺码的聚合
  126 + *
  127 + * @param paramMap
  128 + * @return
  129 + */
91 public SearchApiResult sortSizes(Map<String, String> paramMap) { 130 public SearchApiResult sortSizes(Map<String, String> paramMap) {
92 - this.dealDefaultBreakParamMap(paramMap); 131 + this.addParamsToParamMap(paramMap);
93 logger.info("[func=sortSizes][param={}][begin={}]", paramMap.toString(), System.currentTimeMillis()); 132 logger.info("[func=sortSizes][param={}][begin={}]", paramMap.toString(), System.currentTimeMillis());
94 try { 133 try {
95 // 获取带filter和query的SearchParam 134 // 获取带filter和query的SearchParam
@@ -135,7 +174,6 @@ public class BreakSizeNewServiceImpl implements IBreakSizeNewService { @@ -135,7 +174,6 @@ public class BreakSizeNewServiceImpl implements IBreakSizeNewService {
135 174
136 private List<SortWithSizesVO> getSortSizesResult(Map<String, Aggregation> aggMaps) { 175 private List<SortWithSizesVO> getSortSizesResult(Map<String, Aggregation> aggMaps) {
137 List<SortWithSizesVO> sortWithSizeList = new ArrayList<SortWithSizesVO>(); 176 List<SortWithSizesVO> sortWithSizeList = new ArrayList<SortWithSizesVO>();
138 -  
139 // 处理es返回的数据 177 // 处理es返回的数据
140 Collection<Integer> allSizeIds = new HashSet<Integer>(); 178 Collection<Integer> allSizeIds = new HashSet<Integer>();
141 MultiBucketsAggregation aggreation = (MultiBucketsAggregation) aggMaps.get("sortIdAgg"); 179 MultiBucketsAggregation aggreation = (MultiBucketsAggregation) aggMaps.get("sortIdAgg");
@@ -249,18 +287,4 @@ public class BreakSizeNewServiceImpl implements IBreakSizeNewService { @@ -249,18 +287,4 @@ public class BreakSizeNewServiceImpl implements IBreakSizeNewService {
249 return sizeResult; 287 return sizeResult;
250 } 288 }
251 289
252 - @Override  
253 - public SearchApiResult sort_size_products(Map<String, String> paramMap) {  
254 - this.dealDefaultBreakParamMap(paramMap);  
255 - logger.info("[func=sort_size_products][param={}][begin={}]", paramMap.toString(), System.currentTimeMillis());  
256 - if (searchCommonHelper.isDebugUser(paramMap)) {  
257 - logger.warn("sort_size_products paramMap is : [{}]", paramMap.toString());  
258 - }  
259 - try {  
260 - return productListService.productList(paramMap);  
261 - } catch (Exception e) {  
262 - return SearchApiResultUtils.errorSearchApiResult("sort_size_products", paramMap, e);  
263 - }  
264 - }  
265 -  
266 } 290 }
@@ -19,7 +19,7 @@ public abstract class AbstractSceneService { @@ -19,7 +19,7 @@ public abstract class AbstractSceneService {
19 paramMap.put(SearchRequestParams.PARAM_SEARCH_GLOBAL_FILTER_BRAND, "Y");// 页面屏蔽 19 paramMap.put(SearchRequestParams.PARAM_SEARCH_GLOBAL_FILTER_BRAND, "Y");// 页面屏蔽
20 paramMap.put(SearchRequestParams.PARAM_SEARCH_STATUS, "1");// 上架 20 paramMap.put(SearchRequestParams.PARAM_SEARCH_STATUS, "1");// 上架
21 paramMap.put(SearchRequestParams.PARAM_SEARCH_STOCKNUM, "1");// 有库存 21 paramMap.put(SearchRequestParams.PARAM_SEARCH_STOCKNUM, "1");// 有库存
22 - paramMap.put(SearchRequestParams.PARAM_SEARCH_SHOWSOLDOUT, "1");// 显示售罄商品 22 + paramMap.put(SearchRequestParams.PARAM_SEARCH_SHOWSOLDOUT, "1");// 显示延期显示的商品
23 paramMap.put(SearchRequestParams.PARAM_SEARCH_ISOUTLETS, "2");// 非奥莱 23 paramMap.put(SearchRequestParams.PARAM_SEARCH_ISOUTLETS, "2");// 非奥莱
24 paramMap.put(SearchRequestParams.PARAM_SEARCH_ATTRIBUTE_NOT, "2");// 非赠品 24 paramMap.put(SearchRequestParams.PARAM_SEARCH_ATTRIBUTE_NOT, "2");// 非赠品
25 paramMap.put("needSmallSort", "1");// 品类聚合时带上小分类 25 paramMap.put("needSmallSort", "1");// 品类聚合时带上小分类
@@ -119,6 +119,33 @@ public class SceneSelectionsService extends BaseService { @@ -119,6 +119,33 @@ public class SceneSelectionsService extends BaseService {
119 } 119 }
120 120
121 /** 121 /**
  122 + * @断码区的聚合选项:
  123 + * @比其他的场景少了品类和尺码的筛选项
  124 + */
  125 + public List<IAggregation> getBreakSizeAggregations(Map<String, String> paramMap) {
  126 + List<IAggregation> aggregations = new ArrayList<>();
  127 + // 1)促销
  128 + aggregations.add(aggregationFactoryService.getPromotionAggregation(1000));
  129 + // 2)全球购
  130 + aggregations.add(aggregationFactoryService.getIsGlobalAggregation());
  131 + // 3)品牌
  132 + aggregations.add(aggregationFactoryService.getBrandAggregation(paramMap));
  133 + // 4)人群
  134 + aggregations.add(aggregationFactoryService.getAgeLevelAggregation());
  135 + // 5)性别
  136 + aggregations.add(aggregationFactoryService.getGenderNewAggregation());
  137 + // 6)价格
  138 + aggregations.add(aggregationFactoryService.getPriceAggregation());
  139 + // 7)折扣
  140 + aggregations.add(aggregationFactoryService.getDiscountAggregation());
  141 + // 8)颜色
  142 + aggregations.add(aggregationFactoryService.getColorAggregation(paramMap));
  143 + // 9)风格
  144 + aggregations.add(aggregationFactoryService.getStyleAggregation(paramMap));
  145 + return aggregations;
  146 + }
  147 +
  148 + /**
122 * 店铺、新频到着的筛选项列表 149 * 店铺、新频到着的筛选项列表
123 * 150 *
124 * @param paramMap 151 * @param paramMap
@@ -200,10 +227,9 @@ public class SceneSelectionsService extends BaseService { @@ -200,10 +227,9 @@ public class SceneSelectionsService extends BaseService {
200 } 227 }
201 } 228 }
202 229
203 - private JSONObject getFiltersResult(Map<String, String> paramMap, BoolQueryBuilder mustFilter) { 230 + private JSONObject getFiltersResult(Map<String, String> paramMap, List<IAggregation> aggregations, BoolQueryBuilder mustFilter) {
204 try { 231 try {
205 SearchParam searchParam = searchParamHelper.buildWithMustFilter(paramMap, mustFilter); 232 SearchParam searchParam = searchParamHelper.buildWithMustFilter(paramMap, mustFilter);
206 - List<IAggregation> aggregations = this.getCommonAggregations(paramMap);  
207 return this.getFiltersResults(paramMap, searchParam, aggregations); 233 return this.getFiltersResults(paramMap, searchParam, aggregations);
208 } catch (Exception e) { 234 } catch (Exception e) {
209 logger.error("[func=fuzzyAggregations][params=" + paramMap + "]", e); 235 logger.error("[func=fuzzyAggregations][params=" + paramMap + "]", e);
@@ -217,13 +243,23 @@ public class SceneSelectionsService extends BaseService { @@ -217,13 +243,23 @@ public class SceneSelectionsService extends BaseService {
217 } 243 }
218 244
219 public SearchApiResult aggregations(Map<String, String> paramMap) throws Exception { 245 public SearchApiResult aggregations(Map<String, String> paramMap) throws Exception {
220 - return this.aggregations(paramMap, null); 246 + List<IAggregation> commonAggregations = this.getCommonAggregations(paramMap);
  247 + return this.aggregations(paramMap, commonAggregations, null);
  248 + }
  249 +
  250 + public SearchApiResult aggregations(Map<String, String> paramMap, List<IAggregation> aggregations) throws Exception {
  251 + return this.aggregations(paramMap, aggregations, null);
221 } 252 }
222 253
223 public SearchApiResult aggregations(Map<String, String> paramMap, BoolQueryBuilder mustFilter) throws Exception { 254 public SearchApiResult aggregations(Map<String, String> paramMap, BoolQueryBuilder mustFilter) throws Exception {
  255 + List<IAggregation> commonAggregations = this.getCommonAggregations(paramMap);
  256 + return this.aggregations(paramMap, commonAggregations, mustFilter);
  257 + }
  258 +
  259 + public SearchApiResult aggregations(Map<String, String> paramMap, List<IAggregation> aggregations, BoolQueryBuilder mustFilter) throws Exception {
224 // 1、获取通用筛选项 260 // 1、获取通用筛选项
225 CompletableFuture<JSONObject> commonFiltersFuture = CompletableFuture.supplyAsync(() -> { 261 CompletableFuture<JSONObject> commonFiltersFuture = CompletableFuture.supplyAsync(() -> {
226 - return this.getFiltersResult(paramMap, mustFilter); 262 + return this.getFiltersResult(paramMap, aggregations, mustFilter);
227 }, executorService); 263 }, executorService);
228 // 2、获取推荐的品牌 264 // 2、获取推荐的品牌
229 CompletableFuture<Object> recommendBrandFuture = CompletableFuture.supplyAsync(() -> { 265 CompletableFuture<Object> recommendBrandFuture = CompletableFuture.supplyAsync(() -> {