Authored by wangnan

shops接口 支持encode

... ... @@ -48,6 +48,8 @@ import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.stereotype.Service;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.*;
import java.util.Map.Entry;
... ... @@ -259,7 +261,7 @@ public class SearchWithCacheServiceImpl implements ISearchWithCacheService, Appl
TopHits topHits;
SearchHits hits;
JSONArray result = new JSONArray();
List<Map<String, Object>> dataList =new ArrayList<Map<String, Object>>();
List<Map<String, Object>> dataList = new ArrayList<Map<String, Object>>();
List<String> sknStr = new ArrayList<String>();
while (itAgg.hasNext()) {
Bucket lt = itAgg.next();
... ... @@ -275,9 +277,9 @@ public class SearchWithCacheServiceImpl implements ISearchWithCacheService, Appl
}
}
try {
Map<String, List<Map<String, Object>>> productPricePlanMap = searchServiceHelper.searchProductPricePlan((String[])sknStr.toArray(new String[sknStr.size()]));
for(Map<String, Object> m:dataList){
result.add(searchServiceHelper.getProductMapWithPricePlan(m,productPricePlanMap));
Map<String, List<Map<String, Object>>> productPricePlanMap = searchServiceHelper.searchProductPricePlan((String[]) sknStr.toArray(new String[sknStr.size()]));
for (Map<String, Object> m : dataList) {
result.add(searchServiceHelper.getProductMapWithPricePlan(m, productPricePlanMap));
}
} catch (Exception e) {
logger.error("[func=getNewShelveResponseMap][Exception={}][begin={}]", e, System.currentTimeMillis());
... ... @@ -363,7 +365,7 @@ public class SearchWithCacheServiceImpl implements ISearchWithCacheService, Appl
// 首先获取全部品牌的商品列表
Map<String, Map<String, Object>> brandMap = new HashMap<String, Map<String, Object>>();
List<String> sknStr = new ArrayList<String>();
Map<String, Map<String,Object>> dataList =new HashMap<String, Map<String,Object>>();
Map<String, Map<String, Object>> dataList = new HashMap<String, Map<String, Object>>();
while (itAgg.hasNext()) {
Bucket lt = itAgg.next();
if (lt.getAggregations().getAsMap().containsKey("product")) {
... ... @@ -378,9 +380,9 @@ public class SearchWithCacheServiceImpl implements ISearchWithCacheService, Appl
}
}
try {
Map<String, List<Map<String, Object>>> productPricePlanMap = searchServiceHelper.searchProductPricePlan((String[])sknStr.toArray(new String[sknStr.size()]));
dataList.forEach((k,m)->{
brandMap.put(k,searchServiceHelper.getProductMapWithPricePlan(m,productPricePlanMap));
Map<String, List<Map<String, Object>>> productPricePlanMap = searchServiceHelper.searchProductPricePlan((String[]) sknStr.toArray(new String[sknStr.size()]));
dataList.forEach((k, m) -> {
brandMap.put(k, searchServiceHelper.getProductMapWithPricePlan(m, productPricePlanMap));
});
} catch (Exception e) {
logger.error("[func=getNewBrandResponseMap][Exception={}][begin={}]", e, System.currentTimeMillis());
... ... @@ -506,7 +508,7 @@ public class SearchWithCacheServiceImpl implements ISearchWithCacheService, Appl
private Map<String, Object> getGroupBrandResponseMap(MultiBucketsAggregation aggregation, 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, 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;
... ... @@ -531,11 +533,12 @@ public class SearchWithCacheServiceImpl implements ISearchWithCacheService, Appl
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>> list = new ArrayList<Map<String, Object>>();;
for(Map<String, Object> mm:dataListMap.get(k)){
list.add(searchServiceHelper.getProductMapWithPricePlan(mm,productPricePlanMap));
Map<String, List<Map<String, Object>>> productPricePlanMap = searchServiceHelper.searchProductPricePlan((String[]) sknStr.toArray(new String[sknStr.size()]));
dataMapMap.forEach((k, m) -> {
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
;
for (Map<String, Object> mm : dataListMap.get(k)) {
list.add(searchServiceHelper.getProductMapWithPricePlan(mm, productPricePlanMap));
}
m.put("product_list", list);
dataMap.put(k, m);
... ... @@ -599,6 +602,15 @@ public class SearchWithCacheServiceImpl implements ISearchWithCacheService, Appl
if (keyword.contains("%")) {
keyword.replace("%", "percent");// 特殊处理
}
//编码转换
String is_encode = paramMap.get("is_encode");
if (StringUtils.isNotBlank(is_encode) && is_encode.equals("1")) {
try {
keyword = URLDecoder.decode(keyword, "UTF-8");
} catch (UnsupportedEncodingException e) {
logger.warn(e.getMessage(), e);
}
}
// 2、配置keyword的查询字段以及权重设置
MultiMatchQueryBuilder queryBuilder = QueryBuilders.multiMatchQuery(keyword);
... ... @@ -643,9 +655,6 @@ public class SearchWithCacheServiceImpl implements ISearchWithCacheService, Appl
}
@Override
public SearchApiResult group_shops(Map<String, String> paramMap) {
try {
... ... @@ -706,7 +715,7 @@ public class SearchWithCacheServiceImpl implements ISearchWithCacheService, Appl
private Map<String, Object> getGroupShopResponseMap(MultiBucketsAggregation aggregation, 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, 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;
... ... @@ -730,11 +739,12 @@ public class SearchWithCacheServiceImpl implements ISearchWithCacheService, Appl
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>> list = new ArrayList<Map<String, Object>>();;
for(Map<String, Object> mm:dataListMap.get(k)){
list.add(searchServiceHelper.getProductMapWithPricePlan(mm,productPricePlanMap));
Map<String, List<Map<String, Object>>> productPricePlanMap = searchServiceHelper.searchProductPricePlan((String[]) sknStr.toArray(new String[sknStr.size()]));
dataMapMap.forEach((k, m) -> {
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
;
for (Map<String, Object> mm : dataListMap.get(k)) {
list.add(searchServiceHelper.getProductMapWithPricePlan(mm, productPricePlanMap));
}
m.put("product_list", list);
dataMap.put(k, m);
... ... @@ -769,7 +779,7 @@ public class SearchWithCacheServiceImpl implements ISearchWithCacheService, Appl
// 3)构建filter
BoolQueryBuilder boolFilterBuilder = QueryBuilders.boolQuery().must(QueryBuilders.termQuery("status", 1)).mustNot(QueryBuilders.termQuery("attribute", 2))
.must(QueryBuilders.rangeQuery("storageNum").gte(1)).must(QueryBuilders.termQuery("isOutlets", 2));
if (!searchServiceHelper.containGlobal(paramMap)){
if (!searchServiceHelper.containGlobal(paramMap)) {
boolFilterBuilder.mustNot(QueryBuilders.termQuery("isGlobal", "Y"));
}
searchParam.setFiter(boolFilterBuilder);
... ... @@ -818,7 +828,7 @@ public class SearchWithCacheServiceImpl implements ISearchWithCacheService, Appl
if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_SIZE)) {
size = Integer.parseInt(paramMap.get(SearchRequestParams.PARAM_SEARCH_SIZE));
}
if(size>10){
if (size > 10) {
size = 10;
}
... ...