搜索新增三个接口
1、最新降价列表 2.、最新降价筛选 3、老样式的店铺筛选项
Showing
9 changed files
with
218 additions
and
33 deletions
@@ -4,7 +4,6 @@ import java.util.Map; | @@ -4,7 +4,6 @@ import java.util.Map; | ||
4 | 4 | ||
5 | import javax.servlet.http.HttpServletRequest; | 5 | import javax.servlet.http.HttpServletRequest; |
6 | 6 | ||
7 | -import com.yoho.search.service.service.IAggRecommendService; | ||
8 | import org.springframework.beans.factory.annotation.Autowired; | 7 | import org.springframework.beans.factory.annotation.Autowired; |
9 | import org.springframework.stereotype.Controller; | 8 | import org.springframework.stereotype.Controller; |
10 | import org.springframework.web.bind.annotation.RequestMapping; | 9 | import org.springframework.web.bind.annotation.RequestMapping; |
@@ -26,7 +26,7 @@ public class NewArrivalSceneController { | @@ -26,7 +26,7 @@ public class NewArrivalSceneController { | ||
26 | private NewArrivalSceneService newArrivalService; | 26 | private NewArrivalSceneService newArrivalService; |
27 | 27 | ||
28 | /** | 28 | /** |
29 | - * 店铺页列表 | 29 | + * 新品到着列表 |
30 | * | 30 | * |
31 | * @return | 31 | * @return |
32 | */ | 32 | */ |
@@ -38,7 +38,7 @@ public class NewArrivalSceneController { | @@ -38,7 +38,7 @@ public class NewArrivalSceneController { | ||
38 | } | 38 | } |
39 | 39 | ||
40 | /** | 40 | /** |
41 | - * 店铺页筛选 | 41 | + * 新品到着筛选项 |
42 | * | 42 | * |
43 | * @return | 43 | * @return |
44 | */ | 44 | */ |
1 | +package com.yoho.search.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.common.utils.HttpServletRequestUtils; | ||
14 | +import com.yoho.search.models.SearchApiResult; | ||
15 | +import com.yoho.search.service.scene.ReducePriceSceneService; | ||
16 | + | ||
17 | +/** | ||
18 | + * 最新降价的场景 | ||
19 | + * @author gufei.hu | ||
20 | + */ | ||
21 | + | ||
22 | +@Controller | ||
23 | +public class ReducePriceSceneController { | ||
24 | + | ||
25 | + @Autowired | ||
26 | + private ReducePriceSceneService reducePriceSceneService; | ||
27 | + | ||
28 | + /** | ||
29 | + * 最新降价的商品列表 | ||
30 | + * | ||
31 | + * @return | ||
32 | + */ | ||
33 | + @RequestMapping(method = RequestMethod.GET, value = "/reducePrice/productList") | ||
34 | + @ResponseBody | ||
35 | + public SearchApiResult reducePriceProductList(HttpServletRequest request) { | ||
36 | + Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request); | ||
37 | + return reducePriceSceneService.productList(paramMap); | ||
38 | + } | ||
39 | + | ||
40 | + /** | ||
41 | + * 最新降价的筛选项 | ||
42 | + * | ||
43 | + * @return | ||
44 | + */ | ||
45 | + @RequestMapping(method = RequestMethod.GET, value = "/reducePrice/old/aggregations") | ||
46 | + @ResponseBody | ||
47 | + public SearchApiResult reducePriceAggregations(HttpServletRequest request) { | ||
48 | + Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request); | ||
49 | + return reducePriceSceneService.aggregations(paramMap); | ||
50 | + } | ||
51 | +} |
@@ -49,4 +49,16 @@ public class ShopSceneController { | @@ -49,4 +49,16 @@ public class ShopSceneController { | ||
49 | Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request); | 49 | Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request); |
50 | return shopSearchService.aggregations(paramMap); | 50 | return shopSearchService.aggregations(paramMap); |
51 | } | 51 | } |
52 | + | ||
53 | + /** | ||
54 | + * 店铺页筛选-RN用 | ||
55 | + * | ||
56 | + * @return | ||
57 | + */ | ||
58 | + @RequestMapping(method = RequestMethod.GET, value = "/shop/old/aggregations") | ||
59 | + @ResponseBody | ||
60 | + public SearchApiResult shopOldAggregations(HttpServletRequest request) { | ||
61 | + Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request); | ||
62 | + return shopSearchService.oldAggregations(paramMap); | ||
63 | + } | ||
52 | } | 64 | } |
1 | package com.yoho.search.restapi.scene; | 1 | package com.yoho.search.restapi.scene; |
2 | 2 | ||
3 | -import com.yoho.search.common.utils.HttpServletRequestUtils; | ||
4 | -import com.yoho.search.models.SearchApiResult; | ||
5 | -import com.yoho.search.service.scene.SortSceneService; | ||
6 | -import com.yoho.search.service.service.IAggRecommendService; | 3 | +import java.util.Map; |
4 | + | ||
5 | +import javax.servlet.http.HttpServletRequest; | ||
6 | + | ||
7 | import org.springframework.beans.factory.annotation.Autowired; | 7 | import org.springframework.beans.factory.annotation.Autowired; |
8 | import org.springframework.stereotype.Controller; | 8 | import org.springframework.stereotype.Controller; |
9 | import org.springframework.web.bind.annotation.RequestMapping; | 9 | import org.springframework.web.bind.annotation.RequestMapping; |
10 | import org.springframework.web.bind.annotation.RequestMethod; | 10 | import org.springframework.web.bind.annotation.RequestMethod; |
11 | import org.springframework.web.bind.annotation.ResponseBody; | 11 | import org.springframework.web.bind.annotation.ResponseBody; |
12 | 12 | ||
13 | -import javax.servlet.http.HttpServletRequest; | ||
14 | -import java.util.Map; | 13 | +import com.yoho.search.common.utils.HttpServletRequestUtils; |
14 | +import com.yoho.search.models.SearchApiResult; | ||
15 | +import com.yoho.search.service.scene.SortSceneService; | ||
15 | 16 | ||
16 | /** | 17 | /** |
17 | * 品类列表 | 18 | * 品类列表 |
1 | +package com.yoho.search.service.scene; | ||
2 | + | ||
3 | +import java.util.Date; | ||
4 | +import java.util.List; | ||
5 | +import java.util.Map; | ||
6 | + | ||
7 | +import org.slf4j.Logger; | ||
8 | +import org.slf4j.LoggerFactory; | ||
9 | +import org.springframework.beans.factory.annotation.Autowired; | ||
10 | +import org.springframework.stereotype.Service; | ||
11 | + | ||
12 | +import com.yoho.search.base.utils.DateUtil; | ||
13 | +import com.yoho.search.base.utils.SearchPageIdDefine; | ||
14 | +import com.yoho.search.common.utils.SearchApiResultUtils; | ||
15 | +import com.yoho.search.core.es.agg.IAggregation; | ||
16 | +import com.yoho.search.models.SearchApiResult; | ||
17 | +import com.yoho.search.service.base.SearchRequestParams; | ||
18 | +import com.yoho.search.service.scene.common.AbstractSceneService; | ||
19 | +import com.yoho.search.service.scene.common.SceneProductListService; | ||
20 | +import com.yoho.search.service.scene.common.SceneSelectionsService; | ||
21 | + | ||
22 | +@Service | ||
23 | +public class ReducePriceSceneService extends AbstractSceneService { | ||
24 | + | ||
25 | + private static final Logger logger = LoggerFactory.getLogger(ReducePriceSceneService.class); | ||
26 | + | ||
27 | + @Autowired | ||
28 | + private SceneProductListService sceneProductListService; | ||
29 | + @Autowired | ||
30 | + private SceneSelectionsService sceneSelectionsService; | ||
31 | + | ||
32 | + @Override | ||
33 | + public String pageId() { | ||
34 | + return SearchPageIdDefine.PAGE_ID_REDUCE_PRICE; | ||
35 | + } | ||
36 | + | ||
37 | + @Override | ||
38 | + public void addParamsToParamMap(Map<String, String> paramMap) { | ||
39 | + super.addDefaultParamsToParamMap(paramMap); | ||
40 | + // 默认打折 | ||
41 | + paramMap.put(SearchRequestParams.PARAM_SEARCH_ISDISCOUNT, "Y"); | ||
42 | + // 默认一周降价 | ||
43 | + long begin = DateUtil.getLastTimeSecond(new Date()); | ||
44 | + long end = DateUtil.getFirstTimeSecond(DateUtil.addDay(new Date(), -7)); | ||
45 | + paramMap.put(SearchRequestParams.PARAM_SEARCH_PRICE_UPDATE_TIME, begin + "," + end); | ||
46 | + } | ||
47 | + | ||
48 | + @Override | ||
49 | + public SearchApiResult productList(Map<String, String> paramMap) { | ||
50 | + try { | ||
51 | + // 1、添加默认参数 | ||
52 | + this.addParamsToParamMap(paramMap); | ||
53 | + // 2、返回商品列表 | ||
54 | + return sceneProductListService.productList(paramMap); | ||
55 | + } catch (Exception e) { | ||
56 | + logger.error("[func=NewArrivalProductList][params=" + paramMap + "]", e); | ||
57 | + return SearchApiResultUtils.errorSearchApiResult("NewArrivalProductList", paramMap, e); | ||
58 | + } | ||
59 | + } | ||
60 | + | ||
61 | + @Override | ||
62 | + public SearchApiResult aggregations(Map<String, String> paramMap) { | ||
63 | + try { | ||
64 | + // 1、添加默认参数 | ||
65 | + this.addParamsToParamMap(paramMap); | ||
66 | + // 2、返回聚合结果 | ||
67 | + List<IAggregation> aggregation = sceneSelectionsService.getReducePriceAggregations(paramMap); | ||
68 | + return sceneSelectionsService.aggregations(paramMap, aggregation); | ||
69 | + } catch (Exception e) { | ||
70 | + logger.error("[func=NewArrivalAggregations][params=" + paramMap + "]", e); | ||
71 | + return SearchApiResultUtils.errorSearchApiResult("NewArrivalAggregations", paramMap, e); | ||
72 | + } | ||
73 | + } | ||
74 | + | ||
75 | +} |
1 | package com.yoho.search.service.scene; | 1 | package com.yoho.search.service.scene; |
2 | 2 | ||
3 | +import java.util.List; | ||
3 | import java.util.Map; | 4 | import java.util.Map; |
4 | 5 | ||
5 | import org.apache.commons.lang3.StringUtils; | 6 | import org.apache.commons.lang3.StringUtils; |
@@ -10,6 +11,7 @@ import org.springframework.stereotype.Service; | @@ -10,6 +11,7 @@ import org.springframework.stereotype.Service; | ||
10 | 11 | ||
11 | import com.yoho.search.base.utils.SearchPageIdDefine; | 12 | import com.yoho.search.base.utils.SearchPageIdDefine; |
12 | import com.yoho.search.common.utils.SearchApiResultUtils; | 13 | import com.yoho.search.common.utils.SearchApiResultUtils; |
14 | +import com.yoho.search.core.es.agg.IAggregation; | ||
13 | import com.yoho.search.models.SearchApiResult; | 15 | import com.yoho.search.models.SearchApiResult; |
14 | import com.yoho.search.service.base.SearchRequestParams; | 16 | import com.yoho.search.service.base.SearchRequestParams; |
15 | import com.yoho.search.service.scene.common.AbstractSceneService; | 17 | import com.yoho.search.service.scene.common.AbstractSceneService; |
@@ -69,4 +71,21 @@ public class ShopSceneService extends AbstractSceneService { | @@ -69,4 +71,21 @@ public class ShopSceneService extends AbstractSceneService { | ||
69 | return SearchApiResultUtils.errorSearchApiResult("ShopAggregations", paramMap, e); | 71 | return SearchApiResultUtils.errorSearchApiResult("ShopAggregations", paramMap, e); |
70 | } | 72 | } |
71 | } | 73 | } |
74 | + | ||
75 | + public SearchApiResult oldAggregations(Map<String, String> paramMap) { | ||
76 | + try { | ||
77 | + // 0、参数校验 | ||
78 | + if (StringUtils.isBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_SHOP))) { | ||
79 | + return new SearchApiResult().setCode(400).setMessage("请传shop参数"); | ||
80 | + } | ||
81 | + // 1、添加默认参数 | ||
82 | + this.addParamsToParamMap(paramMap); | ||
83 | + // 2、返回聚合结果 | ||
84 | + List<IAggregation> aggregations = sceneSelectionsService.getShopOldAggregations(paramMap); | ||
85 | + return sceneSelectionsService.aggregations(paramMap, aggregations); | ||
86 | + } catch (Exception e) { | ||
87 | + logger.error("[func=ShopAggregations][params=" + paramMap + "]", e); | ||
88 | + return SearchApiResultUtils.errorSearchApiResult("ShopAggregations", paramMap, e); | ||
89 | + } | ||
90 | + } | ||
72 | } | 91 | } |
@@ -28,7 +28,7 @@ public abstract class AbstractSceneService { | @@ -28,7 +28,7 @@ public abstract class AbstractSceneService { | ||
28 | paramMap.put(SearchRequestParams.PARAM_SEARCH_AGG_WITH_PARAM_BRAND, "Y");// 聚合时使用参数中自带的参数 | 28 | paramMap.put(SearchRequestParams.PARAM_SEARCH_AGG_WITH_PARAM_BRAND, "Y");// 聚合时使用参数中自带的参数 |
29 | // paramMap.put("sale", "Y");// 没用的参数 | 29 | // paramMap.put("sale", "Y");// 没用的参数 |
30 | } | 30 | } |
31 | - | 31 | + |
32 | protected int getPage(Map<String, String> paramMap) { | 32 | protected int getPage(Map<String, String> paramMap) { |
33 | int page = StringUtils.isBlank(paramMap.get("page")) ? 1 : Integer.parseInt(paramMap.get("page")); | 33 | int page = StringUtils.isBlank(paramMap.get("page")) ? 1 : Integer.parseInt(paramMap.get("page")); |
34 | return page; | 34 | return page; |
1 | package com.yoho.search.service.scene.common; | 1 | package com.yoho.search.service.scene.common; |
2 | 2 | ||
3 | +import java.util.ArrayList; | ||
4 | +import java.util.HashMap; | ||
5 | +import java.util.List; | ||
6 | +import java.util.Map; | ||
7 | +import java.util.concurrent.CompletableFuture; | ||
8 | +import java.util.concurrent.ExecutorService; | ||
9 | +import java.util.concurrent.Executors; | ||
10 | + | ||
11 | +import org.elasticsearch.index.query.BoolQueryBuilder; | ||
12 | +import org.elasticsearch.search.aggregations.AbstractAggregationBuilder; | ||
13 | +import org.elasticsearch.search.aggregations.Aggregation; | ||
14 | +import org.slf4j.Logger; | ||
15 | +import org.slf4j.LoggerFactory; | ||
16 | +import org.springframework.beans.factory.annotation.Autowired; | ||
17 | +import org.springframework.stereotype.Service; | ||
18 | + | ||
3 | import com.alibaba.fastjson.JSONArray; | 19 | import com.alibaba.fastjson.JSONArray; |
4 | import com.alibaba.fastjson.JSONObject; | 20 | import com.alibaba.fastjson.JSONObject; |
5 | import com.yoho.search.base.utils.ISearchConstants; | 21 | import com.yoho.search.base.utils.ISearchConstants; |
@@ -13,21 +29,6 @@ import com.yoho.search.service.aggregations.impls.AggregationFactoryService; | @@ -13,21 +29,6 @@ import com.yoho.search.service.aggregations.impls.AggregationFactoryService; | ||
13 | import com.yoho.search.service.base.SearchCommonService; | 29 | import com.yoho.search.service.base.SearchCommonService; |
14 | import com.yoho.search.service.helper.SearchParamHelper; | 30 | import com.yoho.search.service.helper.SearchParamHelper; |
15 | import com.yoho.search.service.service.IAggRecommendService; | 31 | import com.yoho.search.service.service.IAggRecommendService; |
16 | -import org.elasticsearch.index.query.BoolQueryBuilder; | ||
17 | -import org.elasticsearch.search.aggregations.AbstractAggregationBuilder; | ||
18 | -import org.elasticsearch.search.aggregations.Aggregation; | ||
19 | -import org.slf4j.Logger; | ||
20 | -import org.slf4j.LoggerFactory; | ||
21 | -import org.springframework.beans.factory.annotation.Autowired; | ||
22 | -import org.springframework.stereotype.Service; | ||
23 | - | ||
24 | -import java.util.ArrayList; | ||
25 | -import java.util.HashMap; | ||
26 | -import java.util.List; | ||
27 | -import java.util.Map; | ||
28 | -import java.util.concurrent.CompletableFuture; | ||
29 | -import java.util.concurrent.ExecutorService; | ||
30 | -import java.util.concurrent.Executors; | ||
31 | 32 | ||
32 | @Service | 33 | @Service |
33 | public class SceneSelectionsService extends AbstractCacheAbleService { | 34 | public class SceneSelectionsService extends AbstractCacheAbleService { |
@@ -43,7 +44,6 @@ public class SceneSelectionsService extends AbstractCacheAbleService { | @@ -43,7 +44,6 @@ public class SceneSelectionsService extends AbstractCacheAbleService { | ||
43 | @Autowired | 44 | @Autowired |
44 | private IAggRecommendService aggRecommendService; | 45 | private IAggRecommendService aggRecommendService; |
45 | 46 | ||
46 | - | ||
47 | @Override | 47 | @Override |
48 | public SearchCache getSearchCache() { | 48 | public SearchCache getSearchCache() { |
49 | return searchCacheFactory.getSelectionsForAppCache(); | 49 | return searchCacheFactory.getSelectionsForAppCache(); |
@@ -121,20 +121,46 @@ public class SceneSelectionsService extends AbstractCacheAbleService { | @@ -121,20 +121,46 @@ public class SceneSelectionsService extends AbstractCacheAbleService { | ||
121 | } | 121 | } |
122 | 122 | ||
123 | /** | 123 | /** |
124 | - * 店铺、新频到着的筛选项列表 | 124 | + * 最新降价的筛选项 |
125 | * | 125 | * |
126 | * @param paramMap | 126 | * @param paramMap |
127 | * @return | 127 | * @return |
128 | */ | 128 | */ |
129 | - @SuppressWarnings("unused") | ||
130 | - private List<IAggregation> getRNAggregations(Map<String, String> paramMap) { | 129 | + public List<IAggregation> getReducePriceAggregations(Map<String, String> paramMap) { |
131 | List<IAggregation> aggregations = new ArrayList<>(); | 130 | List<IAggregation> aggregations = new ArrayList<>(); |
132 | // 1)性别 | 131 | // 1)性别 |
133 | aggregations.add(aggregationFactoryService.getGenderNewAggregation()); | 132 | aggregations.add(aggregationFactoryService.getGenderNewAggregation()); |
134 | - // 2)品类 | 133 | + // 2)品牌 |
134 | + aggregations.add(aggregationFactoryService.getBrandAggregation(paramMap)); | ||
135 | + // 3)品类 | ||
135 | aggregations.add(aggregationFactoryService.getSortGroupAggregation(paramMap)); | 136 | aggregations.add(aggregationFactoryService.getSortGroupAggregation(paramMap)); |
136 | - // 3)品牌 | 137 | + // 4)颜色 |
138 | + aggregations.add(aggregationFactoryService.getColorAggregation(paramMap)); | ||
139 | + // 5)尺码 | ||
140 | + aggregations.add(aggregationFactoryService.getSizeAggregation()); | ||
141 | + // 6)价格 | ||
142 | + aggregations.add(aggregationFactoryService.getPriceAggregation()); | ||
143 | + // 7)折扣 | ||
144 | + aggregations.add(aggregationFactoryService.getDiscountAggregation()); | ||
145 | + // 8)风格 | ||
146 | + aggregations.add(aggregationFactoryService.getStyleAggregation(paramMap)); | ||
147 | + return aggregations; | ||
148 | + } | ||
149 | + | ||
150 | + /** | ||
151 | + * 老的店铺的筛选项 | ||
152 | + * | ||
153 | + * @param paramMap | ||
154 | + * @return | ||
155 | + */ | ||
156 | + public List<IAggregation> getShopOldAggregations(Map<String, String> paramMap) { | ||
157 | + List<IAggregation> aggregations = new ArrayList<>(); | ||
158 | + // 1)性别 | ||
159 | + aggregations.add(aggregationFactoryService.getGenderNewAggregation()); | ||
160 | + // 2)品牌 | ||
137 | aggregations.add(aggregationFactoryService.getBrandAggregation(paramMap)); | 161 | aggregations.add(aggregationFactoryService.getBrandAggregation(paramMap)); |
162 | + // 3)品类 | ||
163 | + aggregations.add(aggregationFactoryService.getSortGroupAggregation(paramMap)); | ||
138 | // 4)颜色 | 164 | // 4)颜色 |
139 | aggregations.add(aggregationFactoryService.getColorAggregation(paramMap)); | 165 | aggregations.add(aggregationFactoryService.getColorAggregation(paramMap)); |
140 | // 5)尺码 | 166 | // 5)尺码 |
@@ -143,6 +169,8 @@ public class SceneSelectionsService extends AbstractCacheAbleService { | @@ -143,6 +169,8 @@ public class SceneSelectionsService extends AbstractCacheAbleService { | ||
143 | aggregations.add(aggregationFactoryService.getPriceAggregation()); | 169 | aggregations.add(aggregationFactoryService.getPriceAggregation()); |
144 | // 7)折扣 | 170 | // 7)折扣 |
145 | aggregations.add(aggregationFactoryService.getDiscountAggregation()); | 171 | aggregations.add(aggregationFactoryService.getDiscountAggregation()); |
172 | + // 8)风格 | ||
173 | + aggregations.add(aggregationFactoryService.getStyleAggregation(paramMap)); | ||
146 | return aggregations; | 174 | return aggregations; |
147 | } | 175 | } |
148 | 176 | ||
@@ -208,13 +236,13 @@ public class SceneSelectionsService extends AbstractCacheAbleService { | @@ -208,13 +236,13 @@ public class SceneSelectionsService extends AbstractCacheAbleService { | ||
208 | return new JSONObject(); | 236 | return new JSONObject(); |
209 | } | 237 | } |
210 | } | 238 | } |
211 | - | 239 | + |
212 | private JSONArray getRecommendBrands(Map<String, String> paramMap, BoolQueryBuilder mustFilter) { | 240 | private JSONArray getRecommendBrands(Map<String, String> paramMap, BoolQueryBuilder mustFilter) { |
213 | Map<String, String> newParamMap = new HashMap<String, String>(paramMap); | 241 | Map<String, String> newParamMap = new HashMap<String, String>(paramMap); |
214 | SearchApiResult searchApiResult = aggRecommendService.aggRecommendBrand(newParamMap, mustFilter); | 242 | SearchApiResult searchApiResult = aggRecommendService.aggRecommendBrand(newParamMap, mustFilter); |
215 | return (JSONArray) searchApiResult.getData(); | 243 | return (JSONArray) searchApiResult.getData(); |
216 | } | 244 | } |
217 | - | 245 | + |
218 | public SearchApiResult aggregations(Map<String, String> paramMap) throws Exception { | 246 | public SearchApiResult aggregations(Map<String, String> paramMap) throws Exception { |
219 | List<IAggregation> commonAggregations = this.getCommonAggregations(paramMap); | 247 | List<IAggregation> commonAggregations = this.getCommonAggregations(paramMap); |
220 | return this.aggregations(paramMap, commonAggregations, null); | 248 | return this.aggregations(paramMap, commonAggregations, null); |
-
Please register or login to post a comment