...
|
...
|
@@ -13,7 +13,6 @@ import org.elasticsearch.index.query.BoolQueryBuilder; |
|
|
import org.elasticsearch.index.query.MatchQueryBuilder;
|
|
|
import org.elasticsearch.index.query.MultiMatchQueryBuilder;
|
|
|
import org.elasticsearch.index.query.QueryBuilders;
|
|
|
import org.elasticsearch.index.query.TermQueryBuilder;
|
|
|
import org.elasticsearch.search.SearchHit;
|
|
|
import org.elasticsearch.search.SearchHits;
|
|
|
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
|
...
|
...
|
@@ -122,6 +121,7 @@ public class ShopsServiceImpl extends BaseService implements IShopsService, Appl |
|
|
// 5)查询shops索引,获取shopsInfo
|
|
|
SearchApiResult searchResultShops = getShopsInfo(paramMap);
|
|
|
JSONObject jsonObject = (JSONObject) searchResultShops.getData();
|
|
|
@SuppressWarnings("unchecked")
|
|
|
Map<String, Map<String, Object>> shopInfoMap = (Map<String, Map<String, Object>>) jsonObject.get("shopInfo");
|
|
|
|
|
|
// 5)、构建返回结果并将结果存进缓存
|
...
|
...
|
@@ -142,6 +142,65 @@ public class ShopsServiceImpl extends BaseService implements IShopsService, Appl |
|
|
}
|
|
|
}
|
|
|
|
|
|
private Map<String, Object> getGroupShopResponseMap(MultiBucketsAggregation aggregation, Map<String, Map<String, Object>> shopInfoMap, int size) {
|
|
|
Iterator<? extends Bucket> itAgg = aggregation.getBuckets().iterator();
|
|
|
Map<String, Object> dataMap = new HashMap<String, Object>();
|
|
|
Map<String, List<Map<String, Object>>> dataListMap = new HashMap<String, List<Map<String, Object>>>();
|
|
|
Map<String, Map<String, Object>> dataMapMap = new HashMap<String, Map<String, Object>>();
|
|
|
Map<String, Object> map;
|
|
|
List<Map<String, Object>> dataList;
|
|
|
List<String> sknStr = new ArrayList<String>();
|
|
|
while (itAgg.hasNext()) {
|
|
|
Bucket lt = itAgg.next();
|
|
|
map = new HashMap<String, Object>();
|
|
|
map.put("count", lt.getDocCount());
|
|
|
if (size != 0) {
|
|
|
dataList = new ArrayList<Map<String, Object>>();
|
|
|
if (lt.getAggregations().getAsMap().containsKey("product")) {
|
|
|
TopHits topHits = lt.getAggregations().get("product");
|
|
|
SearchHits hits = topHits.getHits();
|
|
|
for (SearchHit hit : hits.getHits()) {
|
|
|
sknStr.add("" + hit.getSource().get("productSkn"));
|
|
|
dataList.add(hit.getSource());
|
|
|
}
|
|
|
dataListMap.put(lt.getKeyAsString(), dataList);
|
|
|
}
|
|
|
}
|
|
|
dataMapMap.put(lt.getKeyAsString(), map);
|
|
|
// 处理品牌信息
|
|
|
Map<String, Object> shopDataMap = new HashMap<String, Object>();
|
|
|
Map<String, Object> shopsInfo = shopInfoMap.get(lt.getKeyAsString());
|
|
|
if (shopsInfo != null) {
|
|
|
shopDataMap.put("shop_id", shopsInfo.get("shopsId"));
|
|
|
shopDataMap.put("shop_name", shopsInfo.get("shopName") == null ? "" : shopsInfo.get("shopName"));
|
|
|
shopDataMap.put("shop_logo", shopsInfo.get("shopLogo") == null ? "" : shopsInfo.get("shopLogo"));
|
|
|
shopDataMap.put("shop_domain", shopsInfo.get("shopDomain") == null ? "" : shopsInfo.get("shopDomain"));
|
|
|
shopDataMap.put("shop_type", shopsInfo.get("shopsType") == null ? "" : shopsInfo.get("shopsType"));
|
|
|
shopDataMap.put("decorator_template_type", shopsInfo.get("decoratorTemplateType") == null ? "" : shopsInfo.get("decoratorTemplateType"));
|
|
|
}
|
|
|
map.put("info", shopDataMap);
|
|
|
dataMapMap.put(lt.getKeyAsString(), map);
|
|
|
}
|
|
|
try {
|
|
|
Map<String, List<Map<String, Object>>> productPricePlanMap = searchServiceHelper.searchProductPricePlan((String[]) sknStr.toArray(new String[sknStr.size()]));
|
|
|
dataMapMap.forEach((k, m) -> {
|
|
|
List<Map<String, Object>> productList = dataListMap.get(k);
|
|
|
if (productList == null) {
|
|
|
productList = new ArrayList<Map<String, Object>>();
|
|
|
}
|
|
|
List<Map<String, Object>> newProductList = new ArrayList<Map<String, Object>>();
|
|
|
for (Map<String, Object> mm : productList) {
|
|
|
newProductList.add(searchServiceHelper.getProductMapWithPricePlan(mm, productPricePlanMap));
|
|
|
}
|
|
|
m.put("product_list", newProductList);
|
|
|
dataMap.put(k, m);
|
|
|
});
|
|
|
} catch (Exception e) {
|
|
|
logger.error("[func=getGroupShopResponseMap]" + e.getMessage(), e);
|
|
|
}
|
|
|
return dataMap;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public SearchApiResult searchYohoBrand(Map<String, String> paramMap) {
|
|
|
try {
|
...
|
...
|
@@ -283,65 +342,6 @@ public class ShopsServiceImpl extends BaseService implements IShopsService, Appl |
|
|
return yohoBrandInfo;
|
|
|
}
|
|
|
|
|
|
private Map<String, Object> getGroupShopResponseMap(MultiBucketsAggregation aggregation, Map<String, Map<String, Object>> shopInfoMap, int size) {
|
|
|
Iterator<? extends Bucket> itAgg = aggregation.getBuckets().iterator();
|
|
|
Map<String, Object> dataMap = new HashMap<String, Object>();
|
|
|
Map<String, List<Map<String, Object>>> dataListMap = new HashMap<String, List<Map<String, Object>>>();
|
|
|
Map<String, Map<String, Object>> dataMapMap = new HashMap<String, Map<String, Object>>();
|
|
|
Map<String, Object> map;
|
|
|
List<Map<String, Object>> dataList;
|
|
|
List<String> sknStr = new ArrayList<String>();
|
|
|
while (itAgg.hasNext()) {
|
|
|
Bucket lt = itAgg.next();
|
|
|
map = new HashMap<String, Object>();
|
|
|
map.put("count", lt.getDocCount());
|
|
|
if (size != 0) {
|
|
|
dataList = new ArrayList<Map<String, Object>>();
|
|
|
if (lt.getAggregations().getAsMap().containsKey("product")) {
|
|
|
TopHits topHits = lt.getAggregations().get("product");
|
|
|
SearchHits hits = topHits.getHits();
|
|
|
for (SearchHit hit : hits.getHits()) {
|
|
|
sknStr.add("" + hit.getSource().get("productSkn"));
|
|
|
dataList.add(hit.getSource());
|
|
|
}
|
|
|
dataListMap.put(lt.getKeyAsString(), dataList);
|
|
|
}
|
|
|
}
|
|
|
dataMapMap.put(lt.getKeyAsString(), map);
|
|
|
// 处理品牌信息
|
|
|
Map<String, Object> shopDataMap = new HashMap<String, Object>();
|
|
|
Map<String, Object> shopsInfo = shopInfoMap.get(lt.getKeyAsString());
|
|
|
if (shopsInfo != null) {
|
|
|
shopDataMap.put("shop_id", shopsInfo.get("shopsId"));
|
|
|
shopDataMap.put("shop_name", shopsInfo.get("shopName") == null ? "" : shopsInfo.get("shopName"));
|
|
|
shopDataMap.put("shop_logo", shopsInfo.get("shopLogo") == null ? "" : shopsInfo.get("shopLogo"));
|
|
|
shopDataMap.put("shop_domain", shopsInfo.get("shopDomain") == null ? "" : shopsInfo.get("shopDomain"));
|
|
|
shopDataMap.put("shop_type", shopsInfo.get("shopsType") == null ? "" : shopsInfo.get("shopsType"));
|
|
|
shopDataMap.put("decorator_template_type", shopsInfo.get("decoratorTemplateType") == null ? "" : shopsInfo.get("decoratorTemplateType"));
|
|
|
}
|
|
|
map.put("info", shopDataMap);
|
|
|
dataMapMap.put(lt.getKeyAsString(), map);
|
|
|
}
|
|
|
try {
|
|
|
Map<String, List<Map<String, Object>>> productPricePlanMap = searchServiceHelper.searchProductPricePlan((String[]) sknStr.toArray(new String[sknStr.size()]));
|
|
|
dataMapMap.forEach((k, m) -> {
|
|
|
List<Map<String, Object>> productList = dataListMap.get(k);
|
|
|
if (productList == null) {
|
|
|
productList = new ArrayList<Map<String, Object>>();
|
|
|
}
|
|
|
List<Map<String, Object>> newProductList = new ArrayList<Map<String, Object>>();
|
|
|
for (Map<String, Object> mm : productList) {
|
|
|
newProductList.add(searchServiceHelper.getProductMapWithPricePlan(mm, productPricePlanMap));
|
|
|
}
|
|
|
m.put("product_list", newProductList);
|
|
|
dataMap.put(k, m);
|
|
|
});
|
|
|
} catch (Exception e) {
|
|
|
logger.error("[func=getGroupShopResponseMap]" + e.getMessage(), e);
|
|
|
}
|
|
|
return dataMap;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 过滤出有库存且有商品上架的店铺id,并且按店铺id排序
|
|
|
*
|
...
|
...
|
|