Authored by hugufei

fix bug

@@ -18,7 +18,8 @@ public class RecallConfigConstants { @@ -18,7 +18,8 @@ public class RecallConfigConstants {
18 public static final String VEC_W2V_SORT_BRAND = "VEC_W2V_SORT_BRAND"; 18 public static final String VEC_W2V_SORT_BRAND = "VEC_W2V_SORT_BRAND";
19 public static final String CONFIG_SORT_BRAND = "CONFIG_SORT_BRAND"; 19 public static final String CONFIG_SORT_BRAND = "CONFIG_SORT_BRAND";
20 20
21 - public static final String RECALL_SKN_COUNT_SORT = "SORT";  
22 - public static final String RECALL_SKN_COUNT_BRAND = "BRAND"; 21 + public static final String SORT = "SORT";
  22 + public static final String BRAND = "BRAND";
  23 + public static final String SORT_BRAND = "SORT_BRAND";
23 24
24 } 25 }
@@ -40,7 +40,7 @@ class RecallConfigProductService { @@ -40,7 +40,7 @@ class RecallConfigProductService {
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();
43 - int configTypeId = productConfig.getConfigTypeId(); 43 + String configTypeId = productConfig.getConfigTypeId();
44 int pageId = productConfig.getConfigPage(); 44 int pageId = productConfig.getConfigPage();
45 String configKey = this.buildConfiKey(configType,configTypeId); 45 String configKey = this.buildConfiKey(configType,configTypeId);
46 int configStatus = productConfig.getConfigStatus(); 46 int configStatus = productConfig.getConfigStatus();
@@ -55,26 +55,20 @@ class RecallConfigProductService { @@ -55,26 +55,20 @@ class RecallConfigProductService {
55 } 55 }
56 } 56 }
57 57
58 - private String buildConfiKey(String configType, int configTypeId) {  
59 - if (configType.equalsIgnoreCase(RecallConfigConstants.RECALL_SKN_COUNT_SORT)) {  
60 - return this.buildSortCacheKey(configTypeId);  
61 - } else if (configType.equalsIgnoreCase(RecallConfigConstants.RECALL_SKN_COUNT_BRAND)) {  
62 - return this.buildBrandCacheKey(configTypeId);  
63 - } else {  
64 - return this.buildSortBrandCacheKey(configType, new SortBrand()); 58 + private String buildConfiKey(String configType, String configTypeId) {
  59 + if (configType.equalsIgnoreCase(RecallConfigConstants.SORT)) {
  60 + return this.buildCacheKey(RecallConfigConstants.SORT,configTypeId);
  61 + } else if (configType.equalsIgnoreCase(RecallConfigConstants.BRAND)) {
  62 + return this.buildCacheKey(RecallConfigConstants.BRAND,configTypeId);
  63 + }else if (configType.equalsIgnoreCase(RecallConfigConstants.SORT_BRAND)){
  64 + return this.buildCacheKey(RecallConfigConstants.SORT_BRAND,configTypeId);
  65 + }else {
  66 + return this.buildCacheKey(configType,configTypeId);
65 } 67 }
66 } 68 }
67 69
68 - private String buildSortCacheKey(int middleSortId) {  
69 - return RecallConfigConstants.RECALL_SKN_COUNT_SORT + "_" + middleSortId;  
70 - }  
71 -  
72 - private String buildBrandCacheKey(int brandId) {  
73 - return RecallConfigConstants.RECALL_SKN_COUNT_BRAND + "_" + brandId;  
74 - }  
75 -  
76 - private String buildSortBrandCacheKey(String sortBrandType, SortBrand sortBrand) {  
77 - return sortBrandType + "_" + sortBrand.key(); 70 + private String buildCacheKey(String type,String cacheKey){
  71 + return type + "_" + cacheKey;
78 } 72 }
79 73
80 private void addElement(String configKey, int pageId, RecallSknCount recallSknCount, Map<String, Map<Integer, RecallSknCount>> map) { 74 private void addElement(String configKey, int pageId, RecallSknCount recallSknCount, Map<String, Map<Integer, RecallSknCount>> map) {
@@ -122,7 +116,13 @@ class RecallConfigProductService { @@ -122,7 +116,13 @@ class RecallConfigProductService {
122 * @param sortBrand 116 * @param sortBrand
123 * @return 117 * @return
124 */ 118 */
125 - public RecallSknCount queryRecallSknCount(int pageId, String sortBrandType, SortBrand sortBrand) { 119 + public RecallSknCount queryRecallSknCount(int pageId, String sortBrandTypeKey, SortBrand sortBrand) {
  120 + //1、先取【配置的品牌*品类】的配置
  121 + RecallSknCount recallSknCount = this.queryConfigBySortBrandWithType(pageId,RecallConfigConstants.SORT_BRAND, sortBrand);
  122 + if(recallSknCount!=null){
  123 + return recallSknCount;
  124 + }
  125 + //2、再取【配置的品牌或品类】配置
126 RecallSknCount sortConfig = this.queryConfigBySort(pageId, sortBrand.getMisort()); 126 RecallSknCount sortConfig = this.queryConfigBySort(pageId, sortBrand.getMisort());
127 RecallSknCount brandConfig = this.queryConfigByBrand(pageId, sortBrand.getBrandId()); 127 RecallSknCount brandConfig = this.queryConfigByBrand(pageId, sortBrand.getBrandId());
128 if (sortConfig != null && sortConfig != null) { 128 if (sortConfig != null && sortConfig != null) {
@@ -134,11 +134,12 @@ class RecallConfigProductService { @@ -134,11 +134,12 @@ class RecallConfigProductService {
134 if (brandConfig != null) { 134 if (brandConfig != null) {
135 return brandConfig; 135 return brandConfig;
136 } 136 }
137 - RecallSknCount pageConfig = this.queryConfigByPage(pageId, sortBrandType, sortBrand); 137 + //3、再取当前类型的【品牌*品类】配置-没有则取默认的【0_0的数据】
  138 + RecallSknCount pageConfig = this.queryConfigBySortBrandWithType(pageId, sortBrandTypeKey, sortBrand);
138 if (pageConfig != null) { 139 if (pageConfig != null) {
139 return pageConfig; 140 return pageConfig;
140 } 141 }
141 - pageConfig = this.queryConfigByPage(pageId, sortBrandType, new SortBrand());//使用默认的值替代 142 + pageConfig = this.queryConfigBySortBrandWithType(pageId, sortBrandTypeKey, new SortBrand());//使用默认的值替代
142 if (pageConfig != null) { 143 if (pageConfig != null) {
143 return pageConfig; 144 return pageConfig;
144 } 145 }
@@ -146,13 +147,25 @@ class RecallConfigProductService { @@ -146,13 +147,25 @@ class RecallConfigProductService {
146 } 147 }
147 148
148 /** 149 /**
  150 + * 查询【品类*品牌】在页面上的召回配置,没有则取pageId=0的数据
  151 + * @param pageId
  152 + * @param sortBrandType
  153 + * @param sortBrand
  154 + * @return
  155 + */
  156 + private RecallSknCount queryConfigBySortBrandWithType(int pageId, String sortBrandType, SortBrand sortBrand) {
  157 + String sortBrandKey = this.buildCacheKey(sortBrandType, sortBrand.key());
  158 + return this.getRecallSknCount(sortBrandKey, pageId);
  159 + }
  160 +
  161 + /**
149 * 查询中分类在页面上的召回配置,没有则取pageId=0的数据 162 * 查询中分类在页面上的召回配置,没有则取pageId=0的数据
150 * @param pageId 163 * @param pageId
151 * @param middleSortId 164 * @param middleSortId
152 * @return 165 * @return
153 */ 166 */
154 private RecallSknCount queryConfigBySort(int pageId, int middleSortId) { 167 private RecallSknCount queryConfigBySort(int pageId, int middleSortId) {
155 - String sortKey = this.buildSortCacheKey(middleSortId); 168 + String sortKey = this.buildCacheKey(RecallConfigConstants.SORT,String.valueOf(middleSortId));
156 return this.getRecallSknCount(sortKey, pageId); 169 return this.getRecallSknCount(sortKey, pageId);
157 } 170 }
158 171
@@ -163,21 +176,10 @@ class RecallConfigProductService { @@ -163,21 +176,10 @@ class RecallConfigProductService {
163 * @return 176 * @return
164 */ 177 */
165 private RecallSknCount queryConfigByBrand(int pageId, int brandId) { 178 private RecallSknCount queryConfigByBrand(int pageId, int brandId) {
166 - String brandKey = this.buildBrandCacheKey(brandId); 179 + String brandKey = this.buildCacheKey(RecallConfigConstants.BRAND,String.valueOf(brandId));
167 return this.getRecallSknCount(brandKey, pageId); 180 return this.getRecallSknCount(brandKey, pageId);
168 } 181 }
169 182
170 - /**  
171 - * 查询【品类*品牌】在页面上的召回配置,没有则取pageId=0的数据  
172 - * @param pageId  
173 - * @param sortBrandType  
174 - * @param sortBrand  
175 - * @return  
176 - */  
177 - private RecallSknCount queryConfigByPage(int pageId, String sortBrandType, SortBrand sortBrand) {  
178 - String sortBrandKey = this.buildSortBrandCacheKey(sortBrandType, sortBrand);  
179 - return this.getRecallSknCount(sortBrandKey, pageId);  
180 - }  
181 183
182 private RecallSknCount getRecallSknCount(String key, int pageId) { 184 private RecallSknCount getRecallSknCount(String key, int pageId) {
183 Map<Integer, RecallSknCount> pageConfig = typePageConfigCache.get(key); 185 Map<Integer, RecallSknCount> pageConfig = typePageConfigCache.get(key);
1 package com.yoho.search.recall.config; 1 package com.yoho.search.recall.config;
2 2
3 import com.alibaba.fastjson.JSON; 3 import com.alibaba.fastjson.JSON;
4 -import com.yoho.search.base.utils.CollectionUtils;  
5 import com.yoho.search.core.personalized.models.SortBrand; 4 import com.yoho.search.core.personalized.models.SortBrand;
6 import com.yoho.search.recall.beans.strategy.SortBrandType; 5 import com.yoho.search.recall.beans.strategy.SortBrandType;
7 import com.yoho.search.recall.beans.strategy.StrategyEnum; 6 import com.yoho.search.recall.beans.strategy.StrategyEnum;
@@ -11,7 +10,6 @@ import org.slf4j.LoggerFactory; @@ -11,7 +10,6 @@ import org.slf4j.LoggerFactory;
11 import org.springframework.beans.factory.annotation.Autowired; 10 import org.springframework.beans.factory.annotation.Autowired;
12 import org.springframework.stereotype.Service; 11 import org.springframework.stereotype.Service;
13 12
14 -import java.util.Collections;  
15 import java.util.List; 13 import java.util.List;
16 import java.util.Set; 14 import java.util.Set;
17 15
@@ -104,8 +102,8 @@ public class RecallConfigService { @@ -104,8 +102,8 @@ public class RecallConfigService {
104 * @return 102 * @return
105 */ 103 */
106 public RecallSknCount queryRecallSknCount(int pageId, SortBrandType sortBrandType, SortBrand sortBrand) { 104 public RecallSknCount queryRecallSknCount(int pageId, SortBrandType sortBrandType, SortBrand sortBrand) {
107 - String sortBrandConfigKey = this.getSortBrandConfigKey(sortBrandType);  
108 - RecallSknCount recallSknCount = recallConfigProductService.queryRecallSknCount(pageId, sortBrandConfigKey, sortBrand); 105 + String sortBrandTypeKey = this.getSortBrandConfigKey(sortBrandType);
  106 + RecallSknCount recallSknCount = recallConfigProductService.queryRecallSknCount(pageId, sortBrandTypeKey, sortBrand);
109 if (recallSknCount == null) { 107 if (recallSknCount == null) {
110 RECALL_LOGGER.info("queryRecallSknCount,pageId is [{}],sortBrandType is [{}],RecallSknCount is[{}]", pageId, sortBrandType.name(), "null"); 108 RECALL_LOGGER.info("queryRecallSknCount,pageId is [{}],sortBrandType is [{}],RecallSknCount is[{}]", pageId, sortBrandType.name(), "null");
111 return null; 109 return null;