|
@@ -13,7 +13,6 @@ import org.elasticsearch.index.query.BoolQueryBuilder; |
|
@@ -13,7 +13,6 @@ import org.elasticsearch.index.query.BoolQueryBuilder; |
13
|
import org.elasticsearch.index.query.MatchQueryBuilder;
|
13
|
import org.elasticsearch.index.query.MatchQueryBuilder;
|
14
|
import org.elasticsearch.index.query.MultiMatchQueryBuilder;
|
14
|
import org.elasticsearch.index.query.MultiMatchQueryBuilder;
|
15
|
import org.elasticsearch.index.query.QueryBuilders;
|
15
|
import org.elasticsearch.index.query.QueryBuilders;
|
16
|
-import org.elasticsearch.index.query.TermQueryBuilder;
|
|
|
17
|
import org.elasticsearch.search.SearchHit;
|
16
|
import org.elasticsearch.search.SearchHit;
|
18
|
import org.elasticsearch.search.SearchHits;
|
17
|
import org.elasticsearch.search.SearchHits;
|
19
|
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
|
18
|
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
|
|
@@ -122,6 +121,7 @@ public class ShopsServiceImpl extends BaseService implements IShopsService, Appl |
|
@@ -122,6 +121,7 @@ public class ShopsServiceImpl extends BaseService implements IShopsService, Appl |
122
|
// 5)查询shops索引,获取shopsInfo
|
121
|
// 5)查询shops索引,获取shopsInfo
|
123
|
SearchApiResult searchResultShops = getShopsInfo(paramMap);
|
122
|
SearchApiResult searchResultShops = getShopsInfo(paramMap);
|
124
|
JSONObject jsonObject = (JSONObject) searchResultShops.getData();
|
123
|
JSONObject jsonObject = (JSONObject) searchResultShops.getData();
|
|
|
124
|
+ @SuppressWarnings("unchecked")
|
125
|
Map<String, Map<String, Object>> shopInfoMap = (Map<String, Map<String, Object>>) jsonObject.get("shopInfo");
|
125
|
Map<String, Map<String, Object>> shopInfoMap = (Map<String, Map<String, Object>>) jsonObject.get("shopInfo");
|
126
|
|
126
|
|
127
|
// 5)、构建返回结果并将结果存进缓存
|
127
|
// 5)、构建返回结果并将结果存进缓存
|
|
@@ -142,6 +142,65 @@ public class ShopsServiceImpl extends BaseService implements IShopsService, Appl |
|
@@ -142,6 +142,65 @@ public class ShopsServiceImpl extends BaseService implements IShopsService, Appl |
142
|
}
|
142
|
}
|
143
|
}
|
143
|
}
|
144
|
|
144
|
|
|
|
145
|
+ private Map<String, Object> getGroupShopResponseMap(MultiBucketsAggregation aggregation, Map<String, Map<String, Object>> shopInfoMap, int size) {
|
|
|
146
|
+ Iterator<? extends Bucket> itAgg = aggregation.getBuckets().iterator();
|
|
|
147
|
+ Map<String, Object> dataMap = new HashMap<String, Object>();
|
|
|
148
|
+ Map<String, List<Map<String, Object>>> dataListMap = new HashMap<String, List<Map<String, Object>>>();
|
|
|
149
|
+ Map<String, Map<String, Object>> dataMapMap = new HashMap<String, Map<String, Object>>();
|
|
|
150
|
+ Map<String, Object> map;
|
|
|
151
|
+ List<Map<String, Object>> dataList;
|
|
|
152
|
+ List<String> sknStr = new ArrayList<String>();
|
|
|
153
|
+ while (itAgg.hasNext()) {
|
|
|
154
|
+ Bucket lt = itAgg.next();
|
|
|
155
|
+ map = new HashMap<String, Object>();
|
|
|
156
|
+ map.put("count", lt.getDocCount());
|
|
|
157
|
+ if (size != 0) {
|
|
|
158
|
+ dataList = new ArrayList<Map<String, Object>>();
|
|
|
159
|
+ if (lt.getAggregations().getAsMap().containsKey("product")) {
|
|
|
160
|
+ TopHits topHits = lt.getAggregations().get("product");
|
|
|
161
|
+ SearchHits hits = topHits.getHits();
|
|
|
162
|
+ for (SearchHit hit : hits.getHits()) {
|
|
|
163
|
+ sknStr.add("" + hit.getSource().get("productSkn"));
|
|
|
164
|
+ dataList.add(hit.getSource());
|
|
|
165
|
+ }
|
|
|
166
|
+ dataListMap.put(lt.getKeyAsString(), dataList);
|
|
|
167
|
+ }
|
|
|
168
|
+ }
|
|
|
169
|
+ dataMapMap.put(lt.getKeyAsString(), map);
|
|
|
170
|
+ // 处理品牌信息
|
|
|
171
|
+ Map<String, Object> shopDataMap = new HashMap<String, Object>();
|
|
|
172
|
+ Map<String, Object> shopsInfo = shopInfoMap.get(lt.getKeyAsString());
|
|
|
173
|
+ if (shopsInfo != null) {
|
|
|
174
|
+ shopDataMap.put("shop_id", shopsInfo.get("shopsId"));
|
|
|
175
|
+ shopDataMap.put("shop_name", shopsInfo.get("shopName") == null ? "" : shopsInfo.get("shopName"));
|
|
|
176
|
+ shopDataMap.put("shop_logo", shopsInfo.get("shopLogo") == null ? "" : shopsInfo.get("shopLogo"));
|
|
|
177
|
+ shopDataMap.put("shop_domain", shopsInfo.get("shopDomain") == null ? "" : shopsInfo.get("shopDomain"));
|
|
|
178
|
+ shopDataMap.put("shop_type", shopsInfo.get("shopsType") == null ? "" : shopsInfo.get("shopsType"));
|
|
|
179
|
+ shopDataMap.put("decorator_template_type", shopsInfo.get("decoratorTemplateType") == null ? "" : shopsInfo.get("decoratorTemplateType"));
|
|
|
180
|
+ }
|
|
|
181
|
+ map.put("info", shopDataMap);
|
|
|
182
|
+ dataMapMap.put(lt.getKeyAsString(), map);
|
|
|
183
|
+ }
|
|
|
184
|
+ try {
|
|
|
185
|
+ Map<String, List<Map<String, Object>>> productPricePlanMap = searchServiceHelper.searchProductPricePlan((String[]) sknStr.toArray(new String[sknStr.size()]));
|
|
|
186
|
+ dataMapMap.forEach((k, m) -> {
|
|
|
187
|
+ List<Map<String, Object>> productList = dataListMap.get(k);
|
|
|
188
|
+ if (productList == null) {
|
|
|
189
|
+ productList = new ArrayList<Map<String, Object>>();
|
|
|
190
|
+ }
|
|
|
191
|
+ List<Map<String, Object>> newProductList = new ArrayList<Map<String, Object>>();
|
|
|
192
|
+ for (Map<String, Object> mm : productList) {
|
|
|
193
|
+ newProductList.add(searchServiceHelper.getProductMapWithPricePlan(mm, productPricePlanMap));
|
|
|
194
|
+ }
|
|
|
195
|
+ m.put("product_list", newProductList);
|
|
|
196
|
+ dataMap.put(k, m);
|
|
|
197
|
+ });
|
|
|
198
|
+ } catch (Exception e) {
|
|
|
199
|
+ logger.error("[func=getGroupShopResponseMap]" + e.getMessage(), e);
|
|
|
200
|
+ }
|
|
|
201
|
+ return dataMap;
|
|
|
202
|
+ }
|
|
|
203
|
+
|
145
|
@Override
|
204
|
@Override
|
146
|
public SearchApiResult searchYohoBrand(Map<String, String> paramMap) {
|
205
|
public SearchApiResult searchYohoBrand(Map<String, String> paramMap) {
|
147
|
try {
|
206
|
try {
|
|
@@ -283,65 +342,6 @@ public class ShopsServiceImpl extends BaseService implements IShopsService, Appl |
|
@@ -283,65 +342,6 @@ public class ShopsServiceImpl extends BaseService implements IShopsService, Appl |
283
|
return yohoBrandInfo;
|
342
|
return yohoBrandInfo;
|
284
|
}
|
343
|
}
|
285
|
|
344
|
|
286
|
- private Map<String, Object> getGroupShopResponseMap(MultiBucketsAggregation aggregation, Map<String, Map<String, Object>> shopInfoMap, int size) {
|
|
|
287
|
- Iterator<? extends Bucket> itAgg = aggregation.getBuckets().iterator();
|
|
|
288
|
- Map<String, Object> dataMap = new HashMap<String, Object>();
|
|
|
289
|
- Map<String, List<Map<String, Object>>> dataListMap = new HashMap<String, List<Map<String, Object>>>();
|
|
|
290
|
- Map<String, Map<String, Object>> dataMapMap = new HashMap<String, Map<String, Object>>();
|
|
|
291
|
- Map<String, Object> map;
|
|
|
292
|
- List<Map<String, Object>> dataList;
|
|
|
293
|
- List<String> sknStr = new ArrayList<String>();
|
|
|
294
|
- while (itAgg.hasNext()) {
|
|
|
295
|
- Bucket lt = itAgg.next();
|
|
|
296
|
- map = new HashMap<String, Object>();
|
|
|
297
|
- map.put("count", lt.getDocCount());
|
|
|
298
|
- if (size != 0) {
|
|
|
299
|
- dataList = new ArrayList<Map<String, Object>>();
|
|
|
300
|
- if (lt.getAggregations().getAsMap().containsKey("product")) {
|
|
|
301
|
- TopHits topHits = lt.getAggregations().get("product");
|
|
|
302
|
- SearchHits hits = topHits.getHits();
|
|
|
303
|
- for (SearchHit hit : hits.getHits()) {
|
|
|
304
|
- sknStr.add("" + hit.getSource().get("productSkn"));
|
|
|
305
|
- dataList.add(hit.getSource());
|
|
|
306
|
- }
|
|
|
307
|
- dataListMap.put(lt.getKeyAsString(), dataList);
|
|
|
308
|
- }
|
|
|
309
|
- }
|
|
|
310
|
- dataMapMap.put(lt.getKeyAsString(), map);
|
|
|
311
|
- // 处理品牌信息
|
|
|
312
|
- Map<String, Object> shopDataMap = new HashMap<String, Object>();
|
|
|
313
|
- Map<String, Object> shopsInfo = shopInfoMap.get(lt.getKeyAsString());
|
|
|
314
|
- if (shopsInfo != null) {
|
|
|
315
|
- shopDataMap.put("shop_id", shopsInfo.get("shopsId"));
|
|
|
316
|
- shopDataMap.put("shop_name", shopsInfo.get("shopName") == null ? "" : shopsInfo.get("shopName"));
|
|
|
317
|
- shopDataMap.put("shop_logo", shopsInfo.get("shopLogo") == null ? "" : shopsInfo.get("shopLogo"));
|
|
|
318
|
- shopDataMap.put("shop_domain", shopsInfo.get("shopDomain") == null ? "" : shopsInfo.get("shopDomain"));
|
|
|
319
|
- shopDataMap.put("shop_type", shopsInfo.get("shopsType") == null ? "" : shopsInfo.get("shopsType"));
|
|
|
320
|
- shopDataMap.put("decorator_template_type", shopsInfo.get("decoratorTemplateType") == null ? "" : shopsInfo.get("decoratorTemplateType"));
|
|
|
321
|
- }
|
|
|
322
|
- map.put("info", shopDataMap);
|
|
|
323
|
- dataMapMap.put(lt.getKeyAsString(), map);
|
|
|
324
|
- }
|
|
|
325
|
- try {
|
|
|
326
|
- Map<String, List<Map<String, Object>>> productPricePlanMap = searchServiceHelper.searchProductPricePlan((String[]) sknStr.toArray(new String[sknStr.size()]));
|
|
|
327
|
- dataMapMap.forEach((k, m) -> {
|
|
|
328
|
- List<Map<String, Object>> productList = dataListMap.get(k);
|
|
|
329
|
- if (productList == null) {
|
|
|
330
|
- productList = new ArrayList<Map<String, Object>>();
|
|
|
331
|
- }
|
|
|
332
|
- List<Map<String, Object>> newProductList = new ArrayList<Map<String, Object>>();
|
|
|
333
|
- for (Map<String, Object> mm : productList) {
|
|
|
334
|
- newProductList.add(searchServiceHelper.getProductMapWithPricePlan(mm, productPricePlanMap));
|
|
|
335
|
- }
|
|
|
336
|
- m.put("product_list", newProductList);
|
|
|
337
|
- dataMap.put(k, m);
|
|
|
338
|
- });
|
|
|
339
|
- } catch (Exception e) {
|
|
|
340
|
- logger.error("[func=getGroupShopResponseMap]" + e.getMessage(), e);
|
|
|
341
|
- }
|
|
|
342
|
- return dataMap;
|
|
|
343
|
- }
|
|
|
344
|
-
|
|
|
345
|
/**
|
345
|
/**
|
346
|
* 过滤出有库存且有商品上架的店铺id,并且按店铺id排序
|
346
|
* 过滤出有库存且有商品上架的店铺id,并且按店铺id排序
|
347
|
*
|
347
|
*
|