Authored by hugufei

Merge branch 'zj'

package com.yoho.search.service.scene;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import com.alibaba.fastjson.JSONArray;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -88,7 +90,7 @@ public class FuzzySceneService extends AbstractSceneService {
// 4、获取自定义标签聚合结果
CompletableFuture<SearchApiResult> customizeTagFuture = CompletableFuture.supplyAsync(() -> sceneAggregationsHelper.secneAggCustomizeTag(this.newParamMap(paramMap)), executor);
// 5、获取促销专题
CompletableFuture<List<Object>> recommendPromotionFuture = CompletableFuture.supplyAsync(() -> recommendService.recommendPromotion(this.newParamMap(paramMap)),
CompletableFuture<SearchApiResult> recommendPromotionFuture = CompletableFuture.supplyAsync(() -> sceneAggregationsHelper.secneAggRecommendPromotion(this.newParamMap(paramMap)),
executor);
// 6、加入建议词
... ... @@ -103,10 +105,15 @@ public class FuzzySceneService extends AbstractSceneService {
}
// 8、组合结果
SearchApiResult customizeTags = customizeTagFuture.get();
List<Object> recommendProducts = recommendPromotionFuture.get();
SearchApiResult recommendProducts = recommendPromotionFuture.get();
JSONObject dataMap = (JSONObject) productListResult.getData();
dataMap.put(CUSTOMIZE_TAG_LIST, customizeTags.getData());
dataMap.put(RECOMMEND_PROMOTION_LIST, recommendProducts);
if (recommendProducts.getData() == null) {
dataMap.put(RECOMMEND_PROMOTION_LIST, Collections.EMPTY_LIST);
} else {
dataMap.put(RECOMMEND_PROMOTION_LIST, subList(recommendProducts.getData(), StringUtils.isBlank(paramMap.get("page")) ? 1 : Integer.parseInt(paramMap.get("page")), 1));
}
return productListResult;
} catch (Exception e) {
logger.error(e.getMessage(), e);
... ... @@ -171,4 +178,5 @@ public class FuzzySceneService extends AbstractSceneService {
// 1.6加入推荐词
dataMap.put("suggestion", searchRecommendService.recommend(searchResult, paramMap));
}
}
... ...
package com.yoho.search.service.scene;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
... ... @@ -162,24 +163,4 @@ public class SortSceneService extends AbstractSceneService {
}
}
private List<Object> subList(Object source, int page, int count) {
try {
JSONArray sourceList = (JSONArray)source;
if (sourceList != null && !sourceList.isEmpty()) {
int start = (page - 1) * count;
int end = start + count;
if (start >= sourceList.size()) {
return Collections.emptyList();
}
if (end > sourceList.size()) {
end = sourceList.size();
}
return sourceList.subList(start, end);
}
} catch (Exception e) {
return Collections.emptyList();
}
return Collections.emptyList();
}
}
... ...
package com.yoho.search.service.scene.common;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yoho.search.common.utils.SearchKeyWordUtils;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.base.SearchRequestParams;
... ... @@ -7,8 +9,7 @@ import com.yoho.search.service.base.SearchRequestParams;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;
import java.util.HashMap;
import java.util.Map;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import java.util.function.Supplier;
... ... @@ -53,6 +54,32 @@ public abstract class AbstractSceneService {
int page = StringUtils.isBlank(paramMap.get("page")) ? 1 : Integer.parseInt(paramMap.get("page"));
return page;
}
protected List<Object> subList(Object source, int page, int count) {
try {
JSONArray sourceList = (JSONArray)source;
if (sourceList != null && !sourceList.isEmpty()) {
int totalCount = sourceList.size();
int start = (page - 1) * count;
int end = start + count;
if (start >= totalCount) {
return Collections.emptyList();
}
if (end > totalCount) {
end = totalCount;
}
List<Object> subList = sourceList.subList(start, end);
subList.forEach(e -> {
JSONObject jsonObject = (JSONObject)e;
jsonObject.put("totalCount", totalCount);
});
return subList;
}
} catch (Exception e) {
return Collections.emptyList();
}
return Collections.emptyList();
}
protected String getuid(Map<String, String> paramMap) {
return MapUtils.getString(paramMap, "uid", "0");
... ...