...
|
...
|
@@ -11,9 +11,13 @@ import org.slf4j.LoggerFactory; |
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.concurrent.Executors;
|
|
|
import java.util.concurrent.ScheduledExecutorService;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
@Component
|
|
|
public class RecallSknCountConfigService {
|
...
|
...
|
@@ -23,15 +27,16 @@ public class RecallSknCountConfigService { |
|
|
@Autowired
|
|
|
private SearchCommonService searchCommonService;
|
|
|
|
|
|
private static int DEFAULT_PAGE_ID = 0;
|
|
|
private Map<Integer, Map<Integer, RecallSknCountConfig>> configCache = new HashMap<>();
|
|
|
|
|
|
private static final int PAGE_CONFIG_TYPE = 1;
|
|
|
private static final int MIDDLE_SORT_CONFIG_TYPE = 2;
|
|
|
private static final int BRAND_CONFIG_TYPE = 3;
|
|
|
private ScheduledExecutorService schedule = Executors.newSingleThreadScheduledExecutor();
|
|
|
|
|
|
private Map<Integer, Map<Integer, RecallSknCountConfig>> wholeConfig = new HashMap<>();
|
|
|
@PostConstruct
|
|
|
void init() {
|
|
|
schedule.scheduleAtFixedRate(() -> loadRecallSknCountConfig(), 0, 1, TimeUnit.MINUTES);
|
|
|
}
|
|
|
|
|
|
private void initConfigFromEs() {
|
|
|
private void loadRecallSknCountConfig() {
|
|
|
try {
|
|
|
SearchParam searchParam = new SearchParam();
|
|
|
searchParam.setOffset(0);
|
...
|
...
|
@@ -50,11 +55,11 @@ public class RecallSknCountConfigService { |
|
|
//2、页面类型的配置,不判断状态,其他类型的需要判断状态
|
|
|
int configTypeId = MapUtils.getIntValue(result, "configTypeId", 0);
|
|
|
int configStatus = MapUtils.getIntValue(result, "configStatus", 1);
|
|
|
if (configType == PAGE_CONFIG_TYPE || configStatus == 1) {
|
|
|
if (configType == ConfigConstants.SKN_COUNT_CONFIG_PAGE || configStatus == 1) {
|
|
|
typeConfig.put(configTypeId, this.genRecallSknCountConfigFromEs(result));
|
|
|
}
|
|
|
}
|
|
|
wholeConfig = tempWholeConfig;
|
|
|
configCache = tempWholeConfig;
|
|
|
} catch (Exception e) {
|
|
|
logger.error(e.getMessage(), e);
|
|
|
}
|
...
|
...
|
@@ -81,10 +86,9 @@ public class RecallSknCountConfigService { |
|
|
return recallSknCountConfig;
|
|
|
}
|
|
|
|
|
|
|
|
|
public RecallSknCountConfig queryRecallSknCount(int pageId, SortBrand sortBrand) {
|
|
|
RecallSknCountConfig sortConfig = this.querySortConfig(sortBrand.getMisort());
|
|
|
RecallSknCountConfig brandConfig = this.queryBrandConfig(sortBrand.getBrandId());
|
|
|
RecallSknCountConfig sortConfig = this.queryConfigBySort(sortBrand.getMisort());
|
|
|
RecallSknCountConfig brandConfig = this.queryConfigByBrand(sortBrand.getBrandId());
|
|
|
if (sortConfig != null && sortConfig != null) {
|
|
|
return genProductCountConfigByCompare(sortConfig, brandConfig);
|
|
|
}
|
...
|
...
|
@@ -94,7 +98,7 @@ public class RecallSknCountConfigService { |
|
|
if (brandConfig != null) {
|
|
|
return brandConfig;
|
|
|
}
|
|
|
RecallSknCountConfig pageConfig = this.queryPageConfig(pageId);
|
|
|
RecallSknCountConfig pageConfig = this.queryConfigByPage(pageId);
|
|
|
if (pageConfig != null) {
|
|
|
return pageConfig;
|
|
|
}
|
...
|
...
|
@@ -111,30 +115,30 @@ public class RecallSknCountConfigService { |
|
|
return genProductCountConfig(newShelve, promotion, reducePrice, ctrValue, heatValue, random);
|
|
|
}
|
|
|
|
|
|
private RecallSknCountConfig querySortConfig(int middleSortId) {
|
|
|
Map<Integer, RecallSknCountConfig> sortConfig = wholeConfig.get(MIDDLE_SORT_CONFIG_TYPE);
|
|
|
private RecallSknCountConfig queryConfigBySort(int middleSortId) {
|
|
|
Map<Integer, RecallSknCountConfig> sortConfig = configCache.get(ConfigConstants.SKN_COUNT_CONFIG_SORT);
|
|
|
if (sortConfig == null) {
|
|
|
return null;
|
|
|
}
|
|
|
return sortConfig.get(middleSortId);
|
|
|
}
|
|
|
|
|
|
private RecallSknCountConfig queryBrandConfig(int brandId) {
|
|
|
Map<Integer, RecallSknCountConfig> brandConfig = wholeConfig.get(BRAND_CONFIG_TYPE);
|
|
|
private RecallSknCountConfig queryConfigByBrand(int brandId) {
|
|
|
Map<Integer, RecallSknCountConfig> brandConfig = configCache.get(ConfigConstants.SKN_COUNT_CONFIG_BRAND);
|
|
|
if (brandConfig == null) {
|
|
|
return null;
|
|
|
}
|
|
|
return brandConfig.get(brandId);
|
|
|
}
|
|
|
|
|
|
private RecallSknCountConfig queryPageConfig(int pageId) {
|
|
|
Map<Integer, RecallSknCountConfig> pageConfig = wholeConfig.get(PAGE_CONFIG_TYPE);
|
|
|
private RecallSknCountConfig queryConfigByPage(int pageId) {
|
|
|
Map<Integer, RecallSknCountConfig> pageConfig = configCache.get(ConfigConstants.SKN_COUNT_CONFIG_PAGE);
|
|
|
if (pageConfig == null) {
|
|
|
return null;
|
|
|
}
|
|
|
RecallSknCountConfig config = pageConfig.get(pageId);
|
|
|
if (config == null) {
|
|
|
return pageConfig.get(DEFAULT_PAGE_ID);
|
|
|
return pageConfig.get(ConfigConstants.DEFAULT_PAGE_ID);
|
|
|
} else {
|
|
|
return config;
|
|
|
}
|
...
|
...
|
|