Merge branch 'zj'
Showing
3 changed files
with
41 additions
and
25 deletions
1 | package com.yoho.search.service.scene; | 1 | package com.yoho.search.service.scene; |
2 | 2 | ||
3 | +import java.util.Collections; | ||
3 | import java.util.List; | 4 | import java.util.List; |
4 | import java.util.Map; | 5 | import java.util.Map; |
5 | import java.util.concurrent.CompletableFuture; | 6 | import java.util.concurrent.CompletableFuture; |
6 | import java.util.concurrent.ExecutorService; | 7 | import java.util.concurrent.ExecutorService; |
7 | import java.util.concurrent.Executors; | 8 | import java.util.concurrent.Executors; |
8 | 9 | ||
10 | +import com.alibaba.fastjson.JSONArray; | ||
9 | import org.apache.commons.lang.StringUtils; | 11 | import org.apache.commons.lang.StringUtils; |
10 | import org.slf4j.Logger; | 12 | import org.slf4j.Logger; |
11 | import org.slf4j.LoggerFactory; | 13 | import org.slf4j.LoggerFactory; |
@@ -88,7 +90,7 @@ public class FuzzySceneService extends AbstractSceneService { | @@ -88,7 +90,7 @@ public class FuzzySceneService extends AbstractSceneService { | ||
88 | // 4、获取自定义标签聚合结果 | 90 | // 4、获取自定义标签聚合结果 |
89 | CompletableFuture<SearchApiResult> customizeTagFuture = CompletableFuture.supplyAsync(() -> sceneAggregationsHelper.secneAggCustomizeTag(this.newParamMap(paramMap)), executor); | 91 | CompletableFuture<SearchApiResult> customizeTagFuture = CompletableFuture.supplyAsync(() -> sceneAggregationsHelper.secneAggCustomizeTag(this.newParamMap(paramMap)), executor); |
90 | // 5、获取促销专题 | 92 | // 5、获取促销专题 |
91 | - CompletableFuture<List<Object>> recommendPromotionFuture = CompletableFuture.supplyAsync(() -> recommendService.recommendPromotion(this.newParamMap(paramMap)), | 93 | + CompletableFuture<SearchApiResult> recommendPromotionFuture = CompletableFuture.supplyAsync(() -> sceneAggregationsHelper.secneAggRecommendPromotion(this.newParamMap(paramMap)), |
92 | executor); | 94 | executor); |
93 | 95 | ||
94 | // 6、加入建议词 | 96 | // 6、加入建议词 |
@@ -103,10 +105,15 @@ public class FuzzySceneService extends AbstractSceneService { | @@ -103,10 +105,15 @@ public class FuzzySceneService extends AbstractSceneService { | ||
103 | } | 105 | } |
104 | // 8、组合结果 | 106 | // 8、组合结果 |
105 | SearchApiResult customizeTags = customizeTagFuture.get(); | 107 | SearchApiResult customizeTags = customizeTagFuture.get(); |
106 | - List<Object> recommendProducts = recommendPromotionFuture.get(); | 108 | + SearchApiResult recommendProducts = recommendPromotionFuture.get(); |
107 | JSONObject dataMap = (JSONObject) productListResult.getData(); | 109 | JSONObject dataMap = (JSONObject) productListResult.getData(); |
108 | dataMap.put(CUSTOMIZE_TAG_LIST, customizeTags.getData()); | 110 | dataMap.put(CUSTOMIZE_TAG_LIST, customizeTags.getData()); |
109 | - dataMap.put(RECOMMEND_PROMOTION_LIST, recommendProducts); | 111 | + |
112 | + if (recommendProducts.getData() == null) { | ||
113 | + dataMap.put(RECOMMEND_PROMOTION_LIST, Collections.EMPTY_LIST); | ||
114 | + } else { | ||
115 | + dataMap.put(RECOMMEND_PROMOTION_LIST, subList(recommendProducts.getData(), StringUtils.isBlank(paramMap.get("page")) ? 1 : Integer.parseInt(paramMap.get("page")), 1)); | ||
116 | + } | ||
110 | return productListResult; | 117 | return productListResult; |
111 | } catch (Exception e) { | 118 | } catch (Exception e) { |
112 | logger.error(e.getMessage(), e); | 119 | logger.error(e.getMessage(), e); |
@@ -171,4 +178,5 @@ public class FuzzySceneService extends AbstractSceneService { | @@ -171,4 +178,5 @@ public class FuzzySceneService extends AbstractSceneService { | ||
171 | // 1.6加入推荐词 | 178 | // 1.6加入推荐词 |
172 | dataMap.put("suggestion", searchRecommendService.recommend(searchResult, paramMap)); | 179 | dataMap.put("suggestion", searchRecommendService.recommend(searchResult, paramMap)); |
173 | } | 180 | } |
181 | + | ||
174 | } | 182 | } |
1 | package com.yoho.search.service.scene; | 1 | package com.yoho.search.service.scene; |
2 | 2 | ||
3 | +import java.util.ArrayList; | ||
3 | import java.util.Collections; | 4 | import java.util.Collections; |
4 | import java.util.List; | 5 | import java.util.List; |
5 | import java.util.Map; | 6 | import java.util.Map; |
@@ -162,24 +163,4 @@ public class SortSceneService extends AbstractSceneService { | @@ -162,24 +163,4 @@ public class SortSceneService extends AbstractSceneService { | ||
162 | } | 163 | } |
163 | } | 164 | } |
164 | 165 | ||
165 | - private List<Object> subList(Object source, int page, int count) { | ||
166 | - try { | ||
167 | - JSONArray sourceList = (JSONArray)source; | ||
168 | - if (sourceList != null && !sourceList.isEmpty()) { | ||
169 | - int start = (page - 1) * count; | ||
170 | - int end = start + count; | ||
171 | - if (start >= sourceList.size()) { | ||
172 | - return Collections.emptyList(); | ||
173 | - } | ||
174 | - if (end > sourceList.size()) { | ||
175 | - end = sourceList.size(); | ||
176 | - } | ||
177 | - return sourceList.subList(start, end); | ||
178 | - } | ||
179 | - } catch (Exception e) { | ||
180 | - return Collections.emptyList(); | ||
181 | - } | ||
182 | - return Collections.emptyList(); | ||
183 | - } | ||
184 | - | ||
185 | } | 166 | } |
1 | package com.yoho.search.service.scene.common; | 1 | package com.yoho.search.service.scene.common; |
2 | 2 | ||
3 | +import com.alibaba.fastjson.JSONArray; | ||
4 | +import com.alibaba.fastjson.JSONObject; | ||
3 | import com.yoho.search.common.utils.SearchKeyWordUtils; | 5 | import com.yoho.search.common.utils.SearchKeyWordUtils; |
4 | import com.yoho.search.models.SearchApiResult; | 6 | import com.yoho.search.models.SearchApiResult; |
5 | import com.yoho.search.service.base.SearchRequestParams; | 7 | import com.yoho.search.service.base.SearchRequestParams; |
@@ -7,8 +9,7 @@ import com.yoho.search.service.base.SearchRequestParams; | @@ -7,8 +9,7 @@ import com.yoho.search.service.base.SearchRequestParams; | ||
7 | import org.apache.commons.collections.MapUtils; | 9 | import org.apache.commons.collections.MapUtils; |
8 | import org.apache.commons.lang.StringUtils; | 10 | import org.apache.commons.lang.StringUtils; |
9 | 11 | ||
10 | -import java.util.HashMap; | ||
11 | -import java.util.Map; | 12 | +import java.util.*; |
12 | import java.util.concurrent.CompletableFuture; | 13 | import java.util.concurrent.CompletableFuture; |
13 | import java.util.concurrent.Executor; | 14 | import java.util.concurrent.Executor; |
14 | import java.util.function.Supplier; | 15 | import java.util.function.Supplier; |
@@ -53,6 +54,32 @@ public abstract class AbstractSceneService { | @@ -53,6 +54,32 @@ public abstract class AbstractSceneService { | ||
53 | int page = StringUtils.isBlank(paramMap.get("page")) ? 1 : Integer.parseInt(paramMap.get("page")); | 54 | int page = StringUtils.isBlank(paramMap.get("page")) ? 1 : Integer.parseInt(paramMap.get("page")); |
54 | return page; | 55 | return page; |
55 | } | 56 | } |
57 | + | ||
58 | + protected List<Object> subList(Object source, int page, int count) { | ||
59 | + try { | ||
60 | + JSONArray sourceList = (JSONArray)source; | ||
61 | + if (sourceList != null && !sourceList.isEmpty()) { | ||
62 | + int totalCount = sourceList.size(); | ||
63 | + int start = (page - 1) * count; | ||
64 | + int end = start + count; | ||
65 | + if (start >= totalCount) { | ||
66 | + return Collections.emptyList(); | ||
67 | + } | ||
68 | + if (end > totalCount) { | ||
69 | + end = totalCount; | ||
70 | + } | ||
71 | + List<Object> subList = sourceList.subList(start, end); | ||
72 | + subList.forEach(e -> { | ||
73 | + JSONObject jsonObject = (JSONObject)e; | ||
74 | + jsonObject.put("totalCount", totalCount); | ||
75 | + }); | ||
76 | + return subList; | ||
77 | + } | ||
78 | + } catch (Exception e) { | ||
79 | + return Collections.emptyList(); | ||
80 | + } | ||
81 | + return Collections.emptyList(); | ||
82 | + } | ||
56 | 83 | ||
57 | protected String getuid(Map<String, String> paramMap) { | 84 | protected String getuid(Map<String, String> paramMap) { |
58 | return MapUtils.getString(paramMap, "uid", "0"); | 85 | return MapUtils.getString(paramMap, "uid", "0"); |
-
Please register or login to post a comment