优化AbstractSceneService
Showing
3 changed files
with
71 additions
and
70 deletions
1 | package com.yoho.search.service.scene.common; | 1 | package com.yoho.search.service.scene.common; |
2 | 2 | ||
3 | -import java.util.HashMap; | ||
4 | -import java.util.Map; | ||
5 | - | ||
6 | -import org.apache.commons.lang.StringUtils; | ||
7 | - | ||
8 | -import com.yoho.search.common.utils.SearchKeyWordUtils; | ||
9 | -import com.yoho.search.models.SearchApiResult; | ||
10 | import com.yoho.search.common.SearchRequestParams; | 3 | import com.yoho.search.common.SearchRequestParams; |
4 | +import com.yoho.search.models.SearchApiResult; | ||
5 | + | ||
6 | +import java.util.Map; | ||
11 | 7 | ||
12 | -public abstract class AbstractSceneService { | 8 | +public abstract class AbstractSceneService extends BaseSceneService{ |
13 | 9 | ||
14 | protected static final String RECOMMEND_PROMOTION_LIST = "recommend_promotion_list"; | 10 | protected static final String RECOMMEND_PROMOTION_LIST = "recommend_promotion_list"; |
15 | protected static final String CUSTOMIZE_TAG_LIST = "customize_tag"; | 11 | protected static final String CUSTOMIZE_TAG_LIST = "customize_tag"; |
16 | protected static final String STANDARD = "standard"; | 12 | protected static final String STANDARD = "standard"; |
17 | 13 | ||
18 | - protected Map<String, String> newParamMap(Map<String, String> paramMap) { | ||
19 | - return new HashMap<>(paramMap); | ||
20 | - } | ||
21 | - | ||
22 | - /** | ||
23 | - * 去除非正常商品的显示 | ||
24 | - * @param paramMap | ||
25 | - */ | ||
26 | - protected void filterNotNormalToMap(Map<String, String> paramMap) { | ||
27 | - paramMap.put(SearchRequestParams.PARAM_SEARCH_ISLIMITED, "N");// 不支持限定 | ||
28 | - paramMap.put(SearchRequestParams.PARAM_SEARCH_CONTAIN_SECKILL, "N");// 不支持秒杀 | ||
29 | - paramMap.put(SearchRequestParams.PARAM_SEARCH_CONTAIN_GLOBAL, "N");// 不支持全球购 | ||
30 | - paramMap.put(SearchRequestParams.PARAM_SEARCH_ISADVANCE, "N");// 不支持预售 | ||
31 | - paramMap.put(SearchRequestParams.PARAM_SEARCH_BUNDLETYPE, "0");// 不支持套餐 | ||
32 | - paramMap.put(SearchRequestParams.PARAM_SEARCH_ISLIMITEDBUY, "N");// 不支持限购 | ||
33 | - paramMap.put(SearchRequestParams.PARAM_SEARCH_ISDESPOSITADVANCE, "N");// 不支持定金预售 | ||
34 | - paramMap.put(SearchRequestParams.PARAM_SEARCH_ISLIMITTIMEADVANCE, "N");// 不支持定金促销 | ||
35 | - } | ||
36 | - | ||
37 | /** | 14 | /** |
38 | * 场景化的默认参数 | 15 | * 场景化的默认参数 |
39 | * | 16 | * |
40 | * @param paramMap | 17 | * @param paramMap |
41 | */ | 18 | */ |
42 | protected void addDefaultParamsToParamMap(Map<String, String> paramMap) { | 19 | protected void addDefaultParamsToParamMap(Map<String, String> paramMap) { |
20 | + super.addDefaultParamsToParamMap(paramMap); | ||
43 | paramMap.put(SearchRequestParams.PARAM_SEARCH_PAGEID, this.pageId());// 根据场景划分的页面id | 21 | paramMap.put(SearchRequestParams.PARAM_SEARCH_PAGEID, this.pageId());// 根据场景划分的页面id |
44 | - paramMap.put(SearchRequestParams.PARAM_SEARCH_GLOBAL_FILTER_BRAND, "Y");// 页面屏蔽 | ||
45 | - paramMap.put(SearchRequestParams.PARAM_SEARCH_STATUS, "1");// 上架 | ||
46 | - paramMap.put(SearchRequestParams.PARAM_SEARCH_STOCKNUM, "1");// 有库存 | ||
47 | - paramMap.put(SearchRequestParams.PARAM_SEARCH_SHOWSOLDOUT, "1");// 显示延期显示的商品 | ||
48 | - paramMap.put(SearchRequestParams.PARAM_SEARCH_ISOUTLETS, "2");// 非奥莱 | ||
49 | - paramMap.put(SearchRequestParams.PARAM_SEARCH_ATTRIBUTE_NOT, "2");// 非赠品 | ||
50 | - paramMap.put(SearchRequestParams.PARAM_SEARCH_NEEDSMALLSORT, "1");// 品类聚合时带上小分类 | ||
51 | - paramMap.put(SearchRequestParams.PARAM_SEARCH_AGG_WITH_PARAM_BRAND, "Y");// 聚合时使用参数中自带的参数 | ||
52 | - // 关键词反转码 | ||
53 | - String keyword = SearchKeyWordUtils.getParamKeyword(paramMap, SearchRequestParams.PARAM_SEARCH_QUERY);// 转码 | ||
54 | - if (!StringUtils.isBlank(keyword)) { | ||
55 | - paramMap.put(SearchRequestParams.PARAM_SEARCH_QUERY, keyword); | ||
56 | - paramMap.put("is_encode", "0"); | ||
57 | - } | ||
58 | - } | ||
59 | - | ||
60 | - protected int getPage(Map<String, String> paramMap) { | ||
61 | - int page = StringUtils.isBlank(paramMap.get("page")) ? 1 : Integer.parseInt(paramMap.get("page")); | ||
62 | - return page; | ||
63 | } | 22 | } |
64 | 23 | ||
65 | public abstract void addParamsToParamMap(Map<String, String> paramMap); | 24 | public abstract void addParamsToParamMap(Map<String, String> paramMap); |
1 | +package com.yoho.search.service.scene.common; | ||
2 | + | ||
3 | +import com.yoho.search.common.SearchRequestParams; | ||
4 | +import com.yoho.search.common.utils.SearchKeyWordUtils; | ||
5 | +import org.apache.commons.lang.StringUtils; | ||
6 | + | ||
7 | +import java.util.HashMap; | ||
8 | +import java.util.Map; | ||
9 | + | ||
10 | +public class BaseSceneService { | ||
11 | + | ||
12 | + protected Map<String, String> newParamMap(Map<String, String> paramMap) { | ||
13 | + return new HashMap<>(paramMap); | ||
14 | + } | ||
15 | + | ||
16 | + /** | ||
17 | + * 场景化的默认参数 | ||
18 | + * | ||
19 | + * @param paramMap | ||
20 | + */ | ||
21 | + protected void addDefaultParamsToParamMap(Map<String, String> paramMap) { | ||
22 | + paramMap.put(SearchRequestParams.PARAM_SEARCH_GLOBAL_FILTER_BRAND, "Y");// 页面屏蔽 | ||
23 | + paramMap.put(SearchRequestParams.PARAM_SEARCH_STATUS, "1");// 上架 | ||
24 | + paramMap.put(SearchRequestParams.PARAM_SEARCH_STOCKNUM, "1");// 有库存 | ||
25 | + paramMap.put(SearchRequestParams.PARAM_SEARCH_SHOWSOLDOUT, "1");// 显示延期显示的商品 | ||
26 | + paramMap.put(SearchRequestParams.PARAM_SEARCH_ISOUTLETS, "2");// 非奥莱 | ||
27 | + paramMap.put(SearchRequestParams.PARAM_SEARCH_ATTRIBUTE_NOT, "2");// 非赠品 | ||
28 | + paramMap.put(SearchRequestParams.PARAM_SEARCH_NEEDSMALLSORT, "1");// 品类聚合时带上小分类 | ||
29 | + paramMap.put(SearchRequestParams.PARAM_SEARCH_AGG_WITH_PARAM_BRAND, "Y");// 聚合时使用参数中自带的参数 | ||
30 | + // 关键词反转码 | ||
31 | + String keyword = SearchKeyWordUtils.getParamKeyword(paramMap, SearchRequestParams.PARAM_SEARCH_QUERY);// 转码 | ||
32 | + if (!StringUtils.isBlank(keyword)) { | ||
33 | + paramMap.put(SearchRequestParams.PARAM_SEARCH_QUERY, keyword); | ||
34 | + paramMap.put("is_encode", "0"); | ||
35 | + } | ||
36 | + } | ||
37 | + | ||
38 | + /** | ||
39 | + * 去除非正常商品的显示 | ||
40 | + * | ||
41 | + * @param paramMap | ||
42 | + */ | ||
43 | + protected void filterNotNormalToMap(Map<String, String> paramMap) { | ||
44 | + paramMap.put(SearchRequestParams.PARAM_SEARCH_ISLIMITED, "N");// 不支持限定 | ||
45 | + paramMap.put(SearchRequestParams.PARAM_SEARCH_CONTAIN_SECKILL, "N");// 不支持秒杀 | ||
46 | + paramMap.put(SearchRequestParams.PARAM_SEARCH_CONTAIN_GLOBAL, "N");// 不支持全球购 | ||
47 | + paramMap.put(SearchRequestParams.PARAM_SEARCH_ISADVANCE, "N");// 不支持预售 | ||
48 | + paramMap.put(SearchRequestParams.PARAM_SEARCH_BUNDLETYPE, "0");// 不支持套餐 | ||
49 | + paramMap.put(SearchRequestParams.PARAM_SEARCH_ISLIMITEDBUY, "N");// 不支持限购 | ||
50 | + paramMap.put(SearchRequestParams.PARAM_SEARCH_ISDESPOSITADVANCE, "N");// 不支持定金预售 | ||
51 | + paramMap.put(SearchRequestParams.PARAM_SEARCH_ISLIMITTIMEADVANCE, "N");// 不支持定金促销 | ||
52 | + } | ||
53 | + | ||
54 | + protected int getPage(Map<String, String> paramMap) { | ||
55 | + int page = StringUtils.isBlank(paramMap.get("page")) ? 1 : Integer.parseInt(paramMap.get("page")); | ||
56 | + return page; | ||
57 | + } | ||
58 | + | ||
59 | +} |
1 | package com.yoho.search.service.scene.hongren; | 1 | package com.yoho.search.service.scene.hongren; |
2 | 2 | ||
3 | import com.alibaba.fastjson.JSONObject; | 3 | import com.alibaba.fastjson.JSONObject; |
4 | -import com.yoho.search.common.utils.SearchApiResultUtils; | ||
5 | -import com.yoho.search.models.SearchApiResult; | ||
6 | import com.yoho.search.cache.beans.SearchCacheService; | 4 | import com.yoho.search.cache.beans.SearchCacheService; |
7 | import com.yoho.search.common.SearchRequestParams; | 5 | import com.yoho.search.common.SearchRequestParams; |
6 | +import com.yoho.search.common.utils.SearchApiResultUtils; | ||
7 | +import com.yoho.search.models.SearchApiResult; | ||
8 | import com.yoho.search.service.helper.SearchCommonHelper; | 8 | import com.yoho.search.service.helper.SearchCommonHelper; |
9 | import com.yoho.search.service.helper.SearchKeyWordHelper; | 9 | import com.yoho.search.service.helper.SearchKeyWordHelper; |
10 | -import com.yoho.search.service.scene.list.ProductListSwitchService; | ||
11 | -import com.yoho.search.service.scene.common.AbstractSceneService; | ||
12 | import com.yoho.search.service.scene.aggregations.AggregationService; | 10 | import com.yoho.search.service.scene.aggregations.AggregationService; |
11 | +import com.yoho.search.service.scene.common.BaseSceneService; | ||
12 | +import com.yoho.search.service.scene.list.ProductListSwitchService; | ||
13 | import org.apache.commons.lang3.StringUtils; | 13 | import org.apache.commons.lang3.StringUtils; |
14 | import org.springframework.beans.factory.annotation.Autowired; | 14 | import org.springframework.beans.factory.annotation.Autowired; |
15 | import org.springframework.stereotype.Service; | 15 | import org.springframework.stereotype.Service; |
@@ -17,7 +17,7 @@ import org.springframework.stereotype.Service; | @@ -17,7 +17,7 @@ import org.springframework.stereotype.Service; | ||
17 | import java.util.Map; | 17 | import java.util.Map; |
18 | 18 | ||
19 | @Service | 19 | @Service |
20 | -public class SearchHongRenService extends AbstractSceneService { | 20 | +public class SearchHongRenService extends BaseSceneService { |
21 | 21 | ||
22 | @Autowired | 22 | @Autowired |
23 | protected SearchCacheService searchCacheService; | 23 | protected SearchCacheService searchCacheService; |
@@ -50,12 +50,10 @@ public class SearchHongRenService extends AbstractSceneService { | @@ -50,12 +50,10 @@ public class SearchHongRenService extends AbstractSceneService { | ||
50 | return searchApiResult; | 50 | return searchApiResult; |
51 | } | 51 | } |
52 | 52 | ||
53 | - | ||
54 | - | ||
55 | public SearchApiResult productList(Map<String, String> paramMap) { | 53 | public SearchApiResult productList(Map<String, String> paramMap) { |
56 | try { | 54 | try { |
57 | // 1、添加默认参数 | 55 | // 1、添加默认参数 |
58 | - addParamsToParamMap(paramMap); | 56 | + this.addDefaultParamsToParamMap(paramMap); |
59 | return productListSwitchService.productList(newParamMap(paramMap)); | 57 | return productListSwitchService.productList(newParamMap(paramMap)); |
60 | } catch (Exception e) { | 58 | } catch (Exception e) { |
61 | return new SearchApiResult().setData(null).setMessage("hrSortProductList Exception").setCode(500); | 59 | return new SearchApiResult().setData(null).setMessage("hrSortProductList Exception").setCode(500); |
@@ -69,7 +67,7 @@ public class SearchHongRenService extends AbstractSceneService { | @@ -69,7 +67,7 @@ public class SearchHongRenService extends AbstractSceneService { | ||
69 | return new SearchApiResult().setCode(400).setMessage("请传query参数"); | 67 | return new SearchApiResult().setCode(400).setMessage("请传query参数"); |
70 | } | 68 | } |
71 | // 2、添加默认参数 | 69 | // 2、添加默认参数 |
72 | - this.addParamsToParamMap(paramMap); | 70 | + this.addDefaultParamsToParamMap(paramMap); |
73 | // 3、获取商品列表 | 71 | // 3、获取商品列表 |
74 | SearchApiResult productListResult = productListSwitchService.fuzzyProductList(this.newParamMap(paramMap)); | 72 | SearchApiResult productListResult = productListSwitchService.fuzzyProductList(this.newParamMap(paramMap)); |
75 | // 7、模糊搜索页记录关键字对应的查询结果 | 73 | // 7、模糊搜索页记录关键字对应的查询结果 |
@@ -84,20 +82,5 @@ public class SearchHongRenService extends AbstractSceneService { | @@ -84,20 +82,5 @@ public class SearchHongRenService extends AbstractSceneService { | ||
84 | } | 82 | } |
85 | } | 83 | } |
86 | 84 | ||
87 | - @Override | ||
88 | - public void addParamsToParamMap(Map<String, String> paramMap) { | ||
89 | - super.addDefaultParamsToParamMap(paramMap); | ||
90 | - } | ||
91 | - | ||
92 | - @Override | ||
93 | - public String pageId() { | ||
94 | - return null; | ||
95 | - } | ||
96 | - | ||
97 | - @Override | ||
98 | - public SearchApiResult aggregations(Map<String, String> paramMap) { | ||
99 | - return null; | ||
100 | - } | ||
101 | - | ||
102 | 85 | ||
103 | } | 86 | } |
-
Please register or login to post a comment