|
|
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, ",");
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|