Showing
3 changed files
with
67 additions
and
16 deletions
@@ -38,7 +38,7 @@ public class CsSearchResourceIndexBaseService { | @@ -38,7 +38,7 @@ public class CsSearchResourceIndexBaseService { | ||
38 | @Autowired | 38 | @Autowired |
39 | private SearchCommonService searchCommonService; | 39 | private SearchCommonService searchCommonService; |
40 | 40 | ||
41 | - //Guava Cache | 41 | + // Guava Cache |
42 | private LoadingCache<String, List<Map<String, Object>>> salesCategorySearchResourceCache = CacheBuilder.newBuilder() | 42 | private LoadingCache<String, List<Map<String, Object>>> salesCategorySearchResourceCache = CacheBuilder.newBuilder() |
43 | .maximumSize(100).expireAfterWrite(3, TimeUnit.MINUTES).build(new CacheLoader<String, List<Map<String, Object>>>() { | 43 | .maximumSize(100).expireAfterWrite(3, TimeUnit.MINUTES).build(new CacheLoader<String, List<Map<String, Object>>>() { |
44 | public List<Map<String, Object>> load(String key) { | 44 | public List<Map<String, Object>> load(String key) { |
@@ -46,7 +46,7 @@ public class CsSearchResourceIndexBaseService { | @@ -46,7 +46,7 @@ public class CsSearchResourceIndexBaseService { | ||
46 | } | 46 | } |
47 | }); | 47 | }); |
48 | 48 | ||
49 | - //Guava Cache | 49 | + // Guava Cache |
50 | private LoadingCache<String, List<Map<String, Object>>> ufoSearchResourceCache = CacheBuilder.newBuilder() | 50 | private LoadingCache<String, List<Map<String, Object>>> ufoSearchResourceCache = CacheBuilder.newBuilder() |
51 | .maximumSize(100).expireAfterWrite(3, TimeUnit.MINUTES).build(new CacheLoader<String, List<Map<String, Object>>>() { | 51 | .maximumSize(100).expireAfterWrite(3, TimeUnit.MINUTES).build(new CacheLoader<String, List<Map<String, Object>>>() { |
52 | public List<Map<String, Object>> load(String key) { | 52 | public List<Map<String, Object>> load(String key) { |
@@ -54,7 +54,7 @@ public class CsSearchResourceIndexBaseService { | @@ -54,7 +54,7 @@ public class CsSearchResourceIndexBaseService { | ||
54 | } | 54 | } |
55 | }); | 55 | }); |
56 | 56 | ||
57 | - //Guava Cache | 57 | + // Guava Cache |
58 | private LoadingCache<String, List<Map<String, Object>>> newArrivalSearchResourceCache = CacheBuilder.newBuilder() | 58 | private LoadingCache<String, List<Map<String, Object>>> newArrivalSearchResourceCache = CacheBuilder.newBuilder() |
59 | .maximumSize(100).expireAfterWrite(3, TimeUnit.MINUTES).build(new CacheLoader<String, List<Map<String, Object>>>() { | 59 | .maximumSize(100).expireAfterWrite(3, TimeUnit.MINUTES).build(new CacheLoader<String, List<Map<String, Object>>>() { |
60 | public List<Map<String, Object>> load(String key) { | 60 | public List<Map<String, Object>> load(String key) { |
@@ -62,7 +62,17 @@ public class CsSearchResourceIndexBaseService { | @@ -62,7 +62,17 @@ public class CsSearchResourceIndexBaseService { | ||
62 | } | 62 | } |
63 | }); | 63 | }); |
64 | 64 | ||
65 | - //获取销售类目当前生效的全部资源位之停车 | 65 | + |
66 | + // Guava Cache | ||
67 | + private LoadingCache<String, List<Map<String, Object>>> firstPageSearchResourceCache = CacheBuilder.newBuilder() | ||
68 | + .maximumSize(100).expireAfterWrite(3, TimeUnit.MINUTES).build(new CacheLoader<String, List<Map<String, Object>>>() { | ||
69 | + public List<Map<String, Object>> load(String key) { | ||
70 | + return queryValidValidCsSearchResourceFromEs(Arrays.asList(5),100); | ||
71 | + } | ||
72 | + }); | ||
73 | + | ||
74 | + | ||
75 | + // 获取销售类目当前生效的全部资源位之停车 | ||
66 | public List<Map<String, Object>> querySalesCategoryCsSearchResource() { | 76 | public List<Map<String, Object>> querySalesCategoryCsSearchResource() { |
67 | try { | 77 | try { |
68 | return salesCategorySearchResourceCache.get(CACHE_KEY); | 78 | return salesCategorySearchResourceCache.get(CACHE_KEY); |
@@ -72,7 +82,7 @@ public class CsSearchResourceIndexBaseService { | @@ -72,7 +82,7 @@ public class CsSearchResourceIndexBaseService { | ||
72 | } | 82 | } |
73 | } | 83 | } |
74 | 84 | ||
75 | - //获取UFO目当前生效的全部资源位之停车 | 85 | + // 获取UFO目当前生效的全部资源位之停车 |
76 | public List<Map<String, Object>> queryUfoCsSearchResources() { | 86 | public List<Map<String, Object>> queryUfoCsSearchResources() { |
77 | try { | 87 | try { |
78 | return ufoSearchResourceCache.get(CACHE_KEY); | 88 | return ufoSearchResourceCache.get(CACHE_KEY); |
@@ -82,7 +92,7 @@ public class CsSearchResourceIndexBaseService { | @@ -82,7 +92,7 @@ public class CsSearchResourceIndexBaseService { | ||
82 | } | 92 | } |
83 | } | 93 | } |
84 | 94 | ||
85 | - //获取新品到着的直通车 | 95 | + // 获取新品到着的直通车 |
86 | public List<Map<String, Object>> queryNewArrivalCsSearchResources() { | 96 | public List<Map<String, Object>> queryNewArrivalCsSearchResources() { |
87 | try { | 97 | try { |
88 | return newArrivalSearchResourceCache.get(CACHE_KEY); | 98 | return newArrivalSearchResourceCache.get(CACHE_KEY); |
@@ -92,6 +102,16 @@ public class CsSearchResourceIndexBaseService { | @@ -92,6 +102,16 @@ public class CsSearchResourceIndexBaseService { | ||
92 | } | 102 | } |
93 | } | 103 | } |
94 | 104 | ||
105 | + // 获取首页猜你喜欢的直通车 | ||
106 | + public List<Map<String,Object>> queryFirstPageSearchResource() { | ||
107 | + try { | ||
108 | + return firstPageSearchResourceCache.get(CACHE_KEY); | ||
109 | + } catch (Exception e) { | ||
110 | + logger.error(e.getMessage(), e); | ||
111 | + return new ArrayList<>(0); | ||
112 | + } | ||
113 | + } | ||
114 | + | ||
95 | private List<Map<String, Object>> queryValidValidCsSearchResourceFromEs(List<Integer> resourceTypes,int limit) { | 115 | private List<Map<String, Object>> queryValidValidCsSearchResourceFromEs(List<Integer> resourceTypes,int limit) { |
96 | try { | 116 | try { |
97 | SearchParam searchParam = new SearchParam(); | 117 | SearchParam searchParam = new SearchParam(); |
@@ -147,4 +167,5 @@ public class CsSearchResourceIndexBaseService { | @@ -147,4 +167,5 @@ public class CsSearchResourceIndexBaseService { | ||
147 | } | 167 | } |
148 | 168 | ||
149 | 169 | ||
170 | + | ||
150 | } | 171 | } |
@@ -39,7 +39,7 @@ public class CsSearchResourceService { | @@ -39,7 +39,7 @@ public class CsSearchResourceService { | ||
39 | @Autowired | 39 | @Autowired |
40 | private SearchDynamicConfigService searchDynamicConfigService; | 40 | private SearchDynamicConfigService searchDynamicConfigService; |
41 | 41 | ||
42 | - //处理品类页的资源位直通车 | 42 | + // 处理品类页的资源位直通车 |
43 | public List<Map<String, Object>> querySortSearchResource(JSONObject productListData, Map<String, String> paramMap) { | 43 | public List<Map<String, Object>> querySortSearchResource(JSONObject productListData, Map<String, String> paramMap) { |
44 | try { | 44 | try { |
45 | //0、判断是否开启 | 45 | //0、判断是否开启 |
@@ -96,6 +96,27 @@ public class CsSearchResourceService { | @@ -96,6 +96,27 @@ public class CsSearchResourceService { | ||
96 | } | 96 | } |
97 | } | 97 | } |
98 | 98 | ||
99 | + //处理首页猜你喜欢的资源位直通车 | ||
100 | + public List<Map<String, Object>> queryFirstPageSearchResource(JSONObject productListData, Map<String, String> paramMap) { | ||
101 | + try { | ||
102 | + // 1、校验 productListData | ||
103 | + if (productListData == null || productListData.get("product_list") == null) { | ||
104 | + return new ArrayList<>(); | ||
105 | + } | ||
106 | + List productList = (List) productListData.get("product_list"); | ||
107 | + List<Map<String, Object>> searchRsesourceList = csSearchResourceIndexBaseService.queryFirstPageSearchResource(); | ||
108 | + | ||
109 | + // 2、执行分页截取 | ||
110 | + int page = MapUtils.getIntValue(paramMap, "page", 1); | ||
111 | + int pageSize = MapUtils.getIntValue(paramMap, "viewNum", 10); | ||
112 | + return this.doPageSearchResource(searchRsesourceList, productList, page, pageSize); | ||
113 | + } catch (Exception e) { | ||
114 | + logger.error(e.getMessage(), e); | ||
115 | + return new ArrayList<>(); | ||
116 | + } | ||
117 | + } | ||
118 | + | ||
119 | + | ||
99 | 120 | ||
100 | //处理UFO首页的资源位直通车 | 121 | //处理UFO首页的资源位直通车 |
101 | public List<Map<String, Object>> queryUfoCsSearchResource(JSONObject productListData, int page, int viewNum) { | 122 | public List<Map<String, Object>> queryUfoCsSearchResource(JSONObject productListData, int page, int viewNum) { |
@@ -112,7 +133,7 @@ public class CsSearchResourceService { | @@ -112,7 +133,7 @@ public class CsSearchResourceService { | ||
112 | } | 133 | } |
113 | } | 134 | } |
114 | 135 | ||
115 | - //分页处理searchResourceList | 136 | + // 分页处理searchResourceList |
116 | private List<Map<String, Object>> doPageSearchResource(List<Map<String, Object>> searchResourceList, List<?> productList, int page, int viewNum) { | 137 | private List<Map<String, Object>> doPageSearchResource(List<Map<String, Object>> searchResourceList, List<?> productList, int page, int viewNum) { |
117 | if (CollectionUtils.isEmpty(searchResourceList) || productList == null || productList.isEmpty()) { | 138 | if (CollectionUtils.isEmpty(searchResourceList) || productList == null || productList.isEmpty()) { |
118 | return new ArrayList<>(); | 139 | return new ArrayList<>(); |
@@ -6,6 +6,7 @@ import com.yoho.search.common.SearchRequestParams; | @@ -6,6 +6,7 @@ import com.yoho.search.common.SearchRequestParams; | ||
6 | import com.yoho.search.common.utils.SearchApiResultUtils; | 6 | import com.yoho.search.common.utils.SearchApiResultUtils; |
7 | import com.yoho.search.core.es.utils.PageUtils; | 7 | import com.yoho.search.core.es.utils.PageUtils; |
8 | import com.yoho.search.models.SearchApiResult; | 8 | import com.yoho.search.models.SearchApiResult; |
9 | +import com.yoho.search.service.scene.general.CsSearchResourceService; | ||
9 | import com.yoho.search.service.scene.pages.entrance.ProductListSwitchService; | 10 | import com.yoho.search.service.scene.pages.entrance.ProductListSwitchService; |
10 | import org.apache.commons.collections.MapUtils; | 11 | import org.apache.commons.collections.MapUtils; |
11 | import org.slf4j.Logger; | 12 | import org.slf4j.Logger; |
@@ -22,6 +23,8 @@ public class FirstPageSceneService extends AbstractPageSceneService { | @@ -22,6 +23,8 @@ public class FirstPageSceneService extends AbstractPageSceneService { | ||
22 | 23 | ||
23 | @Autowired | 24 | @Autowired |
24 | private ProductListSwitchService productListSwitchService; | 25 | private ProductListSwitchService productListSwitchService; |
26 | + @Autowired | ||
27 | + private CsSearchResourceService csSearchResourceService; | ||
25 | 28 | ||
26 | @Override | 29 | @Override |
27 | public String pageId() { | 30 | public String pageId() { |
@@ -32,8 +35,8 @@ public class FirstPageSceneService extends AbstractPageSceneService { | @@ -32,8 +35,8 @@ public class FirstPageSceneService extends AbstractPageSceneService { | ||
32 | public void addParamsToParamMap(Map<String, String> paramMap) { | 35 | public void addParamsToParamMap(Map<String, String> paramMap) { |
33 | super.addDefaultParamsToParamMap(paramMap); | 36 | super.addDefaultParamsToParamMap(paramMap); |
34 | //super.filterNotNormalToMap(paramMap); | 37 | //super.filterNotNormalToMap(paramMap); |
35 | - paramMap.put(SearchRequestParams.PARAM_SEARCH_REC_TYPE,"1"); | ||
36 | - paramMap.put(SearchRequestParams.PARAM_SEARCH_CONTAIN_UFO,"Y"); | 38 | + paramMap.put(SearchRequestParams.PARAM_SEARCH_REC_TYPE, "1"); |
39 | + paramMap.put(SearchRequestParams.PARAM_SEARCH_CONTAIN_UFO, "Y"); | ||
37 | } | 40 | } |
38 | 41 | ||
39 | @Override | 42 | @Override |
@@ -41,15 +44,21 @@ public class FirstPageSceneService extends AbstractPageSceneService { | @@ -41,15 +44,21 @@ public class FirstPageSceneService extends AbstractPageSceneService { | ||
41 | try { | 44 | try { |
42 | // 1、添加默认参数 | 45 | // 1、添加默认参数 |
43 | this.addParamsToParamMap(paramMap); | 46 | this.addParamsToParamMap(paramMap); |
47 | + | ||
44 | // 2、返回商品列表 | 48 | // 2、返回商品列表 |
45 | SearchApiResult searchApiResult = productListSwitchService.productList(this.newParamMap(paramMap)); | 49 | SearchApiResult searchApiResult = productListSwitchService.productList(this.newParamMap(paramMap)); |
46 | - JSONObject jsonObject = (JSONObject) searchApiResult.getData(); | ||
47 | - // 3、限制最大返回条数为200条 | ||
48 | - long total = Math.min(MapUtils.getIntValue(jsonObject, "total", 0), 200L); | ||
49 | - int page_size = MapUtils.getIntValue(jsonObject, "page_size", 0); | ||
50 | - jsonObject.put("total", total); | ||
51 | - jsonObject.put("page_total", PageUtils.getTotalPage(total,page_size)); | 50 | + JSONObject data = (JSONObject) searchApiResult.getData(); |
51 | + | ||
52 | + // 3、获取首页资源位直通车 | ||
53 | + data.put(SEARCH_RESOURCE_LIST, csSearchResourceService.queryFirstPageSearchResource(data, paramMap));//search_resource_list | ||
54 | + | ||
55 | + // 4、限制最大返回条数为200条 | ||
56 | + long total = Math.min(MapUtils.getIntValue(data, "total", 0), 200L); | ||
57 | + int page_size = MapUtils.getIntValue(data, "page_size", 0); | ||
58 | + data.put("total", total); | ||
59 | + data.put("page_total", PageUtils.getTotalPage(total, page_size)); | ||
52 | return searchApiResult; | 60 | return searchApiResult; |
61 | + | ||
53 | } catch (Exception e) { | 62 | } catch (Exception e) { |
54 | return SearchApiResultUtils.errorSearchApiResult(logger, paramMap, e); | 63 | return SearchApiResultUtils.errorSearchApiResult(logger, paramMap, e); |
55 | } | 64 | } |
-
Please register or login to post a comment