|
|
package com.yoho.search.recall.config;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.yoho.search.core.personalized.models.SortBrand;
|
|
|
import com.yoho.search.dal.model.CsRecallConfigProduct;
|
|
|
import com.yoho.search.service.base.index.CsRecallConfigProductIndexBaseService;
|
...
|
...
|
@@ -25,59 +24,60 @@ class RecallConfigProductService { |
|
|
@Autowired
|
|
|
private CsRecallConfigProductIndexBaseService csRecallConfigProductIndexBaseService;
|
|
|
|
|
|
private Map<String, Map<Integer, ConfigSknCount>> typePageConfigCache = new HashMap<>();
|
|
|
private Map<String, Map<Integer, ConfigSknCount>> recallSknCountConfigCache = new HashMap<>();
|
|
|
|
|
|
private ScheduledExecutorService schedule = Executors.newSingleThreadScheduledExecutor();
|
|
|
|
|
|
@PostConstruct
|
|
|
void init() {
|
|
|
schedule.scheduleAtFixedRate(() -> loadRecallSknCountConfig(), 0, 1, TimeUnit.MINUTES);
|
|
|
schedule.scheduleAtFixedRate(() -> loadRecallSknCountConfigCache(), 0, 1, TimeUnit.MINUTES);
|
|
|
}
|
|
|
|
|
|
private void loadRecallSknCountConfig() {
|
|
|
private void loadRecallSknCountConfigCache() {
|
|
|
try {
|
|
|
Map<String, Map<Integer, ConfigSknCount>> tempTypePageConfigCache = new HashMap<>();
|
|
|
List<CsRecallConfigProduct> configList = csRecallConfigProductIndexBaseService.queryAll();
|
|
|
Map<String, Map<Integer, ConfigSknCount>> tempCache = new HashMap<>();
|
|
|
for (CsRecallConfigProduct productConfig : configList) {
|
|
|
//1、类型判断
|
|
|
String configType = productConfig.getConfigType();
|
|
|
String configTypeId = productConfig.getConfigTypeId();
|
|
|
int pageId = productConfig.getConfigPage();
|
|
|
String configKey = this.buildConfiKey(configType,configTypeId);
|
|
|
String configKey = this.buildConfiKey(configType, configTypeId);
|
|
|
if (!tempCache.containsKey(configKey)) {
|
|
|
tempCache.put(configKey, new HashMap<>());
|
|
|
}
|
|
|
//2、状态判断
|
|
|
int configStatus = productConfig.getConfigStatus();
|
|
|
if(configStatus==1){
|
|
|
this.addElement(configKey,pageId,this.genProductCountConfig(productConfig),tempTypePageConfigCache);
|
|
|
if (configStatus != 1) {
|
|
|
continue;
|
|
|
}
|
|
|
//3、生成页面结果
|
|
|
int pageId = productConfig.getConfigPage();
|
|
|
ConfigSknCount configSknCount = this.genProductCountConfig(productConfig);
|
|
|
tempCache.get(configKey).put(pageId, configSknCount);
|
|
|
}
|
|
|
typePageConfigCache = tempTypePageConfigCache;
|
|
|
System.out.println(JSON.toJSONString(typePageConfigCache));
|
|
|
recallSknCountConfigCache = tempCache;
|
|
|
logger.info("loadRecallSknCountConfigCache success,recallSknCountConfigCache size is[{}]", recallSknCountConfigCache.size());
|
|
|
} catch (Exception e) {
|
|
|
logger.error(e.getMessage(), e);
|
|
|
logger.error("loadRecallSknCountConfigCache error,exception is:" + e.getMessage(), e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private String buildConfiKey(String configType, String configTypeId) {
|
|
|
if (configType.equalsIgnoreCase(RecallConfigConstants.SORT)) {
|
|
|
return this.buildCacheKey(RecallConfigConstants.SORT,configTypeId);
|
|
|
return this.buildCacheKey(RecallConfigConstants.SORT, configTypeId);
|
|
|
} else if (configType.equalsIgnoreCase(RecallConfigConstants.BRAND)) {
|
|
|
return this.buildCacheKey(RecallConfigConstants.BRAND,configTypeId);
|
|
|
}else if (configType.equalsIgnoreCase(RecallConfigConstants.SORT_BRAND)){
|
|
|
return this.buildCacheKey(RecallConfigConstants.SORT_BRAND,configTypeId);
|
|
|
}else {
|
|
|
return this.buildCacheKey(configType,configTypeId);
|
|
|
return this.buildCacheKey(RecallConfigConstants.BRAND, configTypeId);
|
|
|
} else if (configType.equalsIgnoreCase(RecallConfigConstants.SORT_BRAND)) {
|
|
|
return this.buildCacheKey(RecallConfigConstants.SORT_BRAND, configTypeId);
|
|
|
} else {
|
|
|
return this.buildCacheKey(configType, configTypeId);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private String buildCacheKey(String type,String cacheKey){
|
|
|
private String buildCacheKey(String type, String cacheKey) {
|
|
|
return type + "_" + cacheKey;
|
|
|
}
|
|
|
|
|
|
private void addElement(String configKey, int pageId, ConfigSknCount configSknCount, Map<String, Map<Integer, ConfigSknCount>> map) {
|
|
|
if (!map.containsKey(configKey)) {
|
|
|
map.put(configKey, new HashMap<>());
|
|
|
}
|
|
|
map.get(configKey).put(pageId, configSknCount);
|
|
|
}
|
|
|
|
|
|
private ConfigSknCount genProductCountConfig(CsRecallConfigProduct configProduct) {
|
|
|
int newShelve = configProduct.getNewShelve();
|
|
|
int promotion = configProduct.getPromotion();
|
...
|
...
|
@@ -118,8 +118,8 @@ class RecallConfigProductService { |
|
|
*/
|
|
|
public ConfigSknCount queryRecallSknCount(int pageId, String sortBrandTypeKey, SortBrand sortBrand) {
|
|
|
//1、先取【配置的品牌*品类】的配置
|
|
|
ConfigSknCount configSknCount = this.queryConfigBySortBrandWithType(pageId,RecallConfigConstants.SORT_BRAND, sortBrand);
|
|
|
if(configSknCount !=null){
|
|
|
ConfigSknCount configSknCount = this.queryConfigBySortBrandWithType(pageId, RecallConfigConstants.SORT_BRAND, sortBrand);
|
|
|
if (configSknCount != null) {
|
|
|
return configSknCount;
|
|
|
}
|
|
|
//2、再取【配置的品牌或品类】配置
|
...
|
...
|
@@ -148,6 +148,7 @@ class RecallConfigProductService { |
|
|
|
|
|
/**
|
|
|
* 查询【品类*品牌】在页面上的召回配置,没有则取pageId=0的数据
|
|
|
*
|
|
|
* @param pageId
|
|
|
* @param sortBrandType
|
|
|
* @param sortBrand
|
...
|
...
|
@@ -160,29 +161,31 @@ class RecallConfigProductService { |
|
|
|
|
|
/**
|
|
|
* 查询中分类在页面上的召回配置,没有则取pageId=0的数据
|
|
|
*
|
|
|
* @param pageId
|
|
|
* @param middleSortId
|
|
|
* @return
|
|
|
*/
|
|
|
private ConfigSknCount queryConfigBySort(int pageId, int middleSortId) {
|
|
|
String sortKey = this.buildCacheKey(RecallConfigConstants.SORT,String.valueOf(middleSortId));
|
|
|
String sortKey = this.buildCacheKey(RecallConfigConstants.SORT, String.valueOf(middleSortId));
|
|
|
return this.getRecallSknCount(sortKey, pageId);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查询品牌在页面上的召回配置,没有则取pageId=0的数据
|
|
|
*
|
|
|
* @param pageId
|
|
|
* @param brandId
|
|
|
* @return
|
|
|
*/
|
|
|
private ConfigSknCount queryConfigByBrand(int pageId, int brandId) {
|
|
|
String brandKey = this.buildCacheKey(RecallConfigConstants.BRAND,String.valueOf(brandId));
|
|
|
String brandKey = this.buildCacheKey(RecallConfigConstants.BRAND, String.valueOf(brandId));
|
|
|
return this.getRecallSknCount(brandKey, pageId);
|
|
|
}
|
|
|
|
|
|
|
|
|
private ConfigSknCount getRecallSknCount(String key, int pageId) {
|
|
|
Map<Integer, ConfigSknCount> pageConfig = typePageConfigCache.get(key);
|
|
|
Map<Integer, ConfigSknCount> pageConfig = recallSknCountConfigCache.get(key);
|
|
|
if (pageConfig == null) {
|
|
|
return null;
|
|
|
}
|
...
|
...
|
|