...
|
...
|
@@ -2,25 +2,23 @@ package com.yoho.search.service.scene.pages.promotion; |
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.yoho.search.base.utils.ISearchConstants;
|
|
|
import com.yoho.search.cache.log.SearchCacheMatchLogger;
|
|
|
import com.yoho.search.cache.model.SearchCache;
|
|
|
import com.yoho.search.cache.CacheTimeConstants;
|
|
|
import com.yoho.search.cache.beans.AbstractCacheComponent;
|
|
|
import com.yoho.search.common.SearchCommonService;
|
|
|
import com.yoho.search.common.SearchDynamicConfigService;
|
|
|
import com.yoho.search.core.es.model.SearchParam;
|
|
|
import com.yoho.search.core.es.model.SearchResult;
|
|
|
import com.yoho.search.models.PromotionConditions;
|
|
|
import com.yoho.search.models.SearchApiResult;
|
|
|
import com.yoho.search.service.recall.SceneRecallProductListService;
|
|
|
import com.yoho.search.service.recall.beans.builder.UserRecallRequestBuilder;
|
|
|
import com.yoho.search.service.recall.beans.strategy.NotRecallTypeEnum;
|
|
|
import com.yoho.search.service.recall.models.req.UserRecallRequest;
|
|
|
import com.yoho.search.cache.beans.SearchCacheService;
|
|
|
import com.yoho.search.common.SearchCommonService;
|
|
|
import com.yoho.search.common.SearchDynamicConfigService;
|
|
|
import com.yoho.search.service.index.ProductIndexBaseService;
|
|
|
import com.yoho.search.service.helper.ProductListHelper;
|
|
|
import com.yoho.search.service.helper.SearchCommonHelper;
|
|
|
import com.yoho.search.service.helper.SearchParamHelper;
|
|
|
import com.yoho.search.service.helper.SearchSortHelper;
|
|
|
import com.yoho.search.cache.beans.AbstractCacheAbleService;
|
|
|
import com.yoho.search.service.index.ProductIndexBaseService;
|
|
|
import com.yoho.search.service.recall.SceneRecallProductListService;
|
|
|
import com.yoho.search.service.recall.beans.builder.UserRecallRequestBuilder;
|
|
|
import com.yoho.search.service.recall.beans.strategy.NotRecallTypeEnum;
|
|
|
import com.yoho.search.service.recall.models.req.UserRecallRequest;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.elasticsearch.index.query.BoolQueryBuilder;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
...
|
...
|
@@ -29,7 +27,7 @@ import org.springframework.stereotype.Component; |
|
|
import java.util.Map;
|
|
|
|
|
|
@Component
|
|
|
public class PromotionProductListService extends AbstractCacheAbleService {
|
|
|
public class PromotionProductListService extends AbstractCacheComponent<JSONObject> {
|
|
|
|
|
|
@Autowired
|
|
|
private PromotionSceneHelper promotionSceneHelper;
|
...
|
...
|
@@ -44,8 +42,6 @@ public class PromotionProductListService extends AbstractCacheAbleService { |
|
|
@Autowired
|
|
|
private SearchCommonHelper searchCommonHelper;
|
|
|
@Autowired
|
|
|
private SearchCacheService searchCacheService;
|
|
|
@Autowired
|
|
|
private UserRecallRequestBuilder userRecallRequestBuilder;
|
|
|
@Autowired
|
|
|
private SceneRecallProductListService sceneRecallProductListService;
|
...
|
...
|
@@ -54,11 +50,6 @@ public class PromotionProductListService extends AbstractCacheAbleService { |
|
|
@Autowired
|
|
|
private ProductIndexBaseService productIndexBaseService;
|
|
|
|
|
|
@Override
|
|
|
public SearchCache getSearchCache() {
|
|
|
return searchCacheFactory.getPromotionSearchCache();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 促销列表入口
|
|
|
*
|
...
|
...
|
@@ -100,7 +91,6 @@ public class PromotionProductListService extends AbstractCacheAbleService { |
|
|
return true;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 默认的促销列表的返回方式
|
|
|
*
|
...
|
...
|
@@ -127,26 +117,32 @@ public class PromotionProductListService extends AbstractCacheAbleService { |
|
|
searchParam.setIncludeFields(productIndexBaseService.getProductIndexIncludeFields());
|
|
|
|
|
|
// 5)从缓存中获取数据
|
|
|
final String productIndexName = ISearchConstants.INDEX_NAME_PRODUCT_INDEX;
|
|
|
JSONObject cacheObject = searchCacheService.getJSONObjectFromCache(this.searchCache, productIndexName, searchParam);
|
|
|
if (cacheObject != null) {
|
|
|
SearchCacheMatchLogger.doSearchCacheMatchLog("/promotion/list.json", paramMap);
|
|
|
return new SearchApiResult().setData(cacheObject);
|
|
|
}
|
|
|
JSONObject productListResult = super.queryWithCache(searchParam,paramMap);
|
|
|
return new SearchApiResult().setData(productListResult);
|
|
|
}
|
|
|
|
|
|
// 6)查询ES
|
|
|
@Override
|
|
|
protected JSONObject doRealQuery(SearchParam searchParam, Map<String, String> paramMap) throws Exception {
|
|
|
// 1、查询ES
|
|
|
final String productIndexName = ISearchConstants.INDEX_NAME_PRODUCT_INDEX;
|
|
|
SearchResult searchResult = searchCommonService.doSearch(productIndexName, searchParam);
|
|
|
if (searchResult == null) {
|
|
|
return new SearchApiResult().setCode(500).setMessage("execption");
|
|
|
throw new RuntimeException("searchResult is Empty");
|
|
|
}
|
|
|
// 7)构造返回结果
|
|
|
// 2、构造返回结果
|
|
|
boolean needResort = searchCommonHelper.isOrderEmpty(paramMap);
|
|
|
int pageSize = StringUtils.isBlank(paramMap.get("viewNum")) ? 10 : Integer.parseInt(paramMap.get("viewNum"));
|
|
|
JSONObject productListResult = productListHelper.buildProductListResult(searchResult, pageSize, needResort,needResort? NotRecallTypeEnum.W2V_PERSIONAL:NotRecallTypeEnum.NOT_PERSIONAL);
|
|
|
|
|
|
// 10)将结果存进缓存
|
|
|
searchCacheService.addJSONObjectToCache(this.searchCache, productIndexName, searchParam, productListResult);
|
|
|
return new SearchApiResult().setData(productListResult);
|
|
|
return productListResult;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected int cacheTimeInMinute() {
|
|
|
return CacheTimeConstants.CACHE_15_MINUTE;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected String cacheSceneKey() {
|
|
|
return "PROMOTION_PRODUCT_LIST";
|
|
|
}
|
|
|
} |
...
|
...
|
|