Authored by hugufei

fix bug

... ... @@ -18,7 +18,8 @@ public class RecallConfigConstants {
public static final String VEC_W2V_SORT_BRAND = "VEC_W2V_SORT_BRAND";
public static final String CONFIG_SORT_BRAND = "CONFIG_SORT_BRAND";
public static final String RECALL_SKN_COUNT_SORT = "SORT";
public static final String RECALL_SKN_COUNT_BRAND = "BRAND";
public static final String SORT = "SORT";
public static final String BRAND = "BRAND";
public static final String SORT_BRAND = "SORT_BRAND";
}
... ...
... ... @@ -40,7 +40,7 @@ class RecallConfigProductService {
List<CsRecallConfigProduct> configList = csRecallConfigProductIndexBaseService.queryAll();
for (CsRecallConfigProduct productConfig : configList) {
String configType = productConfig.getConfigType();
int configTypeId = productConfig.getConfigTypeId();
String configTypeId = productConfig.getConfigTypeId();
int pageId = productConfig.getConfigPage();
String configKey = this.buildConfiKey(configType,configTypeId);
int configStatus = productConfig.getConfigStatus();
... ... @@ -55,26 +55,20 @@ class RecallConfigProductService {
}
}
private String buildConfiKey(String configType, int configTypeId) {
if (configType.equalsIgnoreCase(RecallConfigConstants.RECALL_SKN_COUNT_SORT)) {
return this.buildSortCacheKey(configTypeId);
} else if (configType.equalsIgnoreCase(RecallConfigConstants.RECALL_SKN_COUNT_BRAND)) {
return this.buildBrandCacheKey(configTypeId);
} else {
return this.buildSortBrandCacheKey(configType, new SortBrand());
private String buildConfiKey(String configType, String configTypeId) {
if (configType.equalsIgnoreCase(RecallConfigConstants.SORT)) {
return this.buildCacheKey(RecallConfigConstants.SORT,configTypeId);
} else if (configType.equalsIgnoreCase(RecallConfigConstants.BRAND)) {
return this.buildCacheKey(RecallConfigConstants.BRAND,configTypeId);
}else if (configType.equalsIgnoreCase(RecallConfigConstants.SORT_BRAND)){
return this.buildCacheKey(RecallConfigConstants.SORT_BRAND,configTypeId);
}else {
return this.buildCacheKey(configType,configTypeId);
}
}
private String buildSortCacheKey(int middleSortId) {
return RecallConfigConstants.RECALL_SKN_COUNT_SORT + "_" + middleSortId;
}
private String buildBrandCacheKey(int brandId) {
return RecallConfigConstants.RECALL_SKN_COUNT_BRAND + "_" + brandId;
}
private String buildSortBrandCacheKey(String sortBrandType, SortBrand sortBrand) {
return sortBrandType + "_" + sortBrand.key();
private String buildCacheKey(String type,String cacheKey){
return type + "_" + cacheKey;
}
private void addElement(String configKey, int pageId, RecallSknCount recallSknCount, Map<String, Map<Integer, RecallSknCount>> map) {
... ... @@ -122,7 +116,13 @@ class RecallConfigProductService {
* @param sortBrand
* @return
*/
public RecallSknCount queryRecallSknCount(int pageId, String sortBrandType, SortBrand sortBrand) {
public RecallSknCount queryRecallSknCount(int pageId, String sortBrandTypeKey, SortBrand sortBrand) {
//1、先取【配置的品牌*品类】的配置
RecallSknCount recallSknCount = this.queryConfigBySortBrandWithType(pageId,RecallConfigConstants.SORT_BRAND, sortBrand);
if(recallSknCount!=null){
return recallSknCount;
}
//2、再取【配置的品牌或品类】配置
RecallSknCount sortConfig = this.queryConfigBySort(pageId, sortBrand.getMisort());
RecallSknCount brandConfig = this.queryConfigByBrand(pageId, sortBrand.getBrandId());
if (sortConfig != null && sortConfig != null) {
... ... @@ -134,11 +134,12 @@ class RecallConfigProductService {
if (brandConfig != null) {
return brandConfig;
}
RecallSknCount pageConfig = this.queryConfigByPage(pageId, sortBrandType, sortBrand);
//3、再取当前类型的【品牌*品类】配置-没有则取默认的【0_0的数据】
RecallSknCount pageConfig = this.queryConfigBySortBrandWithType(pageId, sortBrandTypeKey, sortBrand);
if (pageConfig != null) {
return pageConfig;
}
pageConfig = this.queryConfigByPage(pageId, sortBrandType, new SortBrand());//使用默认的值替代
pageConfig = this.queryConfigBySortBrandWithType(pageId, sortBrandTypeKey, new SortBrand());//使用默认的值替代
if (pageConfig != null) {
return pageConfig;
}
... ... @@ -146,13 +147,25 @@ class RecallConfigProductService {
}
/**
* 查询【品类*品牌】在页面上的召回配置,没有则取pageId=0的数据
* @param pageId
* @param sortBrandType
* @param sortBrand
* @return
*/
private RecallSknCount queryConfigBySortBrandWithType(int pageId, String sortBrandType, SortBrand sortBrand) {
String sortBrandKey = this.buildCacheKey(sortBrandType, sortBrand.key());
return this.getRecallSknCount(sortBrandKey, pageId);
}
/**
* 查询中分类在页面上的召回配置,没有则取pageId=0的数据
* @param pageId
* @param middleSortId
* @return
*/
private RecallSknCount queryConfigBySort(int pageId, int middleSortId) {
String sortKey = this.buildSortCacheKey(middleSortId);
String sortKey = this.buildCacheKey(RecallConfigConstants.SORT,String.valueOf(middleSortId));
return this.getRecallSknCount(sortKey, pageId);
}
... ... @@ -163,21 +176,10 @@ class RecallConfigProductService {
* @return
*/
private RecallSknCount queryConfigByBrand(int pageId, int brandId) {
String brandKey = this.buildBrandCacheKey(brandId);
String brandKey = this.buildCacheKey(RecallConfigConstants.BRAND,String.valueOf(brandId));
return this.getRecallSknCount(brandKey, pageId);
}
/**
* 查询【品类*品牌】在页面上的召回配置,没有则取pageId=0的数据
* @param pageId
* @param sortBrandType
* @param sortBrand
* @return
*/
private RecallSknCount queryConfigByPage(int pageId, String sortBrandType, SortBrand sortBrand) {
String sortBrandKey = this.buildSortBrandCacheKey(sortBrandType, sortBrand);
return this.getRecallSknCount(sortBrandKey, pageId);
}
private RecallSknCount getRecallSknCount(String key, int pageId) {
Map<Integer, RecallSknCount> pageConfig = typePageConfigCache.get(key);
... ...
package com.yoho.search.recall.config;
import com.alibaba.fastjson.JSON;
import com.yoho.search.base.utils.CollectionUtils;
import com.yoho.search.core.personalized.models.SortBrand;
import com.yoho.search.recall.beans.strategy.SortBrandType;
import com.yoho.search.recall.beans.strategy.StrategyEnum;
... ... @@ -11,7 +10,6 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Collections;
import java.util.List;
import java.util.Set;
... ... @@ -104,8 +102,8 @@ public class RecallConfigService {
* @return
*/
public RecallSknCount queryRecallSknCount(int pageId, SortBrandType sortBrandType, SortBrand sortBrand) {
String sortBrandConfigKey = this.getSortBrandConfigKey(sortBrandType);
RecallSknCount recallSknCount = recallConfigProductService.queryRecallSknCount(pageId, sortBrandConfigKey, sortBrand);
String sortBrandTypeKey = this.getSortBrandConfigKey(sortBrandType);
RecallSknCount recallSknCount = recallConfigProductService.queryRecallSknCount(pageId, sortBrandTypeKey, sortBrand);
if (recallSknCount == null) {
RECALL_LOGGER.info("queryRecallSknCount,pageId is [{}],sortBrandType is [{}],RecallSknCount is[{}]", pageId, sortBrandType.name(), "null");
return null;
... ...