Authored by 胡古飞

fix shops interfaces

... ... @@ -28,17 +28,17 @@ public class ShopsController {
private IShopListService shopListService;
/**
* 搜索店铺与品牌
* 按shopId聚合一些商品[目前好像没在调]
*
* @param request
* @return
*/
@DownGradeAble(key = "shopsNew")
@RequestMapping(method = RequestMethod.GET, value = "/shopsNew")
@DownGradeAble(key = "group_shops")
@RequestMapping(method = RequestMethod.GET, value = "/group_shops")
@ResponseBody
public SearchApiResult searchShopsNew(HttpServletRequest request) {
public SearchApiResult group_shops(HttpServletRequest request) {
Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
return shopsService.searchShopsNew(paramMap);
return shopsService.group_shops(paramMap);
}
/**
... ... @@ -52,24 +52,23 @@ public class ShopsController {
@ResponseBody
public SearchApiResult searchShops(HttpServletRequest request) {
Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
return shopsService.searchShops(paramMap);
return shopsService.searchYohoBrand(paramMap);
}
/**
* 按shopId聚合一些商品[目前好像没在调]
* 搜索店铺与品牌
*
* @param request
* @return
*/
@DownGradeAble(key = "group_shops")
@RequestMapping(method = RequestMethod.GET, value = "/group_shops")
@DownGradeAble(key = "shopsNew")
@RequestMapping(method = RequestMethod.GET, value = "/shopsNew")
@ResponseBody
public SearchApiResult group_shops(HttpServletRequest request) {
public SearchApiResult searchShopsNew(HttpServletRequest request) {
Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
return shopsService.group_shops(paramMap);
return shopsService.searchShopsNew(paramMap);
}
/**
* 按关键字搜出一堆店铺
*
... ...
package com.yoho.search.service.servicenew.impl;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
... ... @@ -46,7 +44,6 @@ import com.yoho.search.service.service.helper.SearchCommonHelper;
import com.yoho.search.service.service.helper.SearchServiceHelper;
import com.yoho.search.service.servicenew.IShopListService;
import com.yoho.search.service.utils.SearchKeyWordUtils;
import com.yoho.search.service.utils.SearchRequestParams;
import com.yoho.search.service.vo.SearchApiResult;
import com.yoho.search.service.vo.SearchSort;
... ...
... ... @@ -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排序
*
... ...