...
|
...
|
@@ -3,6 +3,7 @@ package com.yoho.search.service.scene.ufo; |
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.yoho.search.aop.cache.SearchCacheAble;
|
|
|
import com.yoho.search.base.constants.ISearchConstants;
|
|
|
import com.yoho.search.base.constants.UfoProductIndexEsField;
|
|
|
import com.yoho.search.cache.CacheInMinute;
|
|
|
import com.yoho.search.common.SearchCommonService;
|
|
|
import com.yoho.search.common.UfoSearchRequestParams;
|
...
|
...
|
@@ -15,6 +16,7 @@ import com.yoho.search.service.index.ufo.UfoProductIndexBaseService; |
|
|
import org.apache.commons.collections.MapUtils;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.elasticsearch.index.query.BoolQueryBuilder;
|
|
|
import org.elasticsearch.index.query.QueryBuilders;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
...
|
...
|
@@ -44,42 +46,39 @@ public class UfoFavoriteService { |
|
|
@Autowired
|
|
|
private CustomizeTagBaseService customizeTagBaseService;
|
|
|
|
|
|
private static final String RETURN_LIST_NAME = "product_list";
|
|
|
|
|
|
@SearchCacheAble(cacheName = "UFO_FAVORITE_LIST", cacheInMinute = CacheInMinute.Minute_UFO)
|
|
|
public SearchApiResult productList(Map<String, String> paramMap) {
|
|
|
public SearchApiResult favoriteProductList(Map<String, String> paramMap) {
|
|
|
try {
|
|
|
// 1、参数校验
|
|
|
if (StringUtils.isBlank(paramMap.get(UfoSearchRequestParams.UFO_PARAM_ID))) {
|
|
|
return new SearchApiResult().setCode(400).setMessage("id参数必传");
|
|
|
}
|
|
|
int page = MapUtils.getIntValue(paramMap, UfoSearchRequestParams.UFO_PARAM_SEARCH_PAGE, 1);
|
|
|
int pageSize = MapUtils.getIntValue(paramMap, UfoSearchRequestParams.UFO_PARAM_SEARCH_VIEWNUM, 10);
|
|
|
pageSize = Math.min(pageSize, 100);
|
|
|
if (page < 1 || pageSize < 0 || page * pageSize > 100000) {
|
|
|
return new SearchApiResult().setCode(400).setMessage("分页参数不合法");
|
|
|
}
|
|
|
if (StringUtils.isBlank(paramMap.get(UfoSearchRequestParams.UFO_PARAM_ID))) {
|
|
|
return new SearchApiResult().setCode(400).setMessage("id参数必传");
|
|
|
}
|
|
|
// 2. 构建SearchParam
|
|
|
|
|
|
// 2. 构建SearchParam[按id和showChannel过滤]
|
|
|
SearchParam searchParam = new SearchParam();
|
|
|
BoolQueryBuilder boolFilter = ufoSearchQueryHelper.constructFilterBuilderIdFilter(paramMap);
|
|
|
BoolQueryBuilder boolFilter = QueryBuilders.boolQuery();
|
|
|
ufoSearchQueryHelper.addMustIntTermsQuery(boolFilter, paramMap, UfoSearchRequestParams.UFO_PARAM_ID, UfoProductIndexEsField.id);
|
|
|
ufoSearchQueryHelper.addMustIntTermsQuery(boolFilter, paramMap, UfoSearchRequestParams.UFO_PARAM_SHOW_CHANNEL, UfoProductIndexEsField.showChannel);
|
|
|
searchParam.setFiter(boolFilter);
|
|
|
searchParam.setAggregationBuilders(null);
|
|
|
|
|
|
// 3、分页
|
|
|
searchParam.setSize(pageSize);
|
|
|
searchParam.setOffset((page - 1) * pageSize);
|
|
|
// 设置返回的结果
|
|
|
// 4、设置返回的结果
|
|
|
searchParam.setIncludeFields(ufoProductIndexBaseService.getUfoProductIndexIncludeFields());
|
|
|
// 执行搜索
|
|
|
// 5、执行搜索
|
|
|
SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_UFO_PRODUCT_INDEX, searchParam);
|
|
|
// 构造返回结果
|
|
|
// 6、构造返回结果
|
|
|
List<Map<String, Object>> returnInfoList = ufoProductIndexBaseService.buildProductReturnInfoList(searchResult.getResultList());
|
|
|
// 添加自定义标签
|
|
|
// 7、添加自定义标签
|
|
|
customizeTagBaseService.fillCustomizeTag(returnInfoList, false);
|
|
|
JSONObject dataMap = new JSONObject();
|
|
|
dataMap.put("total", searchResult.getTotal());
|
|
|
dataMap.put("page", searchResult.getPage());
|
|
|
dataMap.put("page_size", pageSize);
|
|
|
dataMap.put("page_total", searchResult.getTotalPage());
|
|
|
// 按id顺序排序
|
|
|
// 8、按id顺序排序
|
|
|
Map<String, Map<String, Object>> productReturnInfoMap = returnInfoList.stream().collect(Collectors.toMap(p -> p.get("id").toString(), p -> p));
|
|
|
List<Map<String, Object>> productReturnInfoListSorted = new ArrayList<>(productReturnInfoMap.size());
|
|
|
List<String> idList = Arrays.asList(paramMap.get(UfoSearchRequestParams.UFO_PARAM_ID).split(","));
|
...
|
...
|
@@ -89,7 +88,13 @@ public class UfoFavoriteService { |
|
|
productReturnInfoListSorted.add(sknInfo);
|
|
|
}
|
|
|
}
|
|
|
dataMap.put(RETURN_LIST_NAME, productReturnInfoListSorted);
|
|
|
// 9、构造返回结果
|
|
|
JSONObject dataMap = new JSONObject();
|
|
|
dataMap.put("total", searchResult.getTotal());
|
|
|
dataMap.put("page", searchResult.getPage());
|
|
|
dataMap.put("page_size", pageSize);
|
|
|
dataMap.put("page_total", searchResult.getTotalPage());
|
|
|
dataMap.put("product_list", productReturnInfoListSorted);
|
|
|
return new SearchApiResult().setData(dataMap);
|
|
|
} catch (Exception e) {
|
|
|
logger.error(e.getMessage(), e);
|
...
|
...
|
|