Authored by hugufei

修复价格带排序的问题

... ... @@ -55,27 +55,4 @@ public class ProductListSortService {
}
return tempResults;
}
public <K> List<Map<String,Object>> sortProductListByProductSkn(List<Map<String,Object>> productList, List<K> productSkns, int size,Transfer<Map<String,Object>,K> transfer){
List<Map<String,Object>> results = new ArrayList<>();
if(productList==null || productList.isEmpty()){
return results;
}
if(productSkns==null || productSkns.isEmpty() || size<=0){
return results;
}
Map<K, Map<String,Object>> productMap = CollectionUtils.toMap(productList, transfer);
for (K productSkn : productSkns){
if(productMap.containsKey(productSkn)){
Map<String,Object> product = productMap.get(productSkn);
results.add(new HashMap<>(product));//注意循环引用
}
if(results.size()>=size){
break;
}
}
return results;
}
}
... ...
... ... @@ -10,6 +10,7 @@ import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.base.ProductListSortService;
import com.yoho.search.service.base.SearchCommonService;
import com.yoho.search.service.base.index.ProductIndexBaseService;
import com.yoho.search.service.helper.SearchCommonHelper;
import com.yoho.search.service.helper.SearchParamHelper;
import com.yoho.search.service.helper.SearchSortHelper;
import org.apache.commons.lang.StringUtils;
... ... @@ -36,6 +37,8 @@ public class DefaultProductListService {
private ProductIndexBaseService productIndexBaseService;
@Autowired
private SearchCommonService searchCommonService;
@Autowired
private SearchCommonHelper searchCommonHelper;
/**
* 非个性化的列表接口-去除uid缓存
... ... @@ -46,7 +49,7 @@ public class DefaultProductListService {
*/
@SearchCacheAble(cacheName = "PRODUCT_LIST_NOT_PERSIONAL", cacheType = CacheType.SEARCH_REDIS, cacheInMinute = 10, excludeParams = { "uid", "firstProductSkn" })
public SearchApiResult productListNotPersional(Map<String, String> paramMap) {
return this.productList(paramMap,false);
return this.productList(paramMap);
}
/**
... ... @@ -57,10 +60,10 @@ public class DefaultProductListService {
*/
@SearchCacheAble(cacheName = "PRODUCT_LIST_DEFAULT_PERSIONAL", cacheType = CacheType.SEARCH_REDIS, cacheInMinute = 10)
public SearchApiResult productListForDefaultPersional(Map<String, String> paramMap) {
return this.productList(paramMap,true);
return this.productList(paramMap);
}
private SearchApiResult productList(Map<String, String> paramMap,boolean reSort){
private SearchApiResult productList(Map<String, String> paramMap){
try {
// 1)获取分页参数
int page = StringUtils.isBlank(paramMap.get("page")) ? 1 : Integer.parseInt(paramMap.get("page"));
... ... @@ -84,7 +87,7 @@ public class DefaultProductListService {
dataMap.put("page_size", searchParam.getSize());
dataMap.put("page_total", searchResult.getTotalPage());
List<Map<String, Object>> product_list = productIndexBaseService.getProductListWithPricePlan(searchResult.getResultList());
if(reSort){
if(searchCommonHelper.isOrderEmpty(paramMap)){
product_list = productListSortService.sortProductList(product_list);// 处理一下商品的顺序;
}
dataMap.put("product_list",product_list);
... ...
... ... @@ -10,6 +10,7 @@ import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.base.ProductListSortService;
import com.yoho.search.service.base.SearchCommonService;
import com.yoho.search.service.base.index.ProductIndexBaseService;
import com.yoho.search.service.helper.SearchCommonHelper;
import com.yoho.search.service.helper.SearchParamHelper;
import com.yoho.search.service.helper.SearchSortHelper;
import com.yoho.search.service.scene.common.AbstractCacheAbleService;
... ... @@ -36,6 +37,8 @@ public class FuzzySceneProductListService extends AbstractCacheAbleService {
private SearchSortHelper searchSortHelper;
@Autowired
private ProductListSortService productListSortService;
@Autowired
private SearchCommonHelper searchCommonHelper;
@Override
public SearchCache getSearchCache() {
... ... @@ -75,7 +78,10 @@ public class FuzzySceneProductListService extends AbstractCacheAbleService {
dataMap.put("page_size", searchParam.getSize());
dataMap.put("page_total", searchResult.getTotalPage());
List<Map<String, Object>> product_list = productIndexBaseService.getProductListWithPricePlan(searchResult.getResultList());
dataMap.put("product_list", productListSortService.sortProductList(product_list));// 处理一下商品的顺序;
if(searchCommonHelper.isOrderEmpty(paramMap)){
product_list = productListSortService.sortProductList(product_list);// 处理一下商品的顺序;
}
dataMap.put("product_list",product_list);
// 5)将结果存进缓存
searchCacheService.addJSONObjectToCache(this.searchCache, indexName, searchParam, dataMap);
... ...
... ... @@ -133,7 +133,11 @@ public class WebProductListService extends AbstractCacheAbleService {
dataMap.put("page_total", searchResult.getTotalPage());
List<Map<String, Object>> product_list = webProductIndexBaseService.getProductListWithPricePlan(searchResult.getResultList());
dataMap.put("product_list", productListSortService.sortProductList(product_list));// 处理一下商品的顺序
if(searchCommonHelper.isOrderEmpty(paramMap)){
product_list = productListSortService.sortProductList(product_list);// 处理一下商品的顺序;
}
dataMap.put("product_list",product_list);
// 9)将结果存进缓存
searchCacheService.addJSONObjectToCache(this.searchCache, indexName, searchParam, dataMap);
... ...
... ... @@ -127,11 +127,11 @@ public class ProductListServiceImpl implements IProductListService {
dataMap.put("page_size", searchParam.getSize());
dataMap.put("page_total", searchResult.getTotalPage());
List<Map<String, Object>> product_list = productIndexBaseService.getProductListWithPricePlan(searchResult.getResultList());
dataMap.put("product_list", productListSortService.sortProductList(product_list));// 处理一下商品的顺序
dataMap.put("product_list", product_list);
return new SearchApiResult().setData(dataMap);
} catch (Exception e) {
logger.error("[func=productListBySkn][params=" + paramMap + "]", e);
return SearchApiResultUtils.errorSearchApiResult("productListBySkn", paramMap, e);
logger.error("[func=productListWithPhrase][params=" + paramMap + "]", e);
return SearchApiResultUtils.errorSearchApiResult("productListWithPhrase", paramMap, e);
}
}
... ...