...
|
...
|
@@ -40,12 +40,15 @@ import org.springframework.stereotype.Service; |
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
public class YzService extends BaseSceneService {
|
|
|
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(YzService.class);
|
|
|
|
|
|
//品类列表前几个固定顺序为:鞋靴、上衣、裤装、服配、包类/装备
|
|
|
private static final List<String> maxSortIdOrderList = Arrays.asList("6", "1", "3", "8", "7");
|
|
|
|
|
|
@Autowired
|
|
|
private SearchParamHelper searchParamHelper;
|
...
|
...
|
@@ -56,10 +59,8 @@ public class YzService extends BaseSceneService { |
|
|
@Autowired
|
|
|
private ProductListHelper productListHelper;
|
|
|
|
|
|
@SearchCacheAble(cacheInMinute = 30, cacheName = "YZ_MSORT_LIST")
|
|
|
//@SearchCacheAble(cacheInMinute = 30, cacheName = "YZ_MSORT_LIST")
|
|
|
public SearchApiResult msortList(Map<String, String> paramMap) {
|
|
|
List<Map<String, String>> maxList = new ArrayList<>();
|
|
|
SearchApiResult searchApiResult = new SearchApiResult().setData(maxList);
|
|
|
try {
|
|
|
addDefaultParamsToParamMap(paramMap);
|
|
|
SearchParam searchParam = searchParamHelper.buildDefault(paramMap);
|
...
|
...
|
@@ -71,14 +72,15 @@ public class YzService extends BaseSceneService { |
|
|
final String indexName = ISearchConstants.INDEX_NAME_PRODUCT_INDEX;
|
|
|
SearchResult searchResult = searchCommonService.doSearch(indexName, searchParam);
|
|
|
if (searchResult == null || searchResult.getAggMaps() == null || !searchResult.getAggMaps().containsKey("maxAgg")) {
|
|
|
return searchApiResult;
|
|
|
return new SearchApiResult();
|
|
|
}
|
|
|
Map<String, Aggregation> aggMaps = searchResult.getAggMaps();
|
|
|
MultiBucketsAggregation aggregation = aggMaps != null && aggMaps.containsKey("maxAgg") ? (MultiBucketsAggregation)aggMaps.get("maxAgg") : null;
|
|
|
MultiBucketsAggregation aggregation = aggMaps != null && aggMaps.containsKey("maxAgg") ? (MultiBucketsAggregation) aggMaps.get("maxAgg") : null;
|
|
|
if (aggregation == null) {
|
|
|
return searchApiResult;
|
|
|
return new SearchApiResult();
|
|
|
}
|
|
|
Iterator<? extends MultiBucketsAggregation.Bucket> itLongTerm = aggregation.getBuckets().iterator();
|
|
|
List<Map<String, String>> maxList = new ArrayList<>();
|
|
|
while (itLongTerm.hasNext()) {
|
|
|
MultiBucketsAggregation.Bucket ltMax = itLongTerm.next();
|
|
|
String[] sortInfo = ltMax.getKeyAsString().split(":");
|
...
|
...
|
@@ -91,8 +93,26 @@ public class YzService extends BaseSceneService { |
|
|
maxList.add(sortMap);
|
|
|
}
|
|
|
}
|
|
|
if (CollectionUtils.isEmpty(maxList)) {
|
|
|
return new SearchApiResult();
|
|
|
}
|
|
|
//按照固定的顺序重排序
|
|
|
List<Map<String, String>> maxSortListSorted = new ArrayList<>();
|
|
|
Map<String, Map<String, String>> sortInfoMap = maxList.stream().collect(Collectors.toMap(p -> p.get("sort_id"), p -> p));
|
|
|
for (String sortId : maxSortIdOrderList) {
|
|
|
if (sortInfoMap.containsKey(sortId)) {
|
|
|
maxSortListSorted.add(sortInfoMap.get(sortId));
|
|
|
sortInfoMap.remove(sortId);
|
|
|
}
|
|
|
}
|
|
|
if (sortInfoMap.size() > 0) {
|
|
|
for (Map.Entry<String, Map<String, String>> entry : sortInfoMap.entrySet()) {
|
|
|
maxSortListSorted.add(entry.getValue());
|
|
|
}
|
|
|
}
|
|
|
SearchApiResult searchApiResult = new SearchApiResult().setData(maxSortListSorted);
|
|
|
return searchApiResult;
|
|
|
}catch (Exception e) {
|
|
|
} catch (Exception e) {
|
|
|
LOGGER.error(e.getMessage(), e);
|
|
|
}
|
|
|
return new SearchApiResult().setData(null).setMessage("msortList Exception").setCode(500);
|
...
|
...
|
@@ -115,7 +135,7 @@ public class YzService extends BaseSceneService { |
|
|
SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam);
|
|
|
ProductListWithSkn productListWithSkn = productListHelper.buildProductListWithSkn(searchResult, searchParam.getSize(), false, NotRecallTypeEnum.NOT_PERSIONAL);
|
|
|
return new SearchApiResult().setData(productListWithSkn);
|
|
|
}catch (Exception e) {
|
|
|
} catch (Exception e) {
|
|
|
return SearchApiResultUtils.errorSearchApiResult(LOGGER, paramMap, e);
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -146,7 +166,7 @@ public class YzService extends BaseSceneService { |
|
|
private SearchParam getSearchParam(Map<String, String> paramMap, int page, int pageSize) throws Exception {
|
|
|
List<String> sknList = new ArrayList<>();
|
|
|
String firstSkns = paramMap.get(SearchRequestParams.PARAM_SEARCH_FIRST_PRODUCRSKN);
|
|
|
if(!StringUtils.isBlank(firstSkns)){
|
|
|
if (!StringUtils.isBlank(firstSkns)) {
|
|
|
sknList = Lists.newArrayList(firstSkns.split(","));
|
|
|
}
|
|
|
BoolQueryBuilder filter = searchQueryHelper.constructFilterBuilder(paramMap, null);
|
...
|
...
|
@@ -161,7 +181,7 @@ public class YzService extends BaseSceneService { |
|
|
return searchParam;
|
|
|
}
|
|
|
|
|
|
private SearchParam getSearchParam(Map<String, String> paramMap, String productSkn, List<Integer> smallSortIds, int viewNum) throws Exception{
|
|
|
private SearchParam getSearchParam(Map<String, String> paramMap, String productSkn, List<Integer> smallSortIds, int viewNum) throws Exception {
|
|
|
Map<String, String> newParamMap = new HashMap<>(paramMap);
|
|
|
newParamMap.remove(SearchRequestParams.PARAM_SEARCH_PRODUCT_SKN);
|
|
|
newParamMap.remove(SearchRequestParams.PARAM_SEARCH_STOCKNUM);
|
...
|
...
|
@@ -171,7 +191,7 @@ public class YzService extends BaseSceneService { |
|
|
}
|
|
|
List<String> sknList = new ArrayList<>();
|
|
|
String firstSkns = newParamMap.get(SearchRequestParams.PARAM_SEARCH_FIRST_PRODUCRSKN);
|
|
|
if(!StringUtils.isBlank(firstSkns)){
|
|
|
if (!StringUtils.isBlank(firstSkns)) {
|
|
|
sknList = Lists.newArrayList(firstSkns.split(","));
|
|
|
}
|
|
|
BoolQueryBuilder filter = searchQueryHelper.constructFilterBuilder(newParamMap, null);
|
...
|
...
|
|