Authored by hugufei

fix bug

... ... @@ -59,8 +59,8 @@ public class SceneRecallService {
//3、执行召回
RecallSknResult recallSknResult = recallService.getRecallSknResult(recallSknParams);
//4、根据召回结果查询商品信息
List<Map<String, Object>> productList = this.queryProductList(recallSknParams, recallSknResult,page,pageSize);
//6、构造返回结果
List<Map<String, Object>> productList = this.queryProductList(recallSknParams,recallSknResult,page,pageSize);
//5、构造返回结果
JSONObject dataMap = new JSONObject();
dataMap.put("total", recallSknResult.getTotal());
dataMap.put("page", page);
... ... @@ -74,7 +74,7 @@ public class SceneRecallService {
}
}
private List<Map<String, Object>> queryProductList(RecallSknParams recallSknParams, RecallSknResult recallSknResult,int page,int pageSize) {
private List<Map<String, Object>> queryProductList( RecallSknParams recallSknParams,RecallSknResult recallSknResult,int page,int pageSize) {
//1、判断当前页码是否在召回的页码里
int recallTotalPage = recallSknResult.getRecallTotalPage();
//2、在召回结果中则直接根据skn去查询
... ... @@ -84,7 +84,7 @@ public class SceneRecallService {
}
//3、过滤召回的skn,修改真实页码,执行查询
int realPage = page - recallTotalPage;
return this.queryProductByFilterSkn(recallSknResult.getSknList(), realPage, pageSize);
return this.queryProductByFilterSkn(recallSknParams, recallSknResult.getSknList(), realPage, pageSize);
}
/**
... ... @@ -94,15 +94,20 @@ public class SceneRecallService {
* @param pageSize
* @return
*/
private List<Map<String, Object>> queryProductByFilterSkn(List<Integer> notProductSkns,int realPage,int pageSize){
private List<Map<String, Object>> queryProductByFilterSkn(RecallSknParams recallSknParams,List<Integer> notProductSkns,int realPage,int pageSize){
SearchParam searchParam = new SearchParam();
//设置分页参数
searchParam.setOffset((realPage-1)*pageSize);
searchParam.setSize(pageSize);
//设置query
searchParam.setQuery(recallSknParams.getParamQueryFilter().getParamQuery());
//设置filter
BoolQueryBuilder filter = QueryBuilders.boolQuery();
BoolQueryBuilder filter = recallSknParams.getParamQueryFilter().getParamFilter();
filter.mustNot(QueryBuilders.termsQuery(ProductIndexEsField.productSkn,notProductSkns));
searchParam.setFiter(filter);
//设置分页参数
searchParam.setOffset((realPage-1)*pageSize);
searchParam.setSize(pageSize);
//设置IncludeFields
searchParam.setIncludeFields(productIndexBaseService.getProductIndexIncludeFields());
... ...
... ... @@ -79,13 +79,13 @@ public class CacheRequestResponseComponent {
* @param <V>
* @param <T>
*/
public <K extends ICacheRequest, V, T extends CacheRequestResponse<K, V>> void batchFillResponseWithQueryResults(List<T> cacheRequestResponses,Map<RedisKeyBuilder,V> queryResults){
public <K extends ICacheRequest, V, T extends CacheRequestResponse<K, V>> void batchFillResponseWithQueryResults(List<T> cacheRequestResponses,Map<String,V> queryResults){
for (T sknInfoRequestResponse : cacheRequestResponses) {
if(sknInfoRequestResponse.getResponse()!=null){
continue;
}
RedisKeyBuilder redisKeyBuilder = sknInfoRequestResponse.getRequest().redisKeyBuilder();
V response = queryResults.get(redisKeyBuilder);
V response = queryResults.get(redisKeyBuilder.getKey());
if(response!=null){
sknInfoRequestResponse.setResponse(response,true);
}
... ...
... ... @@ -69,7 +69,7 @@ public class BacthSknInfoComponent {
//3、获取未命中缓存的请求
List<CacheSknInfoRequestResponse> missCacheRequests = cacheRequestResponseComponent.filterMissCacheRequests(sknInfoCacheRequestRespons);
//4、执行批量查询
Map<RedisKeyBuilder,Map<String, Object>> queryResults = this.batchQueryMissCacheRequests(missCacheRequests);
Map<String,Map<String, Object>> queryResults = this.batchQueryMissCacheRequests(missCacheRequests);
//5、填充查询结果
cacheRequestResponseComponent.batchFillResponseWithQueryResults(sknInfoCacheRequestRespons,queryResults);
//6、将CacheRequestResponse中需要缓存的key加入缓存
... ... @@ -77,9 +77,9 @@ public class BacthSknInfoComponent {
return sknInfoCacheRequestRespons;
}
private Map<RedisKeyBuilder,Map<String, Object>> batchQueryMissCacheRequests(List<CacheSknInfoRequestResponse> notCachedRequestResponse) {
private Map<String,Map<String, Object>> batchQueryMissCacheRequests(List<CacheSknInfoRequestResponse> notCachedRequestResponse) {
//1、合法性判断
Map<RedisKeyBuilder,Map<String, Object>> results = new HashMap<>();
Map<String,Map<String, Object>> results = new HashMap<>();
if(notCachedRequestResponse==null||notCachedRequestResponse.isEmpty()){
return results;
}
... ... @@ -103,7 +103,7 @@ public class BacthSknInfoComponent {
}
//5、构造最终结果
for (CacheSknInfoRequestResponse requestResponse :notCachedRequestResponse ) {
results.put(requestResponse.getRequest().redisKeyBuilder(),productTempMap.get(requestResponse.getRequest().getProductSkn()));
results.put(requestResponse.getRequest().redisKeyBuilder().getKey(),productTempMap.get(requestResponse.getRequest().getProductSkn()));
}
return results;
}
... ...
... ... @@ -57,7 +57,7 @@ public class BatchRecallComponent {
}
//5、处理剩余请求
Map<RedisKeyBuilder,RecallResponse> notCacheResults = this.queryNotCachedResult(missCacheRequests);
Map<String,RecallResponse> notCacheResults = this.queryNotCachedResult(missCacheRequests);
//6、填充recallRequestResponses
cacheRequestResponseHelper.batchFillResponseWithQueryResults(recallRequestResponses,notCacheResults);
... ... @@ -74,7 +74,7 @@ public class BatchRecallComponent {
* @param notCachedRequests
* @return
*/
private Map<RedisKeyBuilder,RecallResponse> queryNotCachedResult(List<CacheRecallRequestResponse> notCachedRequests) {
private Map<String,RecallResponse> queryNotCachedResult(List<CacheRecallRequestResponse> notCachedRequests) {
//1、构造请求参数
List<SearchParam> searchParams = new ArrayList<>();
for (CacheRecallRequestResponse requestResponse : notCachedRequests) {
... ... @@ -83,12 +83,12 @@ public class BatchRecallComponent {
//2、执行搜索
List<SearchResult> searchResults = searchCommonService.doMutiSearch(ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParams);
//3、构造返回结果
Map<RedisKeyBuilder,RecallResponse> notCachedResults = new HashMap<>();
Map<String,RecallResponse> notCachedResults = new HashMap<>();
for (int i = 0; i < notCachedRequests.size(); i++) {
RecallRequest request = notCachedRequests.get(i).getRequest();
SearchResult searchResult = searchResults.get(i);
RecallResponse response = this.buildResonse(searchResult);
notCachedResults.put(request.redisKeyBuilder(),response);
notCachedResults.put(request.redisKeyBuilder().getKey(),response);
}
return notCachedResults;
}
... ...