Merge branch 'recall_config' into 0510
Showing
9 changed files
with
141 additions
and
76 deletions
@@ -5,7 +5,7 @@ import com.yoho.search.recall.beans.strategy.IStrategy; | @@ -5,7 +5,7 @@ import com.yoho.search.recall.beans.strategy.IStrategy; | ||
5 | import com.yoho.search.recall.beans.strategy.SortBrandType; | 5 | import com.yoho.search.recall.beans.strategy.SortBrandType; |
6 | import com.yoho.search.recall.beans.strategy.impls.*; | 6 | import com.yoho.search.recall.beans.strategy.impls.*; |
7 | import com.yoho.search.recall.config.RecallConfigService; | 7 | import com.yoho.search.recall.config.RecallConfigService; |
8 | -import com.yoho.search.recall.config.RecallSknCount; | 8 | +import com.yoho.search.recall.config.ConfigSknCount; |
9 | import com.yoho.search.recall.models.common.ParamQueryFilter; | 9 | import com.yoho.search.recall.models.common.ParamQueryFilter; |
10 | import com.yoho.search.recall.models.req.RecallRequest; | 10 | import com.yoho.search.recall.models.req.RecallRequest; |
11 | import com.yoho.search.recall.models.req.UserRecallRequest; | 11 | import com.yoho.search.recall.models.req.UserRecallRequest; |
@@ -40,33 +40,33 @@ public class SortBrandRecallRequestBuilder { | @@ -40,33 +40,33 @@ public class SortBrandRecallRequestBuilder { | ||
40 | 40 | ||
41 | // 3)、参数构造 | 41 | // 3)、参数构造 |
42 | for (SortBrand sortBrand : sortBrands) { | 42 | for (SortBrand sortBrand : sortBrands) { |
43 | - RecallSknCount recallSknCount = recallConfigService.queryRecallSknCount(pageId, sortBrandType,sortBrand); | ||
44 | - if (recallSknCount == null) { | 43 | + ConfigSknCount configSknCount = recallConfigService.queryRecallSknCount(pageId, sortBrandType,sortBrand); |
44 | + if (configSknCount == null) { | ||
45 | continue; | 45 | continue; |
46 | } | 46 | } |
47 | // 1) 新品 | 47 | // 1) 新品 |
48 | - if (recallSknCount.getNewShelve() > 0) { | ||
49 | - requests.add(this.buildSortBrandNewShelveRequest(paramQueryFilter, sortBrand, recallSknCount.getNewShelve(), sortBrandType)); | 48 | + if (configSknCount.getNewShelve() > 0) { |
49 | + requests.add(this.buildSortBrandNewShelveRequest(paramQueryFilter, sortBrand, configSknCount.getNewShelve(), sortBrandType)); | ||
50 | } | 50 | } |
51 | // 2) 新开促销 | 51 | // 2) 新开促销 |
52 | - if (recallSknCount.getPromotion() > 0) { | ||
53 | - requests.add(this.buildSortBrandPromotionRequest(paramQueryFilter, sortBrand, recallSknCount.getPromotion(), sortBrandType)); | 52 | + if (configSknCount.getPromotion() > 0) { |
53 | + requests.add(this.buildSortBrandPromotionRequest(paramQueryFilter, sortBrand, configSknCount.getPromotion(), sortBrandType)); | ||
54 | } | 54 | } |
55 | // 3) 新降价 | 55 | // 3) 新降价 |
56 | - if (recallSknCount.getReducePrice() > 0) { | ||
57 | - requests.add(this.buildSortBrandReducePriceRequest(paramQueryFilter, sortBrand, recallSknCount.getReducePrice(), sortBrandType)); | 56 | + if (configSknCount.getReducePrice() > 0) { |
57 | + requests.add(this.buildSortBrandReducePriceRequest(paramQueryFilter, sortBrand, configSknCount.getReducePrice(), sortBrandType)); | ||
58 | } | 58 | } |
59 | // 4) 转化率 | 59 | // 4) 转化率 |
60 | - if (recallSknCount.getCtrValue() > 0) { | ||
61 | - requests.add(this.buildSortBrandCtrValueRequest(paramQueryFilter, sortBrand, recallSknCount.getCtrValue(), sortBrandType)); | 60 | + if (configSknCount.getCtrValue() > 0) { |
61 | + requests.add(this.buildSortBrandCtrValueRequest(paramQueryFilter, sortBrand, configSknCount.getCtrValue(), sortBrandType)); | ||
62 | } | 62 | } |
63 | // 5) 人气 | 63 | // 5) 人气 |
64 | - if (recallSknCount.getHeatValue() > 0) { | ||
65 | - requests.add(this.buildSortBrandHeatValueRequest(paramQueryFilter, sortBrand, recallSknCount.getHeatValue(), sortBrandType)); | 64 | + if (configSknCount.getHeatValue() > 0) { |
65 | + requests.add(this.buildSortBrandHeatValueRequest(paramQueryFilter, sortBrand, configSknCount.getHeatValue(), sortBrandType)); | ||
66 | } | 66 | } |
67 | // 6) 随机 | 67 | // 6) 随机 |
68 | - if (recallSknCount.getRandom() > 0) { | ||
69 | - requests.add(this.buildSortBrandRandomRequest(paramQueryFilter, sortBrand, recallSknCount.getRandom(), sortBrandType)); | 68 | + if (configSknCount.getRandom() > 0) { |
69 | + requests.add(this.buildSortBrandRandomRequest(paramQueryFilter, sortBrand, configSknCount.getRandom(), sortBrandType)); | ||
70 | } | 70 | } |
71 | } | 71 | } |
72 | return requests; | 72 | return requests; |
1 | package com.yoho.search.recall.config; | 1 | package com.yoho.search.recall.config; |
2 | 2 | ||
3 | -public class RecallSizeInterval { | 3 | +public class ConfigSizeInterval { |
4 | 4 | ||
5 | private int size; | 5 | private int size; |
6 | private int interval; | 6 | private int interval; |
7 | 7 | ||
8 | - public RecallSizeInterval(int size, int interval) { | 8 | + public ConfigSizeInterval(int size, int interval) { |
9 | this.size = size; | 9 | this.size = size; |
10 | this.interval = interval; | 10 | this.interval = interval; |
11 | } | 11 | } |
@@ -27,7 +27,7 @@ class RecallConfigCommonService { | @@ -27,7 +27,7 @@ class RecallConfigCommonService { | ||
27 | 27 | ||
28 | private ScheduledExecutorService schedule = Executors.newSingleThreadScheduledExecutor(); | 28 | private ScheduledExecutorService schedule = Executors.newSingleThreadScheduledExecutor(); |
29 | 29 | ||
30 | - private Map<String, Map<Integer, RecallSizeInterval>> typePageConfigCache = new HashMap<>(); | 30 | + private Map<String, Map<Integer, ConfigSizeInterval>> typePageConfigCache = new HashMap<>(); |
31 | 31 | ||
32 | @PostConstruct | 32 | @PostConstruct |
33 | void init() { | 33 | void init() { |
@@ -37,16 +37,16 @@ class RecallConfigCommonService { | @@ -37,16 +37,16 @@ class RecallConfigCommonService { | ||
37 | private void loadConfig() { | 37 | private void loadConfig() { |
38 | try { | 38 | try { |
39 | List<CsRecallConfigCommon> configList = csRecallConfigCommonIndexBaseService.queryAll(); | 39 | List<CsRecallConfigCommon> configList = csRecallConfigCommonIndexBaseService.queryAll(); |
40 | - Map<String, Map<Integer, RecallSizeInterval>> temp = new HashMap<>(); | 40 | + Map<String, Map<Integer, ConfigSizeInterval>> temp = new HashMap<>(); |
41 | for (CsRecallConfigCommon csRecallConfigCommon : configList) { | 41 | for (CsRecallConfigCommon csRecallConfigCommon : configList) { |
42 | - Map<Integer, RecallSizeInterval> pageConfigs = temp.get(csRecallConfigCommon.getConfigType()); | 42 | + Map<Integer, ConfigSizeInterval> pageConfigs = temp.get(csRecallConfigCommon.getConfigType()); |
43 | if (pageConfigs == null) { | 43 | if (pageConfigs == null) { |
44 | pageConfigs = new HashMap<>(); | 44 | pageConfigs = new HashMap<>(); |
45 | temp.put(csRecallConfigCommon.getConfigType(), pageConfigs); | 45 | temp.put(csRecallConfigCommon.getConfigType(), pageConfigs); |
46 | } | 46 | } |
47 | int size = csRecallConfigCommon.getSize(); | 47 | int size = csRecallConfigCommon.getSize(); |
48 | int interval = csRecallConfigCommon.getInterval(); | 48 | int interval = csRecallConfigCommon.getInterval(); |
49 | - pageConfigs.put(csRecallConfigCommon.getConfigPage(), new RecallSizeInterval(size, interval)); | 49 | + pageConfigs.put(csRecallConfigCommon.getConfigPage(), new ConfigSizeInterval(size, interval)); |
50 | } | 50 | } |
51 | typePageConfigCache = temp; | 51 | typePageConfigCache = temp; |
52 | System.out.println(JSON.toJSONString(typePageConfigCache)); | 52 | System.out.println(JSON.toJSONString(typePageConfigCache)); |
@@ -55,12 +55,12 @@ class RecallConfigCommonService { | @@ -55,12 +55,12 @@ class RecallConfigCommonService { | ||
55 | } | 55 | } |
56 | } | 56 | } |
57 | 57 | ||
58 | - private RecallSizeInterval queryCommonConfig(String configKey, int configPage) { | ||
59 | - Map<Integer, RecallSizeInterval> pageConfigMap = typePageConfigCache.get(configKey); | 58 | + private ConfigSizeInterval queryCommonConfig(String configKey, int configPage) { |
59 | + Map<Integer, ConfigSizeInterval> pageConfigMap = typePageConfigCache.get(configKey); | ||
60 | if (pageConfigMap == null) { | 60 | if (pageConfigMap == null) { |
61 | return null; | 61 | return null; |
62 | } | 62 | } |
63 | - RecallSizeInterval pageConfig = pageConfigMap.get(configPage); | 63 | + ConfigSizeInterval pageConfig = pageConfigMap.get(configPage); |
64 | if (pageConfig == null) { | 64 | if (pageConfig == null) { |
65 | pageConfig = pageConfigMap.get(RecallConfigConstants.DEFAULT_PAGE_ID); | 65 | pageConfig = pageConfigMap.get(RecallConfigConstants.DEFAULT_PAGE_ID); |
66 | } | 66 | } |
@@ -83,7 +83,7 @@ class RecallConfigCommonService { | @@ -83,7 +83,7 @@ class RecallConfigCommonService { | ||
83 | if (StringUtils.isBlank(configKey)) { | 83 | if (StringUtils.isBlank(configKey)) { |
84 | return defaultSize; | 84 | return defaultSize; |
85 | } | 85 | } |
86 | - RecallSizeInterval config = queryCommonConfig(configKey, pageId); | 86 | + ConfigSizeInterval config = queryCommonConfig(configKey, pageId); |
87 | return config == null ? defaultSize : config.getSize(); | 87 | return config == null ? defaultSize : config.getSize(); |
88 | } | 88 | } |
89 | 89 | ||
@@ -99,7 +99,7 @@ class RecallConfigCommonService { | @@ -99,7 +99,7 @@ class RecallConfigCommonService { | ||
99 | if (StringUtils.isBlank(configKey)) { | 99 | if (StringUtils.isBlank(configKey)) { |
100 | return defaultInterval; | 100 | return defaultInterval; |
101 | } | 101 | } |
102 | - RecallSizeInterval config = queryCommonConfig(configKey, pageId); | 102 | + ConfigSizeInterval config = queryCommonConfig(configKey, pageId); |
103 | return config == null ? defaultInterval : config.getInterval(); | 103 | return config == null ? defaultInterval : config.getInterval(); |
104 | } | 104 | } |
105 | 105 |
@@ -6,7 +6,6 @@ public class RecallConfigConstants { | @@ -6,7 +6,6 @@ public class RecallConfigConstants { | ||
6 | 6 | ||
7 | public static final int DEFAULT_PAGE_ID = 0; | 7 | public static final int DEFAULT_PAGE_ID = 0; |
8 | 8 | ||
9 | - | ||
10 | public static final String DIRECT_TRAIN = "DIRECT_TRAIN"; | 9 | public static final String DIRECT_TRAIN = "DIRECT_TRAIN"; |
11 | public static final String REC_SKN = "REC_SKN"; | 10 | public static final String REC_SKN = "REC_SKN"; |
12 | public static final String RT_SIM_SKN = "RT_SIM_SKN"; | 11 | public static final String RT_SIM_SKN = "RT_SIM_SKN"; |
@@ -25,7 +25,7 @@ class RecallConfigProductService { | @@ -25,7 +25,7 @@ class RecallConfigProductService { | ||
25 | @Autowired | 25 | @Autowired |
26 | private CsRecallConfigProductIndexBaseService csRecallConfigProductIndexBaseService; | 26 | private CsRecallConfigProductIndexBaseService csRecallConfigProductIndexBaseService; |
27 | 27 | ||
28 | - private Map<String, Map<Integer, RecallSknCount>> typePageConfigCache = new HashMap<>(); | 28 | + private Map<String, Map<Integer, ConfigSknCount>> typePageConfigCache = new HashMap<>(); |
29 | 29 | ||
30 | private ScheduledExecutorService schedule = Executors.newSingleThreadScheduledExecutor(); | 30 | private ScheduledExecutorService schedule = Executors.newSingleThreadScheduledExecutor(); |
31 | 31 | ||
@@ -36,7 +36,7 @@ class RecallConfigProductService { | @@ -36,7 +36,7 @@ class RecallConfigProductService { | ||
36 | 36 | ||
37 | private void loadRecallSknCountConfig() { | 37 | private void loadRecallSknCountConfig() { |
38 | try { | 38 | try { |
39 | - Map<String, Map<Integer, RecallSknCount>> tempTypePageConfigCache = new HashMap<>(); | 39 | + Map<String, Map<Integer, ConfigSknCount>> tempTypePageConfigCache = new HashMap<>(); |
40 | List<CsRecallConfigProduct> configList = csRecallConfigProductIndexBaseService.queryAll(); | 40 | List<CsRecallConfigProduct> configList = csRecallConfigProductIndexBaseService.queryAll(); |
41 | for (CsRecallConfigProduct productConfig : configList) { | 41 | for (CsRecallConfigProduct productConfig : configList) { |
42 | String configType = productConfig.getConfigType(); | 42 | String configType = productConfig.getConfigType(); |
@@ -71,14 +71,14 @@ class RecallConfigProductService { | @@ -71,14 +71,14 @@ class RecallConfigProductService { | ||
71 | return type + "_" + cacheKey; | 71 | return type + "_" + cacheKey; |
72 | } | 72 | } |
73 | 73 | ||
74 | - private void addElement(String configKey, int pageId, RecallSknCount recallSknCount, Map<String, Map<Integer, RecallSknCount>> map) { | 74 | + private void addElement(String configKey, int pageId, ConfigSknCount configSknCount, Map<String, Map<Integer, ConfigSknCount>> map) { |
75 | if (!map.containsKey(configKey)) { | 75 | if (!map.containsKey(configKey)) { |
76 | map.put(configKey, new HashMap<>()); | 76 | map.put(configKey, new HashMap<>()); |
77 | } | 77 | } |
78 | - map.get(configKey).put(pageId, recallSknCount); | 78 | + map.get(configKey).put(pageId, configSknCount); |
79 | } | 79 | } |
80 | 80 | ||
81 | - private RecallSknCount genProductCountConfig(CsRecallConfigProduct configProduct) { | 81 | + private ConfigSknCount genProductCountConfig(CsRecallConfigProduct configProduct) { |
82 | int newShelve = configProduct.getNewShelve(); | 82 | int newShelve = configProduct.getNewShelve(); |
83 | int promotion = configProduct.getPromotion(); | 83 | int promotion = configProduct.getPromotion(); |
84 | int reducePrice = configProduct.getReducePrice(); | 84 | int reducePrice = configProduct.getReducePrice(); |
@@ -88,24 +88,24 @@ class RecallConfigProductService { | @@ -88,24 +88,24 @@ class RecallConfigProductService { | ||
88 | return genProductCountConfig(newShelve, promotion, reducePrice, ctrValue, heatValue, random); | 88 | return genProductCountConfig(newShelve, promotion, reducePrice, ctrValue, heatValue, random); |
89 | } | 89 | } |
90 | 90 | ||
91 | - private RecallSknCount genProductCountConfig(int newShelve, int promotion, int reducePrice, int ctrValue, int heatValue, int random) { | ||
92 | - RecallSknCount recallSknCount = new RecallSknCount(); | ||
93 | - recallSknCount.setNewShelve(newShelve); | ||
94 | - recallSknCount.setPromotion(promotion); | ||
95 | - recallSknCount.setReducePrice(reducePrice); | ||
96 | - recallSknCount.setCtrValue(ctrValue); | ||
97 | - recallSknCount.setHeatValue(heatValue); | ||
98 | - recallSknCount.setRandom(random); | ||
99 | - return recallSknCount; | ||
100 | - } | ||
101 | - | ||
102 | - private RecallSknCount genProductCountConfigByCompare(RecallSknCount recallSknCount1, RecallSknCount recallSknCount2) { | ||
103 | - int newShelve = Math.min(recallSknCount1.getNewShelve(), recallSknCount2.getNewShelve()); | ||
104 | - int promotion = Math.min(recallSknCount1.getPromotion(), recallSknCount2.getPromotion()); | ||
105 | - int reducePrice = Math.min(recallSknCount1.getReducePrice(), recallSknCount2.getReducePrice()); | ||
106 | - int ctrValue = Math.min(recallSknCount1.getCtrValue(), recallSknCount2.getCtrValue()); | ||
107 | - int heatValue = Math.min(recallSknCount1.getHeatValue(), recallSknCount2.getHeatValue()); | ||
108 | - int random = Math.min(recallSknCount1.getHeatValue(), recallSknCount2.getHeatValue()); | 91 | + private ConfigSknCount genProductCountConfig(int newShelve, int promotion, int reducePrice, int ctrValue, int heatValue, int random) { |
92 | + ConfigSknCount configSknCount = new ConfigSknCount(); | ||
93 | + configSknCount.setNewShelve(newShelve); | ||
94 | + configSknCount.setPromotion(promotion); | ||
95 | + configSknCount.setReducePrice(reducePrice); | ||
96 | + configSknCount.setCtrValue(ctrValue); | ||
97 | + configSknCount.setHeatValue(heatValue); | ||
98 | + configSknCount.setRandom(random); | ||
99 | + return configSknCount; | ||
100 | + } | ||
101 | + | ||
102 | + private ConfigSknCount genProductCountConfigByCompare(ConfigSknCount configSknCount1, ConfigSknCount configSknCount2) { | ||
103 | + int newShelve = Math.min(configSknCount1.getNewShelve(), configSknCount2.getNewShelve()); | ||
104 | + int promotion = Math.min(configSknCount1.getPromotion(), configSknCount2.getPromotion()); | ||
105 | + int reducePrice = Math.min(configSknCount1.getReducePrice(), configSknCount2.getReducePrice()); | ||
106 | + int ctrValue = Math.min(configSknCount1.getCtrValue(), configSknCount2.getCtrValue()); | ||
107 | + int heatValue = Math.min(configSknCount1.getHeatValue(), configSknCount2.getHeatValue()); | ||
108 | + int random = Math.min(configSknCount1.getHeatValue(), configSknCount2.getHeatValue()); | ||
109 | return genProductCountConfig(newShelve, promotion, reducePrice, ctrValue, heatValue, random); | 109 | return genProductCountConfig(newShelve, promotion, reducePrice, ctrValue, heatValue, random); |
110 | } | 110 | } |
111 | 111 | ||
@@ -116,15 +116,15 @@ class RecallConfigProductService { | @@ -116,15 +116,15 @@ class RecallConfigProductService { | ||
116 | * @param sortBrand | 116 | * @param sortBrand |
117 | * @return | 117 | * @return |
118 | */ | 118 | */ |
119 | - public RecallSknCount queryRecallSknCount(int pageId, String sortBrandTypeKey, SortBrand sortBrand) { | 119 | + public ConfigSknCount queryRecallSknCount(int pageId, String sortBrandTypeKey, SortBrand sortBrand) { |
120 | //1、先取【配置的品牌*品类】的配置 | 120 | //1、先取【配置的品牌*品类】的配置 |
121 | - RecallSknCount recallSknCount = this.queryConfigBySortBrandWithType(pageId,RecallConfigConstants.SORT_BRAND, sortBrand); | ||
122 | - if(recallSknCount!=null){ | ||
123 | - return recallSknCount; | 121 | + ConfigSknCount configSknCount = this.queryConfigBySortBrandWithType(pageId,RecallConfigConstants.SORT_BRAND, sortBrand); |
122 | + if(configSknCount !=null){ | ||
123 | + return configSknCount; | ||
124 | } | 124 | } |
125 | //2、再取【配置的品牌或品类】配置 | 125 | //2、再取【配置的品牌或品类】配置 |
126 | - RecallSknCount sortConfig = this.queryConfigBySort(pageId, sortBrand.getMisort()); | ||
127 | - RecallSknCount brandConfig = this.queryConfigByBrand(pageId, sortBrand.getBrandId()); | 126 | + ConfigSknCount sortConfig = this.queryConfigBySort(pageId, sortBrand.getMisort()); |
127 | + ConfigSknCount brandConfig = this.queryConfigByBrand(pageId, sortBrand.getBrandId()); | ||
128 | if (sortConfig != null && brandConfig != null) { | 128 | if (sortConfig != null && brandConfig != null) { |
129 | return genProductCountConfigByCompare(sortConfig, brandConfig); | 129 | return genProductCountConfigByCompare(sortConfig, brandConfig); |
130 | } | 130 | } |
@@ -135,7 +135,7 @@ class RecallConfigProductService { | @@ -135,7 +135,7 @@ class RecallConfigProductService { | ||
135 | return brandConfig; | 135 | return brandConfig; |
136 | } | 136 | } |
137 | //3、再取当前类型的【品牌*品类】配置-没有则取默认的【0_0的数据】 | 137 | //3、再取当前类型的【品牌*品类】配置-没有则取默认的【0_0的数据】 |
138 | - RecallSknCount pageConfig = this.queryConfigBySortBrandWithType(pageId, sortBrandTypeKey, sortBrand); | 138 | + ConfigSknCount pageConfig = this.queryConfigBySortBrandWithType(pageId, sortBrandTypeKey, sortBrand); |
139 | if (pageConfig != null) { | 139 | if (pageConfig != null) { |
140 | return pageConfig; | 140 | return pageConfig; |
141 | } | 141 | } |
@@ -153,7 +153,7 @@ class RecallConfigProductService { | @@ -153,7 +153,7 @@ class RecallConfigProductService { | ||
153 | * @param sortBrand | 153 | * @param sortBrand |
154 | * @return | 154 | * @return |
155 | */ | 155 | */ |
156 | - private RecallSknCount queryConfigBySortBrandWithType(int pageId, String sortBrandType, SortBrand sortBrand) { | 156 | + private ConfigSknCount queryConfigBySortBrandWithType(int pageId, String sortBrandType, SortBrand sortBrand) { |
157 | String sortBrandKey = this.buildCacheKey(sortBrandType, sortBrand.key()); | 157 | String sortBrandKey = this.buildCacheKey(sortBrandType, sortBrand.key()); |
158 | return this.getRecallSknCount(sortBrandKey, pageId); | 158 | return this.getRecallSknCount(sortBrandKey, pageId); |
159 | } | 159 | } |
@@ -164,7 +164,7 @@ class RecallConfigProductService { | @@ -164,7 +164,7 @@ class RecallConfigProductService { | ||
164 | * @param middleSortId | 164 | * @param middleSortId |
165 | * @return | 165 | * @return |
166 | */ | 166 | */ |
167 | - private RecallSknCount queryConfigBySort(int pageId, int middleSortId) { | 167 | + private ConfigSknCount queryConfigBySort(int pageId, int middleSortId) { |
168 | String sortKey = this.buildCacheKey(RecallConfigConstants.SORT,String.valueOf(middleSortId)); | 168 | String sortKey = this.buildCacheKey(RecallConfigConstants.SORT,String.valueOf(middleSortId)); |
169 | return this.getRecallSknCount(sortKey, pageId); | 169 | return this.getRecallSknCount(sortKey, pageId); |
170 | } | 170 | } |
@@ -175,18 +175,18 @@ class RecallConfigProductService { | @@ -175,18 +175,18 @@ class RecallConfigProductService { | ||
175 | * @param brandId | 175 | * @param brandId |
176 | * @return | 176 | * @return |
177 | */ | 177 | */ |
178 | - private RecallSknCount queryConfigByBrand(int pageId, int brandId) { | 178 | + private ConfigSknCount queryConfigByBrand(int pageId, int brandId) { |
179 | String brandKey = this.buildCacheKey(RecallConfigConstants.BRAND,String.valueOf(brandId)); | 179 | String brandKey = this.buildCacheKey(RecallConfigConstants.BRAND,String.valueOf(brandId)); |
180 | return this.getRecallSknCount(brandKey, pageId); | 180 | return this.getRecallSknCount(brandKey, pageId); |
181 | } | 181 | } |
182 | 182 | ||
183 | 183 | ||
184 | - private RecallSknCount getRecallSknCount(String key, int pageId) { | ||
185 | - Map<Integer, RecallSknCount> pageConfig = typePageConfigCache.get(key); | 184 | + private ConfigSknCount getRecallSknCount(String key, int pageId) { |
185 | + Map<Integer, ConfigSknCount> pageConfig = typePageConfigCache.get(key); | ||
186 | if (pageConfig == null) { | 186 | if (pageConfig == null) { |
187 | return null; | 187 | return null; |
188 | } | 188 | } |
189 | - RecallSknCount sknCount = pageConfig.get(pageId); | 189 | + ConfigSknCount sknCount = pageConfig.get(pageId); |
190 | if (sknCount == null) { | 190 | if (sknCount == null) { |
191 | sknCount = pageConfig.get(RecallConfigConstants.DEFAULT_PAGE_ID); | 191 | sknCount = pageConfig.get(RecallConfigConstants.DEFAULT_PAGE_ID); |
192 | } | 192 | } |
@@ -101,21 +101,21 @@ public class RecallConfigService { | @@ -101,21 +101,21 @@ public class RecallConfigService { | ||
101 | * @param sortBrand | 101 | * @param sortBrand |
102 | * @return | 102 | * @return |
103 | */ | 103 | */ |
104 | - public RecallSknCount queryRecallSknCount(int pageId, SortBrandType sortBrandType, SortBrand sortBrand) { | 104 | + public ConfigSknCount queryRecallSknCount(int pageId, SortBrandType sortBrandType, SortBrand sortBrand) { |
105 | String sortBrandTypeKey = this.getSortBrandConfigKey(sortBrandType); | 105 | String sortBrandTypeKey = this.getSortBrandConfigKey(sortBrandType); |
106 | - RecallSknCount recallSknCount = recallConfigProductService.queryRecallSknCount(pageId, sortBrandTypeKey, sortBrand); | ||
107 | - if (recallSknCount == null) { | 106 | + ConfigSknCount configSknCount = recallConfigProductService.queryRecallSknCount(pageId, sortBrandTypeKey, sortBrand); |
107 | + if (configSknCount == null) { | ||
108 | RECALL_LOGGER.info("queryRecallSknCount,pageId is [{}],sortBrandType is [{}],sortBrand is[{}], RecallSknCount is[{}]", pageId, sortBrand.key(), sortBrandType.name(), "null"); | 108 | RECALL_LOGGER.info("queryRecallSknCount,pageId is [{}],sortBrandType is [{}],sortBrand is[{}], RecallSknCount is[{}]", pageId, sortBrand.key(), sortBrandType.name(), "null"); |
109 | return null; | 109 | return null; |
110 | } | 110 | } |
111 | - recallSknCount.setNewShelve(this.legallValue(recallSknCount.getNewShelve(), 0, 20)); | ||
112 | - recallSknCount.setPromotion(this.legallValue(recallSknCount.getPromotion(), 0, 20)); | ||
113 | - recallSknCount.setCtrValue(this.legallValue(recallSknCount.getCtrValue(), 0, 20)); | ||
114 | - recallSknCount.setHeatValue(this.legallValue(recallSknCount.getHeatValue(), 0, 20)); | ||
115 | - recallSknCount.setReducePrice(this.legallValue(recallSknCount.getReducePrice(), 0, 20)); | ||
116 | - recallSknCount.setRandom(this.legallValue(recallSknCount.getRandom(), 0, 20)); | ||
117 | - RECALL_LOGGER.info("queryRecallSknCount,pageId is [{}],sortBrandType is [{}],sortBrand is[{}], RecallSknCount is[{}]", pageId, sortBrand.key(), sortBrandType.name(), JSON.toJSONString(recallSknCount)); | ||
118 | - return recallSknCount; | 111 | + configSknCount.setNewShelve(this.legallValue(configSknCount.getNewShelve(), 0, 20)); |
112 | + configSknCount.setPromotion(this.legallValue(configSknCount.getPromotion(), 0, 20)); | ||
113 | + configSknCount.setCtrValue(this.legallValue(configSknCount.getCtrValue(), 0, 20)); | ||
114 | + configSknCount.setHeatValue(this.legallValue(configSknCount.getHeatValue(), 0, 20)); | ||
115 | + configSknCount.setReducePrice(this.legallValue(configSknCount.getReducePrice(), 0, 20)); | ||
116 | + configSknCount.setRandom(this.legallValue(configSknCount.getRandom(), 0, 20)); | ||
117 | + RECALL_LOGGER.info("queryRecallSknCount,pageId is [{}],sortBrandType is [{}],sortBrand is[{}], RecallSknCount is[{}]", pageId, sortBrand.key(), sortBrandType.name(), JSON.toJSONString(configSknCount)); | ||
118 | + return configSknCount; | ||
119 | } | 119 | } |
120 | 120 | ||
121 | private String getSortBrandConfigKey(SortBrandType sortBrandType) { | 121 | private String getSortBrandConfigKey(SortBrandType sortBrandType) { |
1 | package com.yoho.search.recall.config; | 1 | package com.yoho.search.recall.config; |
2 | 2 | ||
3 | import com.yoho.search.base.utils.CollectionUtils; | 3 | import com.yoho.search.base.utils.CollectionUtils; |
4 | +import com.yoho.search.base.utils.ConvertUtils; | ||
4 | import com.yoho.search.core.personalized.models.SortBrand; | 5 | import com.yoho.search.core.personalized.models.SortBrand; |
6 | +import com.yoho.search.dal.model.CsRecallConfigSortBrand; | ||
5 | import com.yoho.search.recall.models.personal.PagePersonalFactor; | 7 | import com.yoho.search.recall.models.personal.PagePersonalFactor; |
8 | +import com.yoho.search.service.base.index.CsRecallConfigSortBrandIndexBaseService; | ||
9 | +import org.springframework.beans.factory.annotation.Autowired; | ||
6 | import org.springframework.stereotype.Component; | 10 | import org.springframework.stereotype.Component; |
7 | 11 | ||
8 | -import java.util.*; | 12 | +import javax.annotation.PostConstruct; |
13 | +import java.util.ArrayList; | ||
14 | +import java.util.Collections; | ||
15 | +import java.util.List; | ||
16 | +import java.util.Set; | ||
9 | import java.util.concurrent.Executors; | 17 | import java.util.concurrent.Executors; |
10 | import java.util.concurrent.ScheduledExecutorService; | 18 | import java.util.concurrent.ScheduledExecutorService; |
19 | +import java.util.concurrent.TimeUnit; | ||
11 | 20 | ||
12 | @Component | 21 | @Component |
13 | class RecallConfigSortBrandService { | 22 | class RecallConfigSortBrandService { |
14 | 23 | ||
24 | + @Autowired | ||
25 | + private CsRecallConfigSortBrandIndexBaseService csRecallConfigSortBrandIndexBaseService; | ||
15 | 26 | ||
16 | private List<SortBrand> configSortBrands = new ArrayList<>(); | 27 | private List<SortBrand> configSortBrands = new ArrayList<>(); |
17 | 28 | ||
29 | + private ScheduledExecutorService schedule = Executors.newSingleThreadScheduledExecutor(); | ||
30 | + | ||
31 | + @PostConstruct | ||
32 | + void init() { | ||
33 | + schedule.scheduleAtFixedRate(() -> loadConfigSortBrands(), 0, 1, TimeUnit.MINUTES); | ||
34 | + } | ||
35 | + | ||
36 | + private void loadConfigSortBrands(){ | ||
37 | + List<SortBrand> temp = new ArrayList<>(); | ||
38 | + List<CsRecallConfigSortBrand> csRecallConfigSortBrands = csRecallConfigSortBrandIndexBaseService.queryAll(); | ||
39 | + for (CsRecallConfigSortBrand csRecallConfigSortBrand:csRecallConfigSortBrands){ | ||
40 | + Integer misort = csRecallConfigSortBrand.getSortId(); | ||
41 | + List<Integer> brandIds = ConvertUtils.stringToIntList(csRecallConfigSortBrand.getBrandIds(),","); | ||
42 | + for (Integer brandId:brandIds){ | ||
43 | + temp.add(new SortBrand(misort,brandId)); | ||
44 | + } | ||
45 | + } | ||
46 | + configSortBrands = temp; | ||
47 | + } | ||
48 | + | ||
49 | + | ||
18 | /** | 50 | /** |
19 | * 随机获取size个品类品牌 | 51 | * 随机获取size个品类品牌 |
20 | * | 52 | * |
1 | +package com.yoho.search.service.base.index; | ||
2 | + | ||
3 | +import com.alibaba.fastjson.JSON; | ||
4 | +import com.yoho.search.base.utils.ISearchConstants; | ||
5 | +import com.yoho.search.core.es.model.SearchParam; | ||
6 | +import com.yoho.search.core.es.model.SearchResult; | ||
7 | +import com.yoho.search.dal.model.CsRecallConfigSortBrand; | ||
8 | +import com.yoho.search.service.base.SearchCommonService; | ||
9 | +import org.springframework.beans.factory.annotation.Autowired; | ||
10 | +import org.springframework.stereotype.Service; | ||
11 | + | ||
12 | +import java.util.ArrayList; | ||
13 | +import java.util.List; | ||
14 | +import java.util.Map; | ||
15 | + | ||
16 | +@Service | ||
17 | +public class CsRecallConfigSortBrandIndexBaseService { | ||
18 | + | ||
19 | + @Autowired | ||
20 | + private SearchCommonService searchCommonService; | ||
21 | + | ||
22 | + public List<CsRecallConfigSortBrand> queryAll(){ | ||
23 | + SearchParam searchParam = new SearchParam(); | ||
24 | + searchParam.setOffset(0); | ||
25 | + searchParam.setSize(10000); | ||
26 | + SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_CS_RECALL_CONFIG_SORT_BRAND, searchParam); | ||
27 | + List<Map<String, Object>> results = searchResult.getResultList(); | ||
28 | + List<CsRecallConfigSortBrand> list = new ArrayList<>(); | ||
29 | + for (Map<String, Object> result : results) { | ||
30 | + list.add(JSON.parseObject(JSON.toJSONString(result),CsRecallConfigSortBrand.class)); | ||
31 | + } | ||
32 | + return list; | ||
33 | + } | ||
34 | +} |
-
Please register or login to post a comment