Authored by hugufei

首页猜你喜欢支持资源位直通车

... ... @@ -38,7 +38,7 @@ public class CsSearchResourceIndexBaseService {
@Autowired
private SearchCommonService searchCommonService;
//Guava Cache
// Guava Cache
private LoadingCache<String, List<Map<String, Object>>> salesCategorySearchResourceCache = CacheBuilder.newBuilder()
.maximumSize(100).expireAfterWrite(3, TimeUnit.MINUTES).build(new CacheLoader<String, List<Map<String, Object>>>() {
public List<Map<String, Object>> load(String key) {
... ... @@ -46,7 +46,7 @@ public class CsSearchResourceIndexBaseService {
}
});
//Guava Cache
// Guava Cache
private LoadingCache<String, List<Map<String, Object>>> ufoSearchResourceCache = CacheBuilder.newBuilder()
.maximumSize(100).expireAfterWrite(3, TimeUnit.MINUTES).build(new CacheLoader<String, List<Map<String, Object>>>() {
public List<Map<String, Object>> load(String key) {
... ... @@ -54,7 +54,7 @@ public class CsSearchResourceIndexBaseService {
}
});
//Guava Cache
// Guava Cache
private LoadingCache<String, List<Map<String, Object>>> newArrivalSearchResourceCache = CacheBuilder.newBuilder()
.maximumSize(100).expireAfterWrite(3, TimeUnit.MINUTES).build(new CacheLoader<String, List<Map<String, Object>>>() {
public List<Map<String, Object>> load(String key) {
... ... @@ -62,7 +62,17 @@ public class CsSearchResourceIndexBaseService {
}
});
//获取销售类目当前生效的全部资源位之停车
// Guava Cache
private LoadingCache<String, List<Map<String, Object>>> firstPageSearchResourceCache = CacheBuilder.newBuilder()
.maximumSize(100).expireAfterWrite(3, TimeUnit.MINUTES).build(new CacheLoader<String, List<Map<String, Object>>>() {
public List<Map<String, Object>> load(String key) {
return queryValidValidCsSearchResourceFromEs(Arrays.asList(5),100);
}
});
// 获取销售类目当前生效的全部资源位之停车
public List<Map<String, Object>> querySalesCategoryCsSearchResource() {
try {
return salesCategorySearchResourceCache.get(CACHE_KEY);
... ... @@ -72,7 +82,7 @@ public class CsSearchResourceIndexBaseService {
}
}
//获取UFO目当前生效的全部资源位之停车
// 获取UFO目当前生效的全部资源位之停车
public List<Map<String, Object>> queryUfoCsSearchResources() {
try {
return ufoSearchResourceCache.get(CACHE_KEY);
... ... @@ -82,7 +92,7 @@ public class CsSearchResourceIndexBaseService {
}
}
//获取新品到着的直通车
// 获取新品到着的直通车
public List<Map<String, Object>> queryNewArrivalCsSearchResources() {
try {
return newArrivalSearchResourceCache.get(CACHE_KEY);
... ... @@ -92,6 +102,16 @@ public class CsSearchResourceIndexBaseService {
}
}
// 获取首页猜你喜欢的直通车
public List<Map<String,Object>> queryFirstPageSearchResource() {
try {
return firstPageSearchResourceCache.get(CACHE_KEY);
} catch (Exception e) {
logger.error(e.getMessage(), e);
return new ArrayList<>(0);
}
}
private List<Map<String, Object>> queryValidValidCsSearchResourceFromEs(List<Integer> resourceTypes,int limit) {
try {
SearchParam searchParam = new SearchParam();
... ... @@ -147,4 +167,5 @@ public class CsSearchResourceIndexBaseService {
}
}
... ...
... ... @@ -39,7 +39,7 @@ public class CsSearchResourceService {
@Autowired
private SearchDynamicConfigService searchDynamicConfigService;
//处理品类页的资源位直通车
// 处理品类页的资源位直通车
public List<Map<String, Object>> querySortSearchResource(JSONObject productListData, Map<String, String> paramMap) {
try {
//0、判断是否开启
... ... @@ -96,6 +96,27 @@ public class CsSearchResourceService {
}
}
//处理首页猜你喜欢的资源位直通车
public List<Map<String, Object>> queryFirstPageSearchResource(JSONObject productListData, Map<String, String> paramMap) {
try {
// 1、校验 productListData
if (productListData == null || productListData.get("product_list") == null) {
return new ArrayList<>();
}
List productList = (List) productListData.get("product_list");
List<Map<String, Object>> searchRsesourceList = csSearchResourceIndexBaseService.queryFirstPageSearchResource();
// 2、执行分页截取
int page = MapUtils.getIntValue(paramMap, "page", 1);
int pageSize = MapUtils.getIntValue(paramMap, "viewNum", 10);
return this.doPageSearchResource(searchRsesourceList, productList, page, pageSize);
} catch (Exception e) {
logger.error(e.getMessage(), e);
return new ArrayList<>();
}
}
//处理UFO首页的资源位直通车
public List<Map<String, Object>> queryUfoCsSearchResource(JSONObject productListData, int page, int viewNum) {
... ... @@ -112,7 +133,7 @@ public class CsSearchResourceService {
}
}
//分页处理searchResourceList
// 分页处理searchResourceList
private List<Map<String, Object>> doPageSearchResource(List<Map<String, Object>> searchResourceList, List<?> productList, int page, int viewNum) {
if (CollectionUtils.isEmpty(searchResourceList) || productList == null || productList.isEmpty()) {
return new ArrayList<>();
... ...
... ... @@ -6,6 +6,7 @@ import com.yoho.search.common.SearchRequestParams;
import com.yoho.search.common.utils.SearchApiResultUtils;
import com.yoho.search.core.es.utils.PageUtils;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.scene.general.CsSearchResourceService;
import com.yoho.search.service.scene.pages.entrance.ProductListSwitchService;
import org.apache.commons.collections.MapUtils;
import org.slf4j.Logger;
... ... @@ -22,6 +23,8 @@ public class FirstPageSceneService extends AbstractPageSceneService {
@Autowired
private ProductListSwitchService productListSwitchService;
@Autowired
private CsSearchResourceService csSearchResourceService;
@Override
public String pageId() {
... ... @@ -32,8 +35,8 @@ public class FirstPageSceneService extends AbstractPageSceneService {
public void addParamsToParamMap(Map<String, String> paramMap) {
super.addDefaultParamsToParamMap(paramMap);
//super.filterNotNormalToMap(paramMap);
paramMap.put(SearchRequestParams.PARAM_SEARCH_REC_TYPE,"1");
paramMap.put(SearchRequestParams.PARAM_SEARCH_CONTAIN_UFO,"Y");
paramMap.put(SearchRequestParams.PARAM_SEARCH_REC_TYPE, "1");
paramMap.put(SearchRequestParams.PARAM_SEARCH_CONTAIN_UFO, "Y");
}
@Override
... ... @@ -41,15 +44,21 @@ public class FirstPageSceneService extends AbstractPageSceneService {
try {
// 1、添加默认参数
this.addParamsToParamMap(paramMap);
// 2、返回商品列表
SearchApiResult searchApiResult = productListSwitchService.productList(this.newParamMap(paramMap));
JSONObject jsonObject = (JSONObject) searchApiResult.getData();
// 3、限制最大返回条数为200条
long total = Math.min(MapUtils.getIntValue(jsonObject, "total", 0), 200L);
int page_size = MapUtils.getIntValue(jsonObject, "page_size", 0);
jsonObject.put("total", total);
jsonObject.put("page_total", PageUtils.getTotalPage(total,page_size));
JSONObject data = (JSONObject) searchApiResult.getData();
// 3、获取首页资源位直通车
data.put(SEARCH_RESOURCE_LIST, csSearchResourceService.queryFirstPageSearchResource(data, paramMap));//search_resource_list
// 4、限制最大返回条数为200条
long total = Math.min(MapUtils.getIntValue(data, "total", 0), 200L);
int page_size = MapUtils.getIntValue(data, "page_size", 0);
data.put("total", total);
data.put("page_total", PageUtils.getTotalPage(total, page_size));
return searchApiResult;
} catch (Exception e) {
return SearchApiResultUtils.errorSearchApiResult(logger, paramMap, e);
}
... ...