|
@@ -2,6 +2,7 @@ package com.yoho.search.recall.config; |
|
@@ -2,6 +2,7 @@ package com.yoho.search.recall.config; |
2
|
|
2
|
|
3
|
import com.yoho.search.core.personalized.models.SortBrand;
|
3
|
import com.yoho.search.core.personalized.models.SortBrand;
|
4
|
import com.yoho.search.dal.model.CsRecallConfigProduct;
|
4
|
import com.yoho.search.dal.model.CsRecallConfigProduct;
|
|
|
5
|
+import com.yoho.search.recall.beans.strategy.SortBrandType;
|
5
|
import com.yoho.search.service.base.index.CsRecallConfigProductIndexBaseService;
|
6
|
import com.yoho.search.service.base.index.CsRecallConfigProductIndexBaseService;
|
6
|
import org.slf4j.Logger;
|
7
|
import org.slf4j.Logger;
|
7
|
import org.slf4j.LoggerFactory;
|
8
|
import org.slf4j.LoggerFactory;
|
|
@@ -24,7 +25,7 @@ class RecallConfigServiceProduct { |
|
@@ -24,7 +25,7 @@ class RecallConfigServiceProduct { |
24
|
@Autowired
|
25
|
@Autowired
|
25
|
private CsRecallConfigProductIndexBaseService csRecallConfigProductIndexBaseService;
|
26
|
private CsRecallConfigProductIndexBaseService csRecallConfigProductIndexBaseService;
|
26
|
|
27
|
|
27
|
- private Map<Integer, Map<Integer, RecallSknCount>> configCache = new HashMap<>();
|
28
|
+ private Map<String, Map<Integer, RecallSknCount>> typePageConfigCache = new HashMap<>();
|
28
|
|
29
|
|
29
|
private ScheduledExecutorService schedule = Executors.newSingleThreadScheduledExecutor();
|
30
|
private ScheduledExecutorService schedule = Executors.newSingleThreadScheduledExecutor();
|
30
|
|
31
|
|
|
@@ -35,24 +36,24 @@ class RecallConfigServiceProduct { |
|
@@ -35,24 +36,24 @@ class RecallConfigServiceProduct { |
35
|
|
36
|
|
36
|
private void loadRecallSknCountConfig() {
|
37
|
private void loadRecallSknCountConfig() {
|
37
|
try {
|
38
|
try {
|
38
|
- Map<Integer, Map<Integer, RecallSknCount>> tempConfig = new HashMap<>();
|
39
|
+ Map<String, Map<Integer, RecallSknCount>> tempTypePageConfigCache = new HashMap<>();
|
39
|
List<CsRecallConfigProduct> configList = csRecallConfigProductIndexBaseService.queryAll();
|
40
|
List<CsRecallConfigProduct> configList = csRecallConfigProductIndexBaseService.queryAll();
|
40
|
for (CsRecallConfigProduct productConfig : configList) {
|
41
|
for (CsRecallConfigProduct productConfig : configList) {
|
41
|
- //1、按配置类型获取配置
|
|
|
42
|
- int configType = productConfig.getConfigType();
|
|
|
43
|
- Map<Integer, RecallSknCount> typeConfig = tempConfig.get(configType);
|
|
|
44
|
- if (typeConfig == null) {
|
|
|
45
|
- typeConfig = new HashMap<>();
|
|
|
46
|
- tempConfig.put(configType, typeConfig);
|
|
|
47
|
- }
|
|
|
48
|
- //2、页面类型的配置,不判断状态,其他类型的需要判断状态
|
|
|
49
|
- int configTypeId = productConfig.getConfigTypeId();
|
|
|
50
|
- int configStatus = productConfig.getConfigStatus();
|
|
|
51
|
- if (configType == RecallConfigConstants.SKN_COUNT_CONFIG_PAGE || configStatus == 1) {
|
|
|
52
|
- typeConfig.put(configTypeId, this.genProductCountConfig(productConfig));
|
|
|
53
|
- }
|
42
|
+// //1、按配置类型获取配置
|
|
|
43
|
+// int configType = productConfig.getConfigType();
|
|
|
44
|
+// Map<Integer, RecallSknCount> typeConfig = tempConfig.get(configType);
|
|
|
45
|
+// if (typeConfig == null) {
|
|
|
46
|
+// typeConfig = new HashMap<>();
|
|
|
47
|
+// tempConfig.put(configType, typeConfig);
|
|
|
48
|
+// }
|
|
|
49
|
+// //2、页面类型的配置,不判断状态,其他类型的需要判断状态
|
|
|
50
|
+// int configTypeId = productConfig.getConfigTypeId();
|
|
|
51
|
+// int configStatus = productConfig.getConfigStatus();
|
|
|
52
|
+// if (configType == RecallConfigConstants.SKN_COUNT_CONFIG_PAGE || configStatus == 1) {
|
|
|
53
|
+// typeConfig.put(configTypeId, this.genProductCountConfig(productConfig));
|
|
|
54
|
+// }
|
54
|
}
|
55
|
}
|
55
|
- configCache = tempConfig;
|
56
|
+ typePageConfigCache = tempTypePageConfigCache;
|
56
|
} catch (Exception e) {
|
57
|
} catch (Exception e) {
|
57
|
logger.error(e.getMessage(), e);
|
58
|
logger.error(e.getMessage(), e);
|
58
|
}
|
59
|
}
|
|
@@ -89,33 +90,44 @@ class RecallConfigServiceProduct { |
|
@@ -89,33 +90,44 @@ class RecallConfigServiceProduct { |
89
|
return genProductCountConfig(newShelve, promotion, reducePrice, ctrValue, heatValue, random);
|
90
|
return genProductCountConfig(newShelve, promotion, reducePrice, ctrValue, heatValue, random);
|
90
|
}
|
91
|
}
|
91
|
|
92
|
|
92
|
- private RecallSknCount queryConfigBySort(int middleSortId) {
|
|
|
93
|
- Map<Integer, RecallSknCount> sortConfig = configCache.get(RecallConfigConstants.SKN_COUNT_CONFIG_SORT);
|
|
|
94
|
- if (sortConfig == null) {
|
|
|
95
|
- return null;
|
|
|
96
|
- }
|
|
|
97
|
- return sortConfig.get(middleSortId);
|
93
|
+ private String buildSortCacheKey(int middleSortId) {
|
|
|
94
|
+ return RecallConfigConstants.RECALL_SKN_COUNT_SORT + "_" + middleSortId;
|
98
|
}
|
95
|
}
|
99
|
|
96
|
|
100
|
- private RecallSknCount queryConfigByBrand(int brandId) {
|
|
|
101
|
- Map<Integer, RecallSknCount> brandConfig = configCache.get(RecallConfigConstants.SKN_COUNT_CONFIG_BRAND);
|
|
|
102
|
- if (brandConfig == null) {
|
|
|
103
|
- return null;
|
|
|
104
|
- }
|
|
|
105
|
- return brandConfig.get(brandId);
|
97
|
+ private String buildBrandCacheKey(int brandId) {
|
|
|
98
|
+ return RecallConfigConstants.RECALL_SKN_COUNT_BRAND + "_" + brandId;
|
106
|
}
|
99
|
}
|
107
|
|
100
|
|
108
|
- private RecallSknCount queryConfigByPage(int pageId) {
|
|
|
109
|
- Map<Integer, RecallSknCount> pageConfig = configCache.get(RecallConfigConstants.SKN_COUNT_CONFIG_PAGE);
|
101
|
+ private String buildSortBrandCacheKey(SortBrandType sortBrandType, SortBrand sortBrand) {
|
|
|
102
|
+ return sortBrandType.name() + "_" + sortBrand.key();
|
|
|
103
|
+ }
|
|
|
104
|
+
|
|
|
105
|
+
|
|
|
106
|
+ private RecallSknCount getRecallSknCount(String key, int pageId) {
|
|
|
107
|
+ Map<Integer, RecallSknCount> pageConfig = typePageConfigCache.get(key);
|
110
|
if (pageConfig == null) {
|
108
|
if (pageConfig == null) {
|
111
|
return null;
|
109
|
return null;
|
112
|
}
|
110
|
}
|
113
|
- RecallSknCount config = pageConfig.get(pageId);
|
|
|
114
|
- if (config == null) {
|
|
|
115
|
- return pageConfig.get(RecallConfigConstants.DEFAULT_PAGE_ID);
|
|
|
116
|
- } else {
|
|
|
117
|
- return config;
|
111
|
+ RecallSknCount sknCount = pageConfig.get(pageId);
|
|
|
112
|
+ if (sknCount == null) {
|
|
|
113
|
+ sknCount = pageConfig.get(RecallConfigConstants.DEFAULT_PAGE_ID);
|
118
|
}
|
114
|
}
|
|
|
115
|
+ return sknCount;
|
|
|
116
|
+ }
|
|
|
117
|
+
|
|
|
118
|
+ private RecallSknCount queryConfigBySort(int pageId, int middleSortId) {
|
|
|
119
|
+ String sortKey = this.buildSortCacheKey(middleSortId);
|
|
|
120
|
+ return this.getRecallSknCount(sortKey, pageId);
|
|
|
121
|
+ }
|
|
|
122
|
+
|
|
|
123
|
+ private RecallSknCount queryConfigByBrand(int pageId, int brandId) {
|
|
|
124
|
+ String brandKey = this.buildBrandCacheKey(brandId);
|
|
|
125
|
+ return this.getRecallSknCount(brandKey, pageId);
|
|
|
126
|
+ }
|
|
|
127
|
+
|
|
|
128
|
+ private RecallSknCount queryConfigByPage(int pageId, SortBrandType sortBrandType, SortBrand sortBrand) {
|
|
|
129
|
+ String sortBrandKey = this.buildSortBrandCacheKey(sortBrandType, sortBrand);
|
|
|
130
|
+ return this.getRecallSknCount(sortBrandKey, pageId);
|
119
|
}
|
131
|
}
|
120
|
|
132
|
|
121
|
/**
|
133
|
/**
|
|
@@ -125,9 +137,9 @@ class RecallConfigServiceProduct { |
|
@@ -125,9 +137,9 @@ class RecallConfigServiceProduct { |
125
|
* @param sortBrand
|
137
|
* @param sortBrand
|
126
|
* @return
|
138
|
* @return
|
127
|
*/
|
139
|
*/
|
128
|
- public RecallSknCount queryRecallSknCount(int pageId, SortBrand sortBrand) {
|
|
|
129
|
- RecallSknCount sortConfig = this.queryConfigBySort(sortBrand.getMisort());
|
|
|
130
|
- RecallSknCount brandConfig = this.queryConfigByBrand(sortBrand.getBrandId());
|
140
|
+ public RecallSknCount queryRecallSknCount(int pageId, SortBrandType sortBrandType, SortBrand sortBrand) {
|
|
|
141
|
+ RecallSknCount sortConfig = this.queryConfigBySort(pageId, sortBrand.getMisort());
|
|
|
142
|
+ RecallSknCount brandConfig = this.queryConfigByBrand(pageId, sortBrand.getBrandId());
|
131
|
if (sortConfig != null && sortConfig != null) {
|
143
|
if (sortConfig != null && sortConfig != null) {
|
132
|
return genProductCountConfigByCompare(sortConfig, brandConfig);
|
144
|
return genProductCountConfigByCompare(sortConfig, brandConfig);
|
133
|
}
|
145
|
}
|
|
@@ -137,7 +149,11 @@ class RecallConfigServiceProduct { |
|
@@ -137,7 +149,11 @@ class RecallConfigServiceProduct { |
137
|
if (brandConfig != null) {
|
149
|
if (brandConfig != null) {
|
138
|
return brandConfig;
|
150
|
return brandConfig;
|
139
|
}
|
151
|
}
|
140
|
- RecallSknCount pageConfig = this.queryConfigByPage(pageId);
|
152
|
+ RecallSknCount pageConfig = this.queryConfigByPage(pageId, sortBrandType, sortBrand);
|
|
|
153
|
+ if (pageConfig != null) {
|
|
|
154
|
+ return pageConfig;
|
|
|
155
|
+ }
|
|
|
156
|
+ pageConfig = this.queryConfigByPage(pageId, sortBrandType, new SortBrand());//使用默认的值替代
|
141
|
if (pageConfig != null) {
|
157
|
if (pageConfig != null) {
|
142
|
return pageConfig;
|
158
|
return pageConfig;
|
143
|
}
|
159
|
}
|