Authored by hugufei

修复价格带排序的问题

@@ -55,27 +55,4 @@ public class ProductListSortService { @@ -55,27 +55,4 @@ public class ProductListSortService {
55 } 55 }
56 return tempResults; 56 return tempResults;
57 } 57 }
58 -  
59 - public <K> List<Map<String,Object>> sortProductListByProductSkn(List<Map<String,Object>> productList, List<K> productSkns, int size,Transfer<Map<String,Object>,K> transfer){  
60 - List<Map<String,Object>> results = new ArrayList<>();  
61 - if(productList==null || productList.isEmpty()){  
62 - return results;  
63 - }  
64 - if(productSkns==null || productSkns.isEmpty() || size<=0){  
65 - return results;  
66 - }  
67 - Map<K, Map<String,Object>> productMap = CollectionUtils.toMap(productList, transfer);  
68 - for (K productSkn : productSkns){  
69 - if(productMap.containsKey(productSkn)){  
70 - Map<String,Object> product = productMap.get(productSkn);  
71 - results.add(new HashMap<>(product));//注意循环引用  
72 - }  
73 - if(results.size()>=size){  
74 - break;  
75 - }  
76 - }  
77 - return results;  
78 - }  
79 -  
80 -  
81 } 58 }
@@ -10,6 +10,7 @@ import com.yoho.search.models.SearchApiResult; @@ -10,6 +10,7 @@ import com.yoho.search.models.SearchApiResult;
10 import com.yoho.search.service.base.ProductListSortService; 10 import com.yoho.search.service.base.ProductListSortService;
11 import com.yoho.search.service.base.SearchCommonService; 11 import com.yoho.search.service.base.SearchCommonService;
12 import com.yoho.search.service.base.index.ProductIndexBaseService; 12 import com.yoho.search.service.base.index.ProductIndexBaseService;
  13 +import com.yoho.search.service.helper.SearchCommonHelper;
13 import com.yoho.search.service.helper.SearchParamHelper; 14 import com.yoho.search.service.helper.SearchParamHelper;
14 import com.yoho.search.service.helper.SearchSortHelper; 15 import com.yoho.search.service.helper.SearchSortHelper;
15 import org.apache.commons.lang.StringUtils; 16 import org.apache.commons.lang.StringUtils;
@@ -36,6 +37,8 @@ public class DefaultProductListService { @@ -36,6 +37,8 @@ public class DefaultProductListService {
36 private ProductIndexBaseService productIndexBaseService; 37 private ProductIndexBaseService productIndexBaseService;
37 @Autowired 38 @Autowired
38 private SearchCommonService searchCommonService; 39 private SearchCommonService searchCommonService;
  40 + @Autowired
  41 + private SearchCommonHelper searchCommonHelper;
39 42
40 /** 43 /**
41 * 非个性化的列表接口-去除uid缓存 44 * 非个性化的列表接口-去除uid缓存
@@ -46,7 +49,7 @@ public class DefaultProductListService { @@ -46,7 +49,7 @@ public class DefaultProductListService {
46 */ 49 */
47 @SearchCacheAble(cacheName = "PRODUCT_LIST_NOT_PERSIONAL", cacheType = CacheType.SEARCH_REDIS, cacheInMinute = 10, excludeParams = { "uid", "firstProductSkn" }) 50 @SearchCacheAble(cacheName = "PRODUCT_LIST_NOT_PERSIONAL", cacheType = CacheType.SEARCH_REDIS, cacheInMinute = 10, excludeParams = { "uid", "firstProductSkn" })
48 public SearchApiResult productListNotPersional(Map<String, String> paramMap) { 51 public SearchApiResult productListNotPersional(Map<String, String> paramMap) {
49 - return this.productList(paramMap,false); 52 + return this.productList(paramMap);
50 } 53 }
51 54
52 /** 55 /**
@@ -57,10 +60,10 @@ public class DefaultProductListService { @@ -57,10 +60,10 @@ public class DefaultProductListService {
57 */ 60 */
58 @SearchCacheAble(cacheName = "PRODUCT_LIST_DEFAULT_PERSIONAL", cacheType = CacheType.SEARCH_REDIS, cacheInMinute = 10) 61 @SearchCacheAble(cacheName = "PRODUCT_LIST_DEFAULT_PERSIONAL", cacheType = CacheType.SEARCH_REDIS, cacheInMinute = 10)
59 public SearchApiResult productListForDefaultPersional(Map<String, String> paramMap) { 62 public SearchApiResult productListForDefaultPersional(Map<String, String> paramMap) {
60 - return this.productList(paramMap,true); 63 + return this.productList(paramMap);
61 } 64 }
62 65
63 - private SearchApiResult productList(Map<String, String> paramMap,boolean reSort){ 66 + private SearchApiResult productList(Map<String, String> paramMap){
64 try { 67 try {
65 // 1)获取分页参数 68 // 1)获取分页参数
66 int page = StringUtils.isBlank(paramMap.get("page")) ? 1 : Integer.parseInt(paramMap.get("page")); 69 int page = StringUtils.isBlank(paramMap.get("page")) ? 1 : Integer.parseInt(paramMap.get("page"));
@@ -84,7 +87,7 @@ public class DefaultProductListService { @@ -84,7 +87,7 @@ public class DefaultProductListService {
84 dataMap.put("page_size", searchParam.getSize()); 87 dataMap.put("page_size", searchParam.getSize());
85 dataMap.put("page_total", searchResult.getTotalPage()); 88 dataMap.put("page_total", searchResult.getTotalPage());
86 List<Map<String, Object>> product_list = productIndexBaseService.getProductListWithPricePlan(searchResult.getResultList()); 89 List<Map<String, Object>> product_list = productIndexBaseService.getProductListWithPricePlan(searchResult.getResultList());
87 - if(reSort){ 90 + if(searchCommonHelper.isOrderEmpty(paramMap)){
88 product_list = productListSortService.sortProductList(product_list);// 处理一下商品的顺序; 91 product_list = productListSortService.sortProductList(product_list);// 处理一下商品的顺序;
89 } 92 }
90 dataMap.put("product_list",product_list); 93 dataMap.put("product_list",product_list);
@@ -10,6 +10,7 @@ import com.yoho.search.models.SearchApiResult; @@ -10,6 +10,7 @@ import com.yoho.search.models.SearchApiResult;
10 import com.yoho.search.service.base.ProductListSortService; 10 import com.yoho.search.service.base.ProductListSortService;
11 import com.yoho.search.service.base.SearchCommonService; 11 import com.yoho.search.service.base.SearchCommonService;
12 import com.yoho.search.service.base.index.ProductIndexBaseService; 12 import com.yoho.search.service.base.index.ProductIndexBaseService;
  13 +import com.yoho.search.service.helper.SearchCommonHelper;
13 import com.yoho.search.service.helper.SearchParamHelper; 14 import com.yoho.search.service.helper.SearchParamHelper;
14 import com.yoho.search.service.helper.SearchSortHelper; 15 import com.yoho.search.service.helper.SearchSortHelper;
15 import com.yoho.search.service.scene.common.AbstractCacheAbleService; 16 import com.yoho.search.service.scene.common.AbstractCacheAbleService;
@@ -36,6 +37,8 @@ public class FuzzySceneProductListService extends AbstractCacheAbleService { @@ -36,6 +37,8 @@ public class FuzzySceneProductListService extends AbstractCacheAbleService {
36 private SearchSortHelper searchSortHelper; 37 private SearchSortHelper searchSortHelper;
37 @Autowired 38 @Autowired
38 private ProductListSortService productListSortService; 39 private ProductListSortService productListSortService;
  40 + @Autowired
  41 + private SearchCommonHelper searchCommonHelper;
39 42
40 @Override 43 @Override
41 public SearchCache getSearchCache() { 44 public SearchCache getSearchCache() {
@@ -75,7 +78,10 @@ public class FuzzySceneProductListService extends AbstractCacheAbleService { @@ -75,7 +78,10 @@ public class FuzzySceneProductListService extends AbstractCacheAbleService {
75 dataMap.put("page_size", searchParam.getSize()); 78 dataMap.put("page_size", searchParam.getSize());
76 dataMap.put("page_total", searchResult.getTotalPage()); 79 dataMap.put("page_total", searchResult.getTotalPage());
77 List<Map<String, Object>> product_list = productIndexBaseService.getProductListWithPricePlan(searchResult.getResultList()); 80 List<Map<String, Object>> product_list = productIndexBaseService.getProductListWithPricePlan(searchResult.getResultList());
78 - dataMap.put("product_list", productListSortService.sortProductList(product_list));// 处理一下商品的顺序; 81 + if(searchCommonHelper.isOrderEmpty(paramMap)){
  82 + product_list = productListSortService.sortProductList(product_list);// 处理一下商品的顺序;
  83 + }
  84 + dataMap.put("product_list",product_list);
79 85
80 // 5)将结果存进缓存 86 // 5)将结果存进缓存
81 searchCacheService.addJSONObjectToCache(this.searchCache, indexName, searchParam, dataMap); 87 searchCacheService.addJSONObjectToCache(this.searchCache, indexName, searchParam, dataMap);
@@ -133,7 +133,11 @@ public class WebProductListService extends AbstractCacheAbleService { @@ -133,7 +133,11 @@ public class WebProductListService extends AbstractCacheAbleService {
133 dataMap.put("page_total", searchResult.getTotalPage()); 133 dataMap.put("page_total", searchResult.getTotalPage());
134 134
135 List<Map<String, Object>> product_list = webProductIndexBaseService.getProductListWithPricePlan(searchResult.getResultList()); 135 List<Map<String, Object>> product_list = webProductIndexBaseService.getProductListWithPricePlan(searchResult.getResultList());
136 - dataMap.put("product_list", productListSortService.sortProductList(product_list));// 处理一下商品的顺序 136 +
  137 + if(searchCommonHelper.isOrderEmpty(paramMap)){
  138 + product_list = productListSortService.sortProductList(product_list);// 处理一下商品的顺序;
  139 + }
  140 + dataMap.put("product_list",product_list);
137 141
138 // 9)将结果存进缓存 142 // 9)将结果存进缓存
139 searchCacheService.addJSONObjectToCache(this.searchCache, indexName, searchParam, dataMap); 143 searchCacheService.addJSONObjectToCache(this.searchCache, indexName, searchParam, dataMap);
@@ -127,11 +127,11 @@ public class ProductListServiceImpl implements IProductListService { @@ -127,11 +127,11 @@ public class ProductListServiceImpl implements IProductListService {
127 dataMap.put("page_size", searchParam.getSize()); 127 dataMap.put("page_size", searchParam.getSize());
128 dataMap.put("page_total", searchResult.getTotalPage()); 128 dataMap.put("page_total", searchResult.getTotalPage());
129 List<Map<String, Object>> product_list = productIndexBaseService.getProductListWithPricePlan(searchResult.getResultList()); 129 List<Map<String, Object>> product_list = productIndexBaseService.getProductListWithPricePlan(searchResult.getResultList());
130 - dataMap.put("product_list", productListSortService.sortProductList(product_list));// 处理一下商品的顺序 130 + dataMap.put("product_list", product_list);
131 return new SearchApiResult().setData(dataMap); 131 return new SearchApiResult().setData(dataMap);
132 } catch (Exception e) { 132 } catch (Exception e) {
133 - logger.error("[func=productListBySkn][params=" + paramMap + "]", e);  
134 - return SearchApiResultUtils.errorSearchApiResult("productListBySkn", paramMap, e); 133 + logger.error("[func=productListWithPhrase][params=" + paramMap + "]", e);
  134 + return SearchApiResultUtils.errorSearchApiResult("productListWithPhrase", paramMap, e);
135 } 135 }
136 } 136 }
137 137