...
|
...
|
@@ -2,6 +2,7 @@ package com.yoho.search.recall.config; |
|
|
|
|
|
import com.yoho.search.core.personalized.models.SortBrand;
|
|
|
import com.yoho.search.dal.model.CsRecallConfigProduct;
|
|
|
import com.yoho.search.recall.beans.strategy.SortBrandType;
|
|
|
import com.yoho.search.service.base.index.CsRecallConfigProductIndexBaseService;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
...
|
...
|
@@ -24,7 +25,7 @@ class RecallConfigServiceProduct { |
|
|
@Autowired
|
|
|
private CsRecallConfigProductIndexBaseService csRecallConfigProductIndexBaseService;
|
|
|
|
|
|
private Map<Integer, Map<Integer, RecallSknCount>> configCache = new HashMap<>();
|
|
|
private Map<String, Map<Integer, RecallSknCount>> typePageConfigCache = new HashMap<>();
|
|
|
|
|
|
private ScheduledExecutorService schedule = Executors.newSingleThreadScheduledExecutor();
|
|
|
|
...
|
...
|
@@ -35,24 +36,24 @@ class RecallConfigServiceProduct { |
|
|
|
|
|
private void loadRecallSknCountConfig() {
|
|
|
try {
|
|
|
Map<Integer, Map<Integer, RecallSknCount>> tempConfig = new HashMap<>();
|
|
|
Map<String, Map<Integer, RecallSknCount>> tempTypePageConfigCache = new HashMap<>();
|
|
|
List<CsRecallConfigProduct> configList = csRecallConfigProductIndexBaseService.queryAll();
|
|
|
for (CsRecallConfigProduct productConfig : configList) {
|
|
|
//1、按配置类型获取配置
|
|
|
int configType = productConfig.getConfigType();
|
|
|
Map<Integer, RecallSknCount> typeConfig = tempConfig.get(configType);
|
|
|
if (typeConfig == null) {
|
|
|
typeConfig = new HashMap<>();
|
|
|
tempConfig.put(configType, typeConfig);
|
|
|
}
|
|
|
//2、页面类型的配置,不判断状态,其他类型的需要判断状态
|
|
|
int configTypeId = productConfig.getConfigTypeId();
|
|
|
int configStatus = productConfig.getConfigStatus();
|
|
|
if (configType == RecallConfigConstants.SKN_COUNT_CONFIG_PAGE || configStatus == 1) {
|
|
|
typeConfig.put(configTypeId, this.genProductCountConfig(productConfig));
|
|
|
}
|
|
|
// //1、按配置类型获取配置
|
|
|
// int configType = productConfig.getConfigType();
|
|
|
// Map<Integer, RecallSknCount> typeConfig = tempConfig.get(configType);
|
|
|
// if (typeConfig == null) {
|
|
|
// typeConfig = new HashMap<>();
|
|
|
// tempConfig.put(configType, typeConfig);
|
|
|
// }
|
|
|
// //2、页面类型的配置,不判断状态,其他类型的需要判断状态
|
|
|
// int configTypeId = productConfig.getConfigTypeId();
|
|
|
// int configStatus = productConfig.getConfigStatus();
|
|
|
// if (configType == RecallConfigConstants.SKN_COUNT_CONFIG_PAGE || configStatus == 1) {
|
|
|
// typeConfig.put(configTypeId, this.genProductCountConfig(productConfig));
|
|
|
// }
|
|
|
}
|
|
|
configCache = tempConfig;
|
|
|
typePageConfigCache = tempTypePageConfigCache;
|
|
|
} catch (Exception e) {
|
|
|
logger.error(e.getMessage(), e);
|
|
|
}
|
...
|
...
|
@@ -89,33 +90,44 @@ class RecallConfigServiceProduct { |
|
|
return genProductCountConfig(newShelve, promotion, reducePrice, ctrValue, heatValue, random);
|
|
|
}
|
|
|
|
|
|
private RecallSknCount queryConfigBySort(int middleSortId) {
|
|
|
Map<Integer, RecallSknCount> sortConfig = configCache.get(RecallConfigConstants.SKN_COUNT_CONFIG_SORT);
|
|
|
if (sortConfig == null) {
|
|
|
return null;
|
|
|
}
|
|
|
return sortConfig.get(middleSortId);
|
|
|
private String buildSortCacheKey(int middleSortId) {
|
|
|
return RecallConfigConstants.RECALL_SKN_COUNT_SORT + "_" + middleSortId;
|
|
|
}
|
|
|
|
|
|
private RecallSknCount queryConfigByBrand(int brandId) {
|
|
|
Map<Integer, RecallSknCount> brandConfig = configCache.get(RecallConfigConstants.SKN_COUNT_CONFIG_BRAND);
|
|
|
if (brandConfig == null) {
|
|
|
return null;
|
|
|
}
|
|
|
return brandConfig.get(brandId);
|
|
|
private String buildBrandCacheKey(int brandId) {
|
|
|
return RecallConfigConstants.RECALL_SKN_COUNT_BRAND + "_" + brandId;
|
|
|
}
|
|
|
|
|
|
private RecallSknCount queryConfigByPage(int pageId) {
|
|
|
Map<Integer, RecallSknCount> pageConfig = configCache.get(RecallConfigConstants.SKN_COUNT_CONFIG_PAGE);
|
|
|
private String buildSortBrandCacheKey(SortBrandType sortBrandType, SortBrand sortBrand) {
|
|
|
return sortBrandType.name() + "_" + sortBrand.key();
|
|
|
}
|
|
|
|
|
|
|
|
|
private RecallSknCount getRecallSknCount(String key, int pageId) {
|
|
|
Map<Integer, RecallSknCount> pageConfig = typePageConfigCache.get(key);
|
|
|
if (pageConfig == null) {
|
|
|
return null;
|
|
|
}
|
|
|
RecallSknCount config = pageConfig.get(pageId);
|
|
|
if (config == null) {
|
|
|
return pageConfig.get(RecallConfigConstants.DEFAULT_PAGE_ID);
|
|
|
} else {
|
|
|
return config;
|
|
|
RecallSknCount sknCount = pageConfig.get(pageId);
|
|
|
if (sknCount == null) {
|
|
|
sknCount = pageConfig.get(RecallConfigConstants.DEFAULT_PAGE_ID);
|
|
|
}
|
|
|
return sknCount;
|
|
|
}
|
|
|
|
|
|
private RecallSknCount queryConfigBySort(int pageId, int middleSortId) {
|
|
|
String sortKey = this.buildSortCacheKey(middleSortId);
|
|
|
return this.getRecallSknCount(sortKey, pageId);
|
|
|
}
|
|
|
|
|
|
private RecallSknCount queryConfigByBrand(int pageId, int brandId) {
|
|
|
String brandKey = this.buildBrandCacheKey(brandId);
|
|
|
return this.getRecallSknCount(brandKey, pageId);
|
|
|
}
|
|
|
|
|
|
private RecallSknCount queryConfigByPage(int pageId, SortBrandType sortBrandType, SortBrand sortBrand) {
|
|
|
String sortBrandKey = this.buildSortBrandCacheKey(sortBrandType, sortBrand);
|
|
|
return this.getRecallSknCount(sortBrandKey, pageId);
|
|
|
}
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -125,9 +137,9 @@ class RecallConfigServiceProduct { |
|
|
* @param sortBrand
|
|
|
* @return
|
|
|
*/
|
|
|
public RecallSknCount queryRecallSknCount(int pageId, SortBrand sortBrand) {
|
|
|
RecallSknCount sortConfig = this.queryConfigBySort(sortBrand.getMisort());
|
|
|
RecallSknCount brandConfig = this.queryConfigByBrand(sortBrand.getBrandId());
|
|
|
public RecallSknCount queryRecallSknCount(int pageId, SortBrandType sortBrandType, SortBrand sortBrand) {
|
|
|
RecallSknCount sortConfig = this.queryConfigBySort(pageId, sortBrand.getMisort());
|
|
|
RecallSknCount brandConfig = this.queryConfigByBrand(pageId, sortBrand.getBrandId());
|
|
|
if (sortConfig != null && sortConfig != null) {
|
|
|
return genProductCountConfigByCompare(sortConfig, brandConfig);
|
|
|
}
|
...
|
...
|
@@ -137,7 +149,11 @@ class RecallConfigServiceProduct { |
|
|
if (brandConfig != null) {
|
|
|
return brandConfig;
|
|
|
}
|
|
|
RecallSknCount pageConfig = this.queryConfigByPage(pageId);
|
|
|
RecallSknCount pageConfig = this.queryConfigByPage(pageId, sortBrandType, sortBrand);
|
|
|
if (pageConfig != null) {
|
|
|
return pageConfig;
|
|
|
}
|
|
|
pageConfig = this.queryConfigByPage(pageId, sortBrandType, new SortBrand());//使用默认的值替代
|
|
|
if (pageConfig != null) {
|
|
|
return pageConfig;
|
|
|
}
|
...
|
...
|
|