Authored by wangnan9279

ufo

@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject; @@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
4 import com.yoho.search.aop.cache.SearchCacheAble; 4 import com.yoho.search.aop.cache.SearchCacheAble;
5 import com.yoho.search.base.utils.ISearchConstants; 5 import com.yoho.search.base.utils.ISearchConstants;
6 import com.yoho.search.common.SearchCommonService; 6 import com.yoho.search.common.SearchCommonService;
  7 +import com.yoho.search.common.SearchRequestParams;
7 import com.yoho.search.core.es.model.SearchParam; 8 import com.yoho.search.core.es.model.SearchParam;
8 import com.yoho.search.core.es.model.SearchResult; 9 import com.yoho.search.core.es.model.SearchResult;
9 import com.yoho.search.models.SearchApiResult; 10 import com.yoho.search.models.SearchApiResult;
@@ -20,6 +21,7 @@ import org.springframework.beans.factory.annotation.Autowired; @@ -20,6 +21,7 @@ import org.springframework.beans.factory.annotation.Autowired;
20 import org.springframework.stereotype.Service; 21 import org.springframework.stereotype.Service;
21 22
22 import java.util.*; 23 import java.util.*;
  24 +import java.util.stream.Collectors;
23 25
24 /** 26 /**
25 * @author wangnan 27 * @author wangnan
@@ -76,6 +78,19 @@ public class UfoProductListService { @@ -76,6 +78,19 @@ public class UfoProductListService {
76 dataMap.put("page_size", pageSize); 78 dataMap.put("page_size", pageSize);
77 dataMap.put("page_total", searchResult.getTotalPage()); 79 dataMap.put("page_total", searchResult.getTotalPage());
78 dataMap.put(RETURN_LIST_NAME, returnInfoList); 80 dataMap.put(RETURN_LIST_NAME, returnInfoList);
  81 + // 如果是纯id过滤,按照id传入顺序排序
  82 + if ("Y".equals(paramMap.get(SearchRequestParams.UFOPRODUCTINDEX_PARAM_IS_ID_FILTER))) {
  83 + Map<String, Map<String, Object>> productReturnInfoMap = returnInfoList.stream().collect(Collectors.toMap(p -> p.get("id").toString(), p -> p));
  84 + List<Map<String, Object>> productReturnInfoListSorted = new ArrayList<>(productReturnInfoMap.size());
  85 + List<String> idList = Arrays.asList(paramMap.get(SearchRequestParams.UFOPRODUCTINDEX_PARAM_ID).split(","));
  86 + for (String id : idList) {
  87 + Map<String, Object> sknInfo = productReturnInfoMap.get(id);
  88 + if (sknInfo != null) {
  89 + productReturnInfoListSorted.add(sknInfo);
  90 + }
  91 + }
  92 + dataMap.put(RETURN_LIST_NAME, productReturnInfoListSorted);
  93 + }
79 return new SearchApiResult().setData(dataMap); 94 return new SearchApiResult().setData(dataMap);
80 } catch (Exception e) { 95 } catch (Exception e) {
81 logger.error(e.getMessage(), e); 96 logger.error(e.getMessage(), e);