Authored by hugufei

使用AbstractCacheComponent重构PromotionProductListService缓存

... ... @@ -49,38 +49,6 @@ public class SearchCacheFactory {
return this.getOrCreateSearchCache("AGGREGATION", cacheType, cacheInMinute);
}
/**
* 获取默认的搜索缓存
*
* @return
*/
public SearchCache getProductCountSearchCache() {
CacheType cacheType = CacheType.SEARCH_REDIS;
int cacheInMinute = 15;
return this.getOrCreateSearchCache("PRODUCT_COUNT", cacheType, cacheInMinute);
}
/**
* 获取聚合相关的缓存
*
* @return
*/
public SearchCache getSelectionsForAppCache() {
CacheType cacheType = CacheType.SEARCH_REDIS;
int cacheInMinute = 15;
return this.getOrCreateSearchCache("SELECTIONS_APP", cacheType, cacheInMinute);
}
/**
* 获取聚合相关的缓存
*
* @return
*/
public SearchCache getSelectionsForPcCache() {
CacheType cacheType = CacheType.SEARCH_REDIS;
int cacheInMinute = 15;
return this.getOrCreateSearchCache("SELECTIONS_PC", cacheType, cacheInMinute);
}
/**
* 个性化聚合推荐相关的缓存
... ... @@ -94,17 +62,6 @@ public class SearchCacheFactory {
}
/**
* 品牌相关的缓存
*
* @return
*/
public SearchCache getBrandRelatedCache() {
CacheType cacheType = CacheType.SEARCH_REDIS;
int cacheInMinute = 15;
return this.getOrCreateSearchCache("BRAND_RELATED", cacheType, cacheInMinute);
}
/**
* aop的缓存
*
* @return
... ... @@ -135,27 +92,4 @@ public class SearchCacheFactory {
int cacheInMinute = 15;
return this.getOrCreateSearchCache("PROMOTION", cacheType, cacheInMinute);
}
/**
* PC列表的缓存
*
* @return
*/
public SearchCache getWebProductListSearchCache() {
CacheType cacheType = CacheType.SEARCH_REDIS;
int cacheInMinute = 15;
return this.getOrCreateSearchCache("WEB_PRODUCT_LIST", cacheType, cacheInMinute);
}
/**
* 有好货的缓存
*
* @return
*/
public SearchCache goodProductListSearchCache() {
CacheType cacheType = CacheType.SEARCH_REDIS;
int cacheInMinute = 15;
return this.getOrCreateSearchCache("GOOD_PRODUCT", cacheType, cacheInMinute);
}
}
... ...
... ... @@ -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";
}
}
... ...