...
|
...
|
@@ -4,15 +4,17 @@ import com.alibaba.fastjson.JSONObject; |
|
|
import com.yoho.search.base.utils.CollectionUtils;
|
|
|
import com.yoho.search.base.utils.ISearchConstants;
|
|
|
import com.yoho.search.base.utils.ProductIndexEsField;
|
|
|
import com.yoho.search.base.utils.Transfer;
|
|
|
import com.yoho.search.core.es.model.SearchParam;
|
|
|
import com.yoho.search.core.es.model.SearchResult;
|
|
|
import com.yoho.search.models.SearchApiResult;
|
|
|
import com.yoho.search.recall.scene.beans.cache.QueryRecallResultCacheBean;
|
|
|
import com.yoho.search.recall.scene.beans.builder.RecallParamsBuilder;
|
|
|
import com.yoho.search.recall.scene.beans.cache.QueryProductInfoCacheBean;
|
|
|
import com.yoho.search.recall.scene.beans.cache.QueryRecallResultCacheBean;
|
|
|
import com.yoho.search.recall.scene.beans.helper.SortBuilderHelper;
|
|
|
import com.yoho.search.recall.scene.models.*;
|
|
|
import com.yoho.search.recall.scene.beans.builder.RecallParamsBuilder;
|
|
|
import com.yoho.search.recall.scene.models.RecallParams;
|
|
|
import com.yoho.search.recall.scene.models.RecallResult;
|
|
|
import com.yoho.search.recall.scene.models.RecallSknInfo;
|
|
|
import com.yoho.search.service.base.SearchCommonService;
|
|
|
import com.yoho.search.service.helper.SearchCommonHelper;
|
|
|
import org.apache.commons.collections.MapUtils;
|
...
|
...
|
@@ -73,34 +75,67 @@ public class SceneRecallProductListService { |
|
|
}
|
|
|
}
|
|
|
|
|
|
private List<Integer> getProductSknList(List<RecallSknInfo> recallSknInfos){
|
|
|
List<Integer> productSknList = new ArrayList<>();
|
|
|
for (RecallSknInfo recallSknInfo:recallSknInfos ){
|
|
|
productSknList.add(recallSknInfo.getProductSkn());
|
|
|
}
|
|
|
return productSknList;
|
|
|
}
|
|
|
|
|
|
private List<Map<String, Object>> queryProductList(RecallParams recallParams, RecallResult recallResult, int page, int pageSize) {
|
|
|
//1、判断当前页码是否在召回的页码里
|
|
|
int recallTotalPage = recallResult.getRecallTotalPage();
|
|
|
//2、在召回结果中则直接根据skn去查询
|
|
|
List<Integer> productSkns = null;
|
|
|
List<RecallSknInfo> recallSknInfos = null;
|
|
|
if(page<=recallTotalPage){
|
|
|
productSkns = CollectionUtils.safeSubList(recallResult.getSknList(),(page-1)*pageSize,page*pageSize);
|
|
|
recallSknInfos = CollectionUtils.safeSubList(recallResult.getSknList(),(page-1)*pageSize,page*pageSize);
|
|
|
}else{
|
|
|
//3、过滤召回的skn,修改真实页码,执行查询
|
|
|
productSkns = this.queryProductSknByFilterSkn(recallParams, recallResult.getSknList(), recallTotalPage-page, pageSize);
|
|
|
recallSknInfos = this.queryProductSknByFilterSkn(recallParams, recallResult.getSknList(), recallTotalPage-page, pageSize);
|
|
|
}
|
|
|
return queryProductInfoCacheBean.queryProductListBySkn(productSkns,productSkns.size());
|
|
|
//3、获取召回结果的skn
|
|
|
List<Integer> productSknList = this.getProductSknList(recallSknInfos);
|
|
|
|
|
|
//4、获取商品的返回信息
|
|
|
List<Map<String, Object>> productInfoList = queryProductInfoCacheBean.queryProductListBySkn(productSknList,productSknList.size());
|
|
|
|
|
|
//5、填充召回类型
|
|
|
Map<Integer,RecallSknInfo> sknRecallTypeMap = CollectionUtils.toMap(recallSknInfos, new Transfer<RecallSknInfo, Integer>() {
|
|
|
@Override
|
|
|
public Integer transfer(RecallSknInfo recallSknInfo) {
|
|
|
return recallSknInfo.getProductSkn();
|
|
|
}
|
|
|
});
|
|
|
for(Map<String, Object> productInfo: productInfoList){
|
|
|
int productSkn = MapUtils.getIntValue(productInfo,"product_skn",0);
|
|
|
RecallSknInfo recallSknInfo = sknRecallTypeMap.get(productSkn);
|
|
|
if(recallSknInfo==null || recallSknInfo.getRecallType()==null){
|
|
|
productInfo.put("recall_type","default");
|
|
|
}else{
|
|
|
productInfo.put("recall_type",recallSknInfo.getRecallType());
|
|
|
}
|
|
|
}
|
|
|
return productInfoList;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 过滤掉已召回的skn,并按人气排序
|
|
|
* @param notProductSkns
|
|
|
* @param recallSknInfos
|
|
|
* @param realPage
|
|
|
* @param pageSize
|
|
|
* @return
|
|
|
*/
|
|
|
private List<Integer> queryProductSknByFilterSkn(RecallParams recallParams, List<Integer> notProductSkns, int realPage, int pageSize){
|
|
|
private List<RecallSknInfo> queryProductSknByFilterSkn(RecallParams recallParams, List<RecallSknInfo> recallSknInfos, int realPage, int pageSize){
|
|
|
SearchParam searchParam = new SearchParam();
|
|
|
|
|
|
//1、设置query
|
|
|
searchParam.setQuery(recallParams.getParamQueryFilter().getParamQuery());
|
|
|
|
|
|
//2、设置filter
|
|
|
List<Integer> notProductSkns = new ArrayList<>();
|
|
|
for (RecallSknInfo recallSknInfo:recallSknInfos ){
|
|
|
notProductSkns.add(recallSknInfo.getProductSkn());
|
|
|
}
|
|
|
BoolQueryBuilder filter = recallParams.getParamQueryFilter().getParamFilter();
|
|
|
filter.mustNot(QueryBuilders.termsQuery(ProductIndexEsField.productSkn,notProductSkns));
|
|
|
searchParam.setFiter(filter);
|
...
|
...
|
@@ -119,9 +154,10 @@ public class SceneRecallProductListService { |
|
|
searchParam.setSortBuilders(sortBuilders);
|
|
|
SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_PRODUCT_BASE_INDEX,searchParam);
|
|
|
|
|
|
List<Integer> results = new ArrayList<>();
|
|
|
//6、构造返回结果
|
|
|
List<RecallSknInfo> results = new ArrayList<>();
|
|
|
for (Map<String, Object> product : searchResult.getResultList()) {
|
|
|
results.add(MapUtils.getIntValue(product,ProductIndexEsField.productSkn,0));
|
|
|
results.add(new RecallSknInfo(MapUtils.getIntValue(product,ProductIndexEsField.productSkn,0),"DEFAULT"));
|
|
|
}
|
|
|
return results;
|
|
|
}
|
...
|
...
|
|