fix sceneAggRecommendPromotion
Showing
7 changed files
with
107 additions
and
123 deletions
1 | package com.yoho.search.models; | 1 | package com.yoho.search.models; |
2 | 2 | ||
3 | -import com.alibaba.fastjson.JSON; | ||
4 | -import com.alibaba.fastjson.annotation.JSONField; | ||
5 | - | ||
6 | public class RecommendPromotionAggVO { | 3 | public class RecommendPromotionAggVO { |
7 | 4 | ||
8 | - @JSONField(name = "promotion_info_id") | ||
9 | - private int promotionInfoId; | 5 | + private int promotion_info_id; |
6 | + | ||
7 | + private String coverimg_url; | ||
8 | + | ||
9 | + private String title; | ||
10 | 10 | ||
11 | - @JSONField(name = "coverimg_url") | ||
12 | - private String coverImgUrl; | 11 | + private long total_count; |
13 | 12 | ||
14 | - private String title; | 13 | + public int getPromotion_info_id() { |
14 | + return promotion_info_id; | ||
15 | + } | ||
15 | 16 | ||
16 | - public int getPromotionInfoId() { | ||
17 | - return promotionInfoId; | ||
18 | - } | 17 | + public void setPromotion_info_id(int promotion_info_id) { |
18 | + this.promotion_info_id = promotion_info_id; | ||
19 | + } | ||
19 | 20 | ||
20 | - public void setPromotionInfoId(int promotionInfoId) { | ||
21 | - this.promotionInfoId = promotionInfoId; | ||
22 | - } | 21 | + public String getCoverimg_url() { |
22 | + return coverimg_url; | ||
23 | + } | ||
23 | 24 | ||
24 | - public String getCoverImgUrl() { | ||
25 | - return coverImgUrl; | ||
26 | - } | 25 | + public void setCoverimg_url(String coverimg_url) { |
26 | + this.coverimg_url = coverimg_url; | ||
27 | + } | ||
27 | 28 | ||
28 | - public void setCoverImgUrl(String coverImgUrl) { | ||
29 | - this.coverImgUrl = coverImgUrl; | ||
30 | - } | 29 | + public String getTitle() { |
30 | + return title; | ||
31 | + } | ||
31 | 32 | ||
32 | - public String getTitle() { | ||
33 | - return title; | ||
34 | - } | 33 | + public void setTitle(String title) { |
34 | + this.title = title; | ||
35 | + } | ||
35 | 36 | ||
36 | - public void setTitle(String title) { | ||
37 | - this.title = title; | ||
38 | - } | 37 | + public long getTotal_count() { |
38 | + return total_count; | ||
39 | + } | ||
39 | 40 | ||
40 | - public static void main(String[] args) { | ||
41 | - RecommendPromotionAggVO recommendPromotionAggVO = new RecommendPromotionAggVO(); | ||
42 | - recommendPromotionAggVO.setPromotionInfoId(1); | ||
43 | - recommendPromotionAggVO.setCoverImgUrl("sdf"); | ||
44 | - recommendPromotionAggVO.setTitle("dfas"); | 41 | + public void setTotal_count(long total_count) { |
42 | + this.total_count = total_count; | ||
43 | + } | ||
45 | 44 | ||
46 | - System.out.println(JSON.toJSONString(recommendPromotionAggVO)); | ||
47 | - ; | ||
48 | - } | ||
49 | } | 45 | } |
1 | package com.yoho.search.service.aggregations.impls; | 1 | package com.yoho.search.service.aggregations.impls; |
2 | 2 | ||
3 | -import com.yoho.search.base.utils.DateUtil; | ||
4 | -import com.yoho.search.base.utils.ISearchConstants; | ||
5 | -import com.yoho.search.base.utils.ProductIndexEsField; | ||
6 | -import com.yoho.search.core.es.agg.AbstractAggregation; | ||
7 | -import com.yoho.search.service.base.index.PromotionIndexBaseService; | 3 | +import java.util.ArrayList; |
4 | +import java.util.Date; | ||
5 | +import java.util.List; | ||
6 | +import java.util.Map; | ||
7 | +import java.util.stream.Collectors; | ||
8 | + | ||
8 | import org.elasticsearch.index.query.BoolQueryBuilder; | 9 | import org.elasticsearch.index.query.BoolQueryBuilder; |
9 | import org.elasticsearch.index.query.QueryBuilders; | 10 | import org.elasticsearch.index.query.QueryBuilders; |
10 | import org.elasticsearch.search.aggregations.AbstractAggregationBuilder; | 11 | import org.elasticsearch.search.aggregations.AbstractAggregationBuilder; |
@@ -15,10 +16,13 @@ import org.elasticsearch.search.aggregations.bucket.nested.InternalNested; | @@ -15,10 +16,13 @@ import org.elasticsearch.search.aggregations.bucket.nested.InternalNested; | ||
15 | import org.elasticsearch.search.aggregations.bucket.nested.NestedAggregationBuilder; | 16 | import org.elasticsearch.search.aggregations.bucket.nested.NestedAggregationBuilder; |
16 | import org.elasticsearch.search.aggregations.bucket.terms.LongTerms; | 17 | import org.elasticsearch.search.aggregations.bucket.terms.LongTerms; |
17 | import org.elasticsearch.search.aggregations.bucket.terms.Terms; | 18 | import org.elasticsearch.search.aggregations.bucket.terms.Terms; |
18 | -import org.springframework.util.CollectionUtils; | ||
19 | 19 | ||
20 | -import java.util.*; | ||
21 | -import java.util.stream.Collectors; | 20 | +import com.yoho.search.base.utils.DateUtil; |
21 | +import com.yoho.search.base.utils.ISearchConstants; | ||
22 | +import com.yoho.search.base.utils.ProductIndexEsField; | ||
23 | +import com.yoho.search.core.es.agg.AbstractAggregation; | ||
24 | +import com.yoho.search.models.RecommendPromotionAggVO; | ||
25 | +import com.yoho.search.service.base.index.PromotionIndexBaseService; | ||
22 | 26 | ||
23 | public class RecommendPromotionAggregation extends AbstractAggregation { | 27 | public class RecommendPromotionAggregation extends AbstractAggregation { |
24 | private static final String TERM_AGGREGATION_NAME = "promotionIdAgg"; | 28 | private static final String TERM_AGGREGATION_NAME = "promotionIdAgg"; |
@@ -66,15 +70,16 @@ public class RecommendPromotionAggregation extends AbstractAggregation { | @@ -66,15 +70,16 @@ public class RecommendPromotionAggregation extends AbstractAggregation { | ||
66 | @Override | 70 | @Override |
67 | public Object getAggregationResponseMap(Map<String, Aggregation> aggMaps) { | 71 | public Object getAggregationResponseMap(Map<String, Aggregation> aggMaps) { |
68 | InternalNested aggregation = (InternalNested) aggMaps.get(aggName()); | 72 | InternalNested aggregation = (InternalNested) aggMaps.get(aggName()); |
69 | - if (!CollectionUtils.isEmpty(aggregation.getAggregations().asList())) { | ||
70 | - InternalFilter filter = (InternalFilter)aggregation.getAggregations().asList().get(0); | ||
71 | - List<LongTerms.Bucket> longTerms = ((LongTerms)filter.getAggregations().asList().get(0)).getBucketsInternal(); | ||
72 | - List<Integer> ids = longTerms.stream().map(e -> e.getKeyAsNumber().intValue()).collect(Collectors.toList()); | ||
73 | - if (!CollectionUtils.isEmpty(ids)) { | ||
74 | - return promotionIndexBaseService.getPromotionInfosByIds(ISearchConstants.INDEX_NAME_PROMOTIONINDEX, ids); | ||
75 | - } | 73 | + if(aggregation.getAggregations().asList().isEmpty()){ |
74 | + return new ArrayList<RecommendPromotionAggVO>(); | ||
75 | + } | ||
76 | + InternalFilter filter = (InternalFilter)aggregation.getAggregations().asList().get(0); | ||
77 | + List<LongTerms.Bucket> longTerms = ((LongTerms)filter.getAggregations().asList().get(0)).getBucketsInternal(); | ||
78 | + List<Integer> ids = longTerms.stream().map(e -> e.getKeyAsNumber().intValue()).collect(Collectors.toList()); | ||
79 | + if(ids==null || ids.isEmpty()){ | ||
80 | + return new ArrayList<RecommendPromotionAggVO>(); | ||
76 | } | 81 | } |
77 | - return null; | 82 | + return promotionIndexBaseService.getPromotionInfosByIds(ISearchConstants.INDEX_NAME_PROMOTIONINDEX, ids); |
78 | } | 83 | } |
79 | 84 | ||
80 | } | 85 | } |
@@ -66,9 +66,10 @@ public class PromotionIndexBaseService { | @@ -66,9 +66,10 @@ public class PromotionIndexBaseService { | ||
66 | return Collections.emptyList(); | 66 | return Collections.emptyList(); |
67 | } | 67 | } |
68 | List<RecommendPromotionAggVO> resultList = new ArrayList<>(); | 68 | List<RecommendPromotionAggVO> resultList = new ArrayList<>(); |
69 | + long total = searchResult.getTotal(); | ||
69 | for (Map<String, Object> esMap : searchResult.getResultList()) { | 70 | for (Map<String, Object> esMap : searchResult.getResultList()) { |
70 | if (!CollectionUtils.isEmpty(esMap)) { | 71 | if (!CollectionUtils.isEmpty(esMap)) { |
71 | - resultList.add(parsePromotionInfos(esMap)); | 72 | + resultList.add(parsePromotionInfos(esMap,total)); |
72 | } | 73 | } |
73 | } | 74 | } |
74 | return resultList; | 75 | return resultList; |
@@ -103,11 +104,12 @@ public class PromotionIndexBaseService { | @@ -103,11 +104,12 @@ public class PromotionIndexBaseService { | ||
103 | return map; | 104 | return map; |
104 | } | 105 | } |
105 | 106 | ||
106 | - private RecommendPromotionAggVO parsePromotionInfos(Map<String, Object> esMap) { | 107 | + private RecommendPromotionAggVO parsePromotionInfos(Map<String, Object> esMap,long total) { |
107 | RecommendPromotionAggVO recommendPromotionAggVO = new RecommendPromotionAggVO(); | 108 | RecommendPromotionAggVO recommendPromotionAggVO = new RecommendPromotionAggVO(); |
108 | - recommendPromotionAggVO.setPromotionInfoId(MapUtils.getIntValue(esMap, "id", 0)); | 109 | + recommendPromotionAggVO.setPromotion_info_id(MapUtils.getIntValue(esMap, "id", 0)); |
109 | recommendPromotionAggVO.setTitle(MapUtils.getString(esMap,"title", "")); | 110 | recommendPromotionAggVO.setTitle(MapUtils.getString(esMap,"title", "")); |
110 | - recommendPromotionAggVO.setCoverImgUrl(MapUtils.getString(esMap, "commonBanner", "")); | 111 | + recommendPromotionAggVO.setCoverimg_url(MapUtils.getString(esMap, "commonBanner", "")); |
112 | + recommendPromotionAggVO.setTotal_count(total); | ||
111 | return recommendPromotionAggVO; | 113 | return recommendPromotionAggVO; |
112 | } | 114 | } |
113 | 115 |
1 | package com.yoho.search.service.scene; | 1 | package com.yoho.search.service.scene; |
2 | 2 | ||
3 | -import java.util.Collections; | ||
4 | import java.util.Map; | 3 | import java.util.Map; |
5 | import java.util.concurrent.CompletableFuture; | 4 | import java.util.concurrent.CompletableFuture; |
6 | import java.util.concurrent.ExecutorService; | 5 | import java.util.concurrent.ExecutorService; |
@@ -88,7 +87,7 @@ public class FuzzySceneService extends AbstractSceneService { | @@ -88,7 +87,7 @@ public class FuzzySceneService extends AbstractSceneService { | ||
88 | // 4、获取自定义标签聚合结果 | 87 | // 4、获取自定义标签聚合结果 |
89 | CompletableFuture<SearchApiResult> customizeTagFuture = CompletableFuture.supplyAsync(() -> sceneAggregationsHelper.sceneAggCustomizeTag(this.newParamMap(paramMap)), executor); | 88 | CompletableFuture<SearchApiResult> customizeTagFuture = CompletableFuture.supplyAsync(() -> sceneAggregationsHelper.sceneAggCustomizeTag(this.newParamMap(paramMap)), executor); |
90 | // 5、获取促销专题 | 89 | // 5、获取促销专题 |
91 | - CompletableFuture<SearchApiResult> recommendPromotionFuture = CompletableFuture.supplyAsync(() -> sceneAggregationsHelper.sceneAggRecommendPromotion(this.newParamMap(paramMap)), | 90 | + CompletableFuture<SearchApiResult> promotionsFuture = CompletableFuture.supplyAsync(() -> sceneAggregationsHelper.sceneAggRecommendPromotion(this.newParamMap(paramMap)), |
92 | executor); | 91 | executor); |
93 | 92 | ||
94 | // 6、加入建议词 | 93 | // 6、加入建议词 |
@@ -103,14 +102,10 @@ public class FuzzySceneService extends AbstractSceneService { | @@ -103,14 +102,10 @@ public class FuzzySceneService extends AbstractSceneService { | ||
103 | } | 102 | } |
104 | // 8、组合结果 | 103 | // 8、组合结果 |
105 | SearchApiResult customizeTags = customizeTagFuture.get(); | 104 | SearchApiResult customizeTags = customizeTagFuture.get(); |
106 | - SearchApiResult recommendProducts = recommendPromotionFuture.get(); | 105 | + SearchApiResult promotions = promotionsFuture.get(); |
107 | JSONObject dataMap = (JSONObject) productListResult.getData(); | 106 | JSONObject dataMap = (JSONObject) productListResult.getData(); |
108 | dataMap.put(CUSTOMIZE_TAG_LIST, customizeTags.getData()); | 107 | dataMap.put(CUSTOMIZE_TAG_LIST, customizeTags.getData()); |
109 | - if (recommendProducts.getData() == null) { | ||
110 | - dataMap.put(RECOMMEND_PROMOTION_LIST, Collections.EMPTY_LIST); | ||
111 | - } else { | ||
112 | - dataMap.put(RECOMMEND_PROMOTION_LIST, subList(recommendProducts.getData(), StringUtils.isBlank(paramMap.get("page")) ? 1 : Integer.parseInt(paramMap.get("page")), 1)); | ||
113 | - } | 108 | + dataMap.put(RECOMMEND_PROMOTION_LIST, sceneAggregationsHelper.subRecommendPromotions(promotions.getData(),this.getPage(paramMap),1)); |
114 | return productListResult; | 109 | return productListResult; |
115 | } catch (Exception e) { | 110 | } catch (Exception e) { |
116 | logger.error(e.getMessage(), e); | 111 | logger.error(e.getMessage(), e); |
1 | package com.yoho.search.service.scene; | 1 | package com.yoho.search.service.scene; |
2 | 2 | ||
3 | -import java.util.Collections; | ||
4 | import java.util.Map; | 3 | import java.util.Map; |
5 | import java.util.concurrent.CompletableFuture; | 4 | import java.util.concurrent.CompletableFuture; |
6 | import java.util.concurrent.ExecutorService; | 5 | import java.util.concurrent.ExecutorService; |
@@ -101,22 +100,16 @@ public class SortSceneService extends AbstractSceneService { | @@ -101,22 +100,16 @@ public class SortSceneService extends AbstractSceneService { | ||
101 | // 3、获取聚合结果 | 100 | // 3、获取聚合结果 |
102 | CompletableFuture<SearchApiResult> standardsFuture = CompletableFuture.supplyAsync(() -> sceneAggregationsHelper.sceneAggStandard(this.newParamMap(paramMap)), executorService); | 101 | CompletableFuture<SearchApiResult> standardsFuture = CompletableFuture.supplyAsync(() -> sceneAggregationsHelper.sceneAggStandard(this.newParamMap(paramMap)), executorService); |
103 | CompletableFuture<SearchApiResult> customizeTagFuture = CompletableFuture.supplyAsync(() -> sceneAggregationsHelper.sceneAggCustomizeTag(this.newParamMap(paramMap)),executorService); | 102 | CompletableFuture<SearchApiResult> customizeTagFuture = CompletableFuture.supplyAsync(() -> sceneAggregationsHelper.sceneAggCustomizeTag(this.newParamMap(paramMap)),executorService); |
104 | - CompletableFuture<SearchApiResult> recommendProductFuture = CompletableFuture.supplyAsync(() -> sceneAggregationsHelper.sceneAggRecommendPromotion(this.newParamMap(paramMap)),executorService); | 103 | + CompletableFuture<SearchApiResult> promotionsFuture = CompletableFuture.supplyAsync(() -> sceneAggregationsHelper.sceneAggRecommendPromotion(this.newParamMap(paramMap)),executorService); |
105 | // 4、组合结果 | 104 | // 4、组合结果 |
106 | SearchApiResult productList = productListFuture.get(); | 105 | SearchApiResult productList = productListFuture.get(); |
107 | SearchApiResult standards = standardsFuture.get(); | 106 | SearchApiResult standards = standardsFuture.get(); |
108 | SearchApiResult customizeTags = customizeTagFuture.get(); | 107 | SearchApiResult customizeTags = customizeTagFuture.get(); |
109 | - SearchApiResult recommendProducts = recommendProductFuture.get(); | ||
110 | - | 108 | + SearchApiResult promotions = promotionsFuture.get(); |
111 | JSONObject jsonObject = (JSONObject) productList.getData(); | 109 | JSONObject jsonObject = (JSONObject) productList.getData(); |
112 | - jsonObject.put("standard", standards.getData()); | 110 | + jsonObject.put(STANDARD, standards.getData()); |
113 | jsonObject.put(CUSTOMIZE_TAG_LIST, customizeTags.getData()); | 111 | jsonObject.put(CUSTOMIZE_TAG_LIST, customizeTags.getData()); |
114 | - | ||
115 | - if (recommendProducts.getData() == null) { | ||
116 | - jsonObject.put(RECOMMEND_PROMOTION_LIST, Collections.EMPTY_LIST); | ||
117 | - } else { | ||
118 | - jsonObject.put(RECOMMEND_PROMOTION_LIST, subList(recommendProducts.getData(), StringUtils.isBlank(paramMap.get("page")) ? 1 : Integer.parseInt(paramMap.get("page")), 1)); | ||
119 | - } | 112 | + jsonObject.put(RECOMMEND_PROMOTION_LIST, sceneAggregationsHelper.subRecommendPromotions(promotions.getData(),this.getPage(paramMap),1)); |
120 | return productList; | 113 | return productList; |
121 | } catch (Exception e) { | 114 | } catch (Exception e) { |
122 | logger.error(e.getMessage(), e); | 115 | logger.error(e.getMessage(), e); |
1 | package com.yoho.search.service.scene.aggregations; | 1 | package com.yoho.search.service.scene.aggregations; |
2 | 2 | ||
3 | +import java.util.ArrayList; | ||
3 | import java.util.Arrays; | 4 | import java.util.Arrays; |
5 | +import java.util.Collections; | ||
6 | +import java.util.List; | ||
4 | import java.util.Map; | 7 | import java.util.Map; |
5 | 8 | ||
6 | import org.elasticsearch.search.aggregations.Aggregation; | 9 | import org.elasticsearch.search.aggregations.Aggregation; |
@@ -66,12 +69,12 @@ public class SceneAggregationsHelper { | @@ -66,12 +69,12 @@ public class SceneAggregationsHelper { | ||
66 | return new SearchApiResult().setCode(500).setMessage("secneAggCustomizeTag Exception"); | 69 | return new SearchApiResult().setCode(500).setMessage("secneAggCustomizeTag Exception"); |
67 | } | 70 | } |
68 | } | 71 | } |
69 | - | 72 | + |
70 | @SearchCacheAble(cacheName = "SCENE_AGG_RECOMMENDPROMOTION", cacheInMinute = 30, excludeParams = { "uid", "order", "page", "viewNum", "yh_channel" }) | 73 | @SearchCacheAble(cacheName = "SCENE_AGG_RECOMMENDPROMOTION", cacheInMinute = 30, excludeParams = { "uid", "order", "page", "viewNum", "yh_channel" }) |
71 | public SearchApiResult sceneAggRecommendPromotion(Map<String, String> paramMap) { | 74 | public SearchApiResult sceneAggRecommendPromotion(Map<String, String> paramMap) { |
72 | try { | 75 | try { |
73 | // 1、获取aggregation | 76 | // 1、获取aggregation |
74 | - IAggregation aggregation = aggregationFactoryService.getRecommendPromotionAggregation(100); | 77 | + IAggregation aggregation = aggregationFactoryService.getRecommendPromotionAggregation(50); |
75 | Object respone = this.getAggregationResponse(aggregation, paramMap); | 78 | Object respone = this.getAggregationResponse(aggregation, paramMap); |
76 | return new SearchApiResult().setData(respone); | 79 | return new SearchApiResult().setData(respone); |
77 | } catch (Exception e) { | 80 | } catch (Exception e) { |
@@ -80,4 +83,27 @@ public class SceneAggregationsHelper { | @@ -80,4 +83,27 @@ public class SceneAggregationsHelper { | ||
80 | } | 83 | } |
81 | } | 84 | } |
82 | 85 | ||
86 | + public List<?> subRecommendPromotions(Object recommendPromotions, int page, int count) { | ||
87 | + try { | ||
88 | + if (recommendPromotions == null || !(recommendPromotions instanceof List)) { | ||
89 | + return new ArrayList<Object>(); | ||
90 | + } | ||
91 | + List<?> recommendPromotionList = (List<?>) recommendPromotions; | ||
92 | + | ||
93 | + int totalCount = recommendPromotionList.size(); | ||
94 | + int start = (page - 1) * count; | ||
95 | + int end = start + count; | ||
96 | + if (start >= totalCount) { | ||
97 | + return Collections.emptyList(); | ||
98 | + } | ||
99 | + if (end > totalCount) { | ||
100 | + end = totalCount; | ||
101 | + } | ||
102 | + return recommendPromotionList.subList(start, end); | ||
103 | + } catch (Exception e) { | ||
104 | + logger.error(e.getMessage(), e); | ||
105 | + return new ArrayList<Object>(); | ||
106 | + } | ||
107 | + } | ||
108 | + | ||
83 | } | 109 | } |
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; | ||
5 | -import com.yoho.search.common.utils.SearchKeyWordUtils; | ||
6 | -import com.yoho.search.models.SearchApiResult; | ||
7 | -import com.yoho.search.service.base.SearchRequestParams; | 3 | +import java.util.HashMap; |
4 | +import java.util.Map; | ||
8 | 5 | ||
9 | import org.apache.commons.collections.MapUtils; | 6 | import org.apache.commons.collections.MapUtils; |
10 | import org.apache.commons.lang.StringUtils; | 7 | import org.apache.commons.lang.StringUtils; |
11 | 8 | ||
12 | -import java.util.*; | ||
13 | -import java.util.concurrent.CompletableFuture; | ||
14 | -import java.util.concurrent.Executor; | ||
15 | -import java.util.function.Supplier; | 9 | +import com.yoho.search.common.utils.SearchKeyWordUtils; |
10 | +import com.yoho.search.models.SearchApiResult; | ||
11 | +import com.yoho.search.service.base.SearchRequestParams; | ||
16 | 12 | ||
17 | public abstract class AbstractSceneService { | 13 | public abstract class AbstractSceneService { |
18 | - | 14 | + |
19 | protected static final String RECOMMEND_PROMOTION_LIST = "recommend_promotion_list"; | 15 | protected static final String RECOMMEND_PROMOTION_LIST = "recommend_promotion_list"; |
20 | - protected static final String CUSTOMIZE_TAG_LIST = "customize_tag"; | ||
21 | - | ||
22 | - protected Map<String, String> newParamMap(Map<String, String> paramMap) { | 16 | + protected static final String CUSTOMIZE_TAG_LIST = "customize_tag"; |
17 | + protected static final String STANDARD = "standard"; | ||
18 | + | ||
19 | + protected Map<String, String> newParamMap(Map<String, String> paramMap) { | ||
23 | return new HashMap<String, String>(paramMap); | 20 | return new HashMap<String, String>(paramMap); |
24 | } | 21 | } |
25 | - | ||
26 | - protected CompletableFuture<?> getFuture(Supplier<?> supplier,Executor executor){ | ||
27 | - return CompletableFuture.supplyAsync(() -> supplier,executor); | ||
28 | - } | ||
29 | - | 22 | + |
30 | /** | 23 | /** |
31 | * 场景化的默认参数 | 24 | * 场景化的默认参数 |
32 | * | 25 | * |
@@ -42,45 +35,19 @@ public abstract class AbstractSceneService { | @@ -42,45 +35,19 @@ public abstract class AbstractSceneService { | ||
42 | paramMap.put(SearchRequestParams.PARAM_SEARCH_ATTRIBUTE_NOT, "2");// 非赠品 | 35 | paramMap.put(SearchRequestParams.PARAM_SEARCH_ATTRIBUTE_NOT, "2");// 非赠品 |
43 | paramMap.put(SearchRequestParams.PARAM_SEARCH_NEEDSMALLSORT, "1");// 品类聚合时带上小分类 | 36 | paramMap.put(SearchRequestParams.PARAM_SEARCH_NEEDSMALLSORT, "1");// 品类聚合时带上小分类 |
44 | paramMap.put(SearchRequestParams.PARAM_SEARCH_AGG_WITH_PARAM_BRAND, "Y");// 聚合时使用参数中自带的参数 | 37 | paramMap.put(SearchRequestParams.PARAM_SEARCH_AGG_WITH_PARAM_BRAND, "Y");// 聚合时使用参数中自带的参数 |
45 | - //关键词反转码 | ||
46 | - String keyword = SearchKeyWordUtils.getParamKeyword(paramMap, SearchRequestParams.PARAM_SEARCH_QUERY);//转码 | ||
47 | - if(!StringUtils.isBlank(keyword)){ | 38 | + // 关键词反转码 |
39 | + String keyword = SearchKeyWordUtils.getParamKeyword(paramMap, SearchRequestParams.PARAM_SEARCH_QUERY);// 转码 | ||
40 | + if (!StringUtils.isBlank(keyword)) { | ||
48 | paramMap.put(SearchRequestParams.PARAM_SEARCH_QUERY, keyword); | 41 | paramMap.put(SearchRequestParams.PARAM_SEARCH_QUERY, keyword); |
49 | paramMap.put("is_encode", "0"); | 42 | paramMap.put("is_encode", "0"); |
50 | } | 43 | } |
51 | } | 44 | } |
52 | - | 45 | + |
53 | protected int getPage(Map<String, String> paramMap) { | 46 | protected int getPage(Map<String, String> paramMap) { |
54 | int page = StringUtils.isBlank(paramMap.get("page")) ? 1 : Integer.parseInt(paramMap.get("page")); | 47 | int page = StringUtils.isBlank(paramMap.get("page")) ? 1 : Integer.parseInt(paramMap.get("page")); |
55 | return page; | 48 | return page; |
56 | } | 49 | } |
57 | 50 | ||
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 | - } | ||
83 | - | ||
84 | protected String getuid(Map<String, String> paramMap) { | 51 | protected String getuid(Map<String, String> paramMap) { |
85 | return MapUtils.getString(paramMap, "uid", "0"); | 52 | return MapUtils.getString(paramMap, "uid", "0"); |
86 | } | 53 | } |
-
Please register or login to post a comment