|
|
package com.yoho.search.recall.scene.cache.beans;
|
|
|
|
|
|
import com.yoho.search.recall.scene.builder.request.BrandRecallRequestBuilder;
|
|
|
import com.yoho.search.recall.scene.builder.request.CommonRecallRequestBuilder;
|
|
|
import com.yoho.search.recall.scene.builder.request.SortPriceRecallRequestBuilder;
|
|
|
import com.yoho.search.recall.scene.builder.response.RecallResponseBatchBuilder;
|
|
|
import com.yoho.search.recall.scene.builder.response.RecallSknResultBuilder;
|
|
|
import com.yoho.search.recall.scene.cache.CacheRequestResponseComponent;
|
|
|
import com.yoho.search.recall.scene.models.RecallRequest;
|
|
|
import com.yoho.search.recall.scene.models.RecallResponseBatch;
|
|
|
import com.yoho.search.recall.scene.models.RecallSknParams;
|
|
|
import com.yoho.search.recall.scene.models.RecallSknResult;
|
|
|
import com.yoho.search.recall.scene.persional.PersionalFactor;
|
|
|
import com.yoho.search.recall.scene.persional.RecallPersionalService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
@Component
|
|
|
public class CacheRecallSknRequestResponseBean extends CacheRequestResponseComponent<RecallSknParams,RecallSknResult,CacheRecallSknRequestResponse>{
|
|
|
|
|
|
@Autowired
|
|
|
private RecallPersionalService recallPersionalService;
|
|
|
@Autowired
|
|
|
private CacheRecallRequestResponseBean cacheRecallRequestResponseBean;
|
|
|
@Autowired
|
|
|
private RecallResponseBatchBuilder recallResponseBatchBuilder;
|
|
|
@Autowired
|
|
|
private RecallSknResultBuilder recallSknResultBuilder;
|
|
|
@Autowired
|
|
|
private CommonRecallRequestBuilder commonRequestBuilder;
|
|
|
@Autowired
|
|
|
private BrandRecallRequestBuilder brandRequestBuilder;
|
|
|
@Autowired
|
|
|
private SortPriceRecallRequestBuilder sortPriceRequestBuilder;
|
|
|
|
|
|
/**
|
|
|
* 召回入口
|
|
|
* @param recallSknParams
|
|
|
* @return
|
|
|
*/
|
|
|
public RecallSknResult doRecallSknResult(RecallSknParams recallSknParams){
|
|
|
//1、构建请求
|
|
|
List<CacheRecallSknRequestResponse> requests = new ArrayList<>();
|
|
|
requests.add(new CacheRecallSknRequestResponse(recallSknParams));
|
|
|
|
|
|
//2、执行父类方法
|
|
|
this.bacthFillResponseWithCache(requests,false);
|
|
|
|
|
|
//3、判断
|
|
|
if(requests.size()==1 && requests.get(0).getResponse()!=null){
|
|
|
return requests.get(0).getResponse();
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Map<RecallSknParams, RecallSknResult> queryMissCacheRequestResults(List<CacheRecallSknRequestResponse> missCachseRequests) {
|
|
|
Map<RecallSknParams, RecallSknResult> results = new HashMap<>();
|
|
|
for (CacheRecallSknRequestResponse request: missCachseRequests) {
|
|
|
RecallSknResult response = this.doRealRecall(request.getRequest());
|
|
|
results.put(request.getRequest(),response);
|
|
|
}
|
|
|
return results;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 真正的召回入口
|
|
|
* @param param
|
|
|
* @return
|
|
|
*/
|
|
|
private RecallSknResult doRealRecall(RecallSknParams param) {
|
|
|
//1、获取个性化因子
|
|
|
PersionalFactor persionalFactor = recallPersionalService.queryPersionalFactor(param);
|
|
|
//2、构造请求
|
|
|
List<RecallRequest> batchRequests = this.buildBatchRequests(param, persionalFactor);
|
|
|
//3、批量召回
|
|
|
List<CacheRecallRequestResponse> requestResponses = cacheRecallRequestResponseBean.batchRecallAndCache(batchRequests);
|
|
|
//4、获取skn列表[去重]
|
|
|
RecallResponseBatch recallResponseBatch = recallResponseBatchBuilder.buildRecallResponseBatch(requestResponses);
|
|
|
//5、构造真实结果[排序,截取skn]
|
|
|
RecallSknResult recallSknResult = recallSknResultBuilder.builderRecallResult(recallResponseBatch, param, persionalFactor);
|
|
|
return recallSknResult;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 批量构造请求
|
|
|
* @param param
|
|
|
* @param persionalFactor
|
|
|
* @return
|
|
|
*/
|
|
|
private List<RecallRequest> buildBatchRequests(RecallSknParams param, PersionalFactor persionalFactor) {
|
|
|
//1、构造召回请求
|
|
|
List<RecallRequest> allRequests = new ArrayList<>();
|
|
|
//2、构造非个性化的请求
|
|
|
List<RecallRequest> commonRequests = commonRequestBuilder.buildCommonRecallRequests(param.getParamQueryFilter(), param.getFirstProductSkns());
|
|
|
allRequests.addAll(commonRequests);
|
|
|
//4、构建个性化品牌的召回请求
|
|
|
List<RecallRequest> brandRequests = brandRequestBuilder.buildBrandRecallRequests(param.getParamQueryFilter(), persionalFactor.getBrandIds());
|
|
|
allRequests.addAll(brandRequests);
|
|
|
//5、构建个性化品牌的召回请求
|
|
|
List<RecallRequest> sortPriceRequests = sortPriceRequestBuilder.buildSortPriceRecallRequests(param.getParamQueryFilter(), persionalFactor.getSortPriceAreas());
|
|
|
allRequests.addAll(sortPriceRequests);
|
|
|
return allRequests;
|
|
|
}
|
|
|
|
|
|
|
|
|
} |
...
|
...
|
|