Authored by 胡古飞

新版屏蔽功能

package com.yoho.search.consumer.restapi;
import java.util.HashMap;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.yoho.search.consumer.service.logic.tools.ForbiddenPageIdsLogicService;
import com.yoho.search.consumer.service.logic.tools.ForbidenSortBrandLogicService;
@Controller
public class ForbiddenPageIdsController {
@Autowired
private ForbiddenPageIdsLogicService forbiddenPageIdsLogicService;
@RequestMapping(value = "/forbiddenPageIds")
@ResponseBody
public Map<String, Object> forbiddenBrands() {
Map<String, Object> testResult = new HashMap<String, Object>();
try {
testResult.put("data", forbiddenPageIdsLogicService.reloadForbiddenPageIds());
testResult.put("code", 200);
testResult.put("message", "success");
} catch (Exception e) {
e.printStackTrace();
testResult.put("code", 400);
testResult.put("message", e.getMessage());
}
return testResult;
}
}
... ...
... ... @@ -966,6 +966,10 @@
"sknDefaultImg": {
"type": "string",
"index": "not_analyzed"
},
"forbiddenPageIds": {
"type": "string",
"analyzer": "comma_spliter"
}
}
}
... ...
... ... @@ -184,6 +184,7 @@ public class ProductIndexService {
}
map.put("specialSearchField", productIndexBO.getSpecialSearchField());
map.put("isForbiddenSortBrand", productIndexBO.getIsForbiddenSortBrand());
map.put("forbiddenPageIds", productIndexBO.getForbiddenPageIds());
map.put("productFeatureFactor", productIndexBO.getProductFeatureFactor());
map.put("tblCountryId", productIndexBO.getTblCountryId());
map.put("tblCountryName", productIndexBO.getTblCountryName());
... ...
... ... @@ -83,6 +83,7 @@ public class ProductIBO implements Serializable {
private String specialSearchField;// 特殊搜索字段
private Integer isForbiddenSortBrand;// 是否是品类+品牌的屏蔽字段
private String forbiddenPageIds;// 需要屏蔽的页面id
// from quanqiugou
private String isGlobal = "N";
... ... @@ -91,7 +92,7 @@ public class ProductIBO implements Serializable {
private String physicalChannels;
private Integer bundleType; // 折扣类型 0:正常商品 1:套餐 2:量贩 3:搭配
public Integer getId() {
return id;
}
... ... @@ -604,6 +605,14 @@ public class ProductIBO implements Serializable {
this.isForbiddenSortBrand = isForbiddenSortBrand;
}
public String getForbiddenPageIds() {
return forbiddenPageIds;
}
public void setForbiddenPageIds(String forbiddenPageIds) {
this.forbiddenPageIds = forbiddenPageIds;
}
public String getIsGlobal() {
return isGlobal;
}
... ...
package com.yoho.search.consumer.service.logic.tools;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yoho.search.base.utils.SearchPageIdDefine;
import com.yoho.search.consumer.service.bo.ProductIBO;
import com.yoho.search.core.personalized.BigDataRedisOper;
@Service
public class ForbiddenPageIdsLogicService {
private static final Logger logger = LoggerFactory.getLogger(ForbiddenPageIdsLogicService.class);
@Autowired
private BigDataRedisOper<String, String> bigDataRedisOper;
private static final String key = "SEARCH_FORBIDDEN_SKNLIST_%s";
private Map<String, List<String>> skn_forbiddenPageIds_map = null;
public synchronized Map<String, List<String>> reloadForbiddenPageIds() {
List<String> allPageIds = SearchPageIdDefine.getAllPgeIds();
Map<String, List<String>> temp = new HashMap<String, List<String>>();
for (String pageId : allPageIds) {
Set<String> forbiddenSknSet = this.getPageForbiddenSknSet(pageId);
for (String forbiddenSkn : forbiddenSknSet) {
List<String> pageIds = temp.get(forbiddenSkn);
if (pageIds == null) {
pageIds = new ArrayList<String>();
temp.put(forbiddenSkn, pageIds);
}
pageIds.add(pageId);
}
}
skn_forbiddenPageIds_map = temp;
return skn_forbiddenPageIds_map;
}
private synchronized void checkAndInit() {
if (skn_forbiddenPageIds_map == null) {
reloadForbiddenPageIds();
}
}
private Set<String> getPageForbiddenSknSet(String pageId) {
try {
String redisKey = String.format(key, pageId);
Set<String> forbiddenSkns = bigDataRedisOper.getBigDataSetOperations().members(redisKey);
logger.info("pageId is[{}], redisKey is [{}], forbiddenSkns size is [{}]", pageId, redisKey, forbiddenSkns.size());
return forbiddenSkns;
} catch (Exception e) {
logger.error(e.getMessage(), e);
return new HashSet<String>();
}
}
public String getSknForbiddenPageIds(ProductIBO productIBO) {
checkAndInit();
Integer productSkn = productIBO.getProductSkn();
if (productSkn == null) {
return "";
}
List<String> forbidPageIds = skn_forbiddenPageIds_map.get(productSkn.toString());
if (forbidPageIds == null || forbidPageIds.isEmpty()) {
return "";
}
return StringUtils.join(forbidPageIds, ",");
}
}
... ...
package com.yoho.search.consumer.service.logic.tools;
import com.yoho.search.consumer.service.bo.ProductIBO;
import com.yoho.search.consumer.service.bo.ProductIndexBO;
import com.yoho.search.consumer.service.bo.StorageSkuBO;
import com.yoho.search.consumer.service.logic.SalesCategoryLogicService;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import com.yoho.search.consumer.service.bo.ProductIBO;
import com.yoho.search.consumer.service.bo.ProductIndexBO;
import com.yoho.search.consumer.service.bo.StorageSkuBO;
import com.yoho.search.consumer.service.logic.SalesCategoryLogicService;
/**
* Created by hugufei
... ... @@ -19,6 +20,8 @@ public class SpecialDealLogicService {
@Autowired
private ForbidenSortBrandLogicService forbidenSortBrandLogicService;
@Autowired
private ForbiddenPageIdsLogicService forbiddenPageIdsLogicService;
@Autowired
private SalesCategoryLogicService salesCategoryLogicService;
private String specialDealAgeLevel(String ageLevel) {
... ... @@ -106,14 +109,18 @@ public class SpecialDealLogicService {
int isForbiddenSortBrand = this.getIsForbiddenSortBrand(productIBO);
productIBO.setIsForbiddenSortBrand(isForbiddenSortBrand);
// 4、处理物理分类对应的销售分类
// 4、处理forbiddenPageIds
String forbiddenPageIds = forbiddenPageIdsLogicService.getSknForbiddenPageIds(productIBO);
productIBO.setForbiddenPageIds(forbiddenPageIds);
// 5、处理物理分类对应的销售分类
List<Integer> physicalChannels = salesCategoryLogicService.getPhysicalChannelsBySmallSortId(productIBO.getSmallSortId());
productIBO.setPhysicalChannels(StringUtils.join(physicalChannels, ","));
if ("Y".equals(productIBO.getIsGlobal())) {
productIBO.setPhysicalChannels("1,2,3,4");
}
// 5、处理限购,防止数据库未设置
// 6、处理限购,防止数据库未设置
if (StringUtils.isBlank(productIBO.getIsLimitbuy())) {
productIBO.setIsLimitbuy("N");
}
... ...