|
@@ -2,13 +2,11 @@ package com.yoho.search.service.servicenew.scene.common; |
|
@@ -2,13 +2,11 @@ package com.yoho.search.service.servicenew.scene.common; |
2
|
|
2
|
|
3
|
import java.util.ArrayList;
|
3
|
import java.util.ArrayList;
|
4
|
import java.util.Arrays;
|
4
|
import java.util.Arrays;
|
5
|
-import java.util.Iterator;
|
|
|
6
|
import java.util.List;
|
5
|
import java.util.List;
|
7
|
import java.util.Map;
|
6
|
import java.util.Map;
|
8
|
|
7
|
|
9
|
import javax.annotation.PostConstruct;
|
8
|
import javax.annotation.PostConstruct;
|
10
|
|
9
|
|
11
|
-import org.apache.commons.collections.MapUtils;
|
|
|
12
|
import org.apache.commons.lang.StringUtils;
|
10
|
import org.apache.commons.lang.StringUtils;
|
13
|
import org.slf4j.Logger;
|
11
|
import org.slf4j.Logger;
|
14
|
import org.slf4j.LoggerFactory;
|
12
|
import org.slf4j.LoggerFactory;
|
|
@@ -91,7 +89,7 @@ public class SceneProductListService extends BaseService { |
|
@@ -91,7 +89,7 @@ public class SceneProductListService extends BaseService { |
91
|
dataMap.put("page_size", searchParam.getSize());
|
89
|
dataMap.put("page_size", searchParam.getSize());
|
92
|
dataMap.put("page_total", searchResult.getTotalPage());
|
90
|
dataMap.put("page_total", searchResult.getTotalPage());
|
93
|
List<Map<String, Object>> product_list = productIndexBaseService.getProductListWithPricePlan(searchResult.getResultList(), null);
|
91
|
List<Map<String, Object>> product_list = productIndexBaseService.getProductListWithPricePlan(searchResult.getResultList(), null);
|
94
|
- dataMap.put("product_list", this.moveProductListSort(paramMap, product_list));
|
92
|
+ dataMap.put("product_list", product_list);
|
95
|
|
93
|
|
96
|
// 5)将结果存进缓存
|
94
|
// 5)将结果存进缓存
|
97
|
searchCacheService.addJSONObjectToCache(searchCache, indexName, searchParam, dataMap);
|
95
|
searchCacheService.addJSONObjectToCache(searchCache, indexName, searchParam, dataMap);
|
|
@@ -102,52 +100,6 @@ public class SceneProductListService extends BaseService { |
|
@@ -102,52 +100,6 @@ public class SceneProductListService extends BaseService { |
102
|
}
|
100
|
}
|
103
|
}
|
101
|
}
|
104
|
|
102
|
|
105
|
- /**
|
|
|
106
|
- * 品类列表页针对第一页的商品,将价格高的往前面平移8个
|
|
|
107
|
- *
|
|
|
108
|
- * @param paramMap
|
|
|
109
|
- * @param product_list
|
|
|
110
|
- * @return
|
|
|
111
|
- */
|
|
|
112
|
- private List<Map<String, Object>> moveProductListSort(Map<String, String> paramMap, List<Map<String, Object>> product_list) {
|
|
|
113
|
- // 判断页面合法性
|
|
|
114
|
- if (!searchCommonHelper.isSortPageDefault(paramMap)) {
|
|
|
115
|
- return product_list;
|
|
|
116
|
- }
|
|
|
117
|
- String page = paramMap.get("page");
|
|
|
118
|
- if (StringUtils.isNotBlank(page) && !page.equals("1")) {
|
|
|
119
|
- return product_list;
|
|
|
120
|
- }
|
|
|
121
|
- // 判断总数
|
|
|
122
|
- int total = product_list.size();
|
|
|
123
|
- if (total <= 10) {
|
|
|
124
|
- return product_list;
|
|
|
125
|
- }
|
|
|
126
|
- // 计算均价
|
|
|
127
|
- double totalPrice = 0;
|
|
|
128
|
- for (Map<String, Object> product : product_list) {
|
|
|
129
|
- totalPrice += MapUtils.getDoubleValue(product, "sales_price", 0);
|
|
|
130
|
- }
|
|
|
131
|
- double averagePrice = totalPrice / total;
|
|
|
132
|
- List<Map<String, Object>> results = new ArrayList<Map<String, Object>>();
|
|
|
133
|
- results.add(product_list.get(0));
|
|
|
134
|
- product_list.remove(0);
|
|
|
135
|
- Iterator<Map<String, Object>> iterator = product_list.iterator();
|
|
|
136
|
- int moveCount = 0;
|
|
|
137
|
- while (iterator.hasNext() && moveCount < 8) {
|
|
|
138
|
- Map<String, Object> product = iterator.next();
|
|
|
139
|
- if (MapUtils.getDoubleValue(product, "sales_price", 0) >= averagePrice) {
|
|
|
140
|
- results.add(product);
|
|
|
141
|
- moveCount++;
|
|
|
142
|
- iterator.remove();
|
|
|
143
|
- }
|
|
|
144
|
- }
|
|
|
145
|
- if (!product_list.isEmpty()) {
|
|
|
146
|
- results.addAll(product_list);
|
|
|
147
|
- }
|
|
|
148
|
- return results;
|
|
|
149
|
- }
|
|
|
150
|
-
|
|
|
151
|
private SearchParam buildProductListSearchParam(Map<String, String> paramMap) throws Exception {
|
103
|
private SearchParam buildProductListSearchParam(Map<String, String> paramMap) throws Exception {
|
152
|
// 1)验证查询条数
|
104
|
// 1)验证查询条数
|
153
|
int pageSize = StringUtils.isBlank(paramMap.get("viewNum")) ? 10 : Integer.parseInt(paramMap.get("viewNum"));
|
105
|
int pageSize = StringUtils.isBlank(paramMap.get("viewNum")) ? 10 : Integer.parseInt(paramMap.get("viewNum"));
|