Authored by 胡古飞

fix

package com.yoho.search.consumer.restapi;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -26,7 +24,8 @@ public class ForbiddenPageIdsController {
public Map<String, Object> reloadForbiddenPageIds() {
Map<String, Object> testResult = new HashMap<String, Object>();
try {
testResult.put("data", forbiddenPageIdsLogicService.reloadForbiddenPageIds());
forbiddenPageIdsLogicService.reloadForbiddenPageIds();
testResult.put("pageForbiddenSknCountMap",forbiddenPageIdsLogicService.getPageForbiddenSknCountMap());
testResult.put("code", 200);
testResult.put("message", "success");
} catch (Exception e) {
... ... @@ -36,33 +35,13 @@ public class ForbiddenPageIdsController {
}
return testResult;
}
@RequestMapping(value = "/getPageIdForbiddenSkns")
@ResponseBody
public Map<String, Object> getPageIdForbiddenSkns(@RequestParam String pageId) {
Map<String, Object> testResult = new HashMap<String, Object>();
try {
testResult.put("data", forbiddenPageIdsLogicService.getPageIdForbiddenSkns(pageId));
testResult.put("code", 200);
testResult.put("message", "success");
} catch (Exception e) {
e.printStackTrace();
testResult.put("code", 400);
testResult.put("message", e.getMessage());
}
return testResult;
}
@RequestMapping(value = "/existPageIdForbiddenSkns")
@RequestMapping(value = "/getSknForbiddenPageIds")
@ResponseBody
public Map<String, Object> existPageIdForbiddenSkns(@RequestParam String pageId, @RequestParam String productSkn) {
public Map<String, Object> getSknForbiddenPageIds(@RequestParam String productSkn) {
Map<String, Object> testResult = new HashMap<String, Object>();
try {
List<String> skns = forbiddenPageIdsLogicService.getPageIdForbiddenSkns(pageId);
if(skns==null){
skns = new ArrayList<String>();
}
testResult.put("data",skns.contains(productSkn));
testResult.put("data", forbiddenPageIdsLogicService.getSknForbiddenPageIds(productSkn));
testResult.put("code", 200);
testResult.put("message", "success");
} catch (Exception e) {
... ...
... ... @@ -29,40 +29,32 @@ public class ForbiddenPageIdsLogicService {
private static final String key = "SEARCH_FORBIDDEN_SKNLIST_%s";
private Map<String, List<String>> skn_forbiddenPageIds_map = null;
private Map<String, List<String>> sknForbiddenPageIdsMap = null;
private Map<String, Integer> pageForbiddenSknCountMap = null;
public List<String> getPageIdForbiddenSkns(String pageId) {
if (skn_forbiddenPageIds_map == null || skn_forbiddenPageIds_map.isEmpty()) {
return new ArrayList<String>();
}
return skn_forbiddenPageIds_map.get(pageId);
}
public synchronized Map<String, Integer> reloadForbiddenPageIds() {
Map<String, Integer> pageCountMap = new HashMap<String, Integer>();
public synchronized void reloadForbiddenPageIds() {
try {
INDEX_REBUILD_LOG.info("do reloadForbiddenPageIds .........");
List<String> allPageIds = SearchPageIdDefine.getAllPgeIds();
Map<String, List<String>> temp = new HashMap<String, List<String>>();
Map<String, List<String>> sknForbiddenPageIdsMap_temp = new HashMap<String, List<String>>();
Map<String, Integer> pageForbiddenSknCountMap_temp = new HashMap<String, Integer>();
for (String pageId : allPageIds) {
Set<String> forbiddenSknSet = this.getPageForbiddenSknSet(pageId);
for (String forbiddenSkn : forbiddenSknSet) {
List<String> pageIds = temp.get(forbiddenSkn);
List<String> pageIds = sknForbiddenPageIdsMap_temp.get(forbiddenSkn);
if (pageIds == null) {
pageIds = new ArrayList<String>();
temp.put(forbiddenSkn, pageIds);
sknForbiddenPageIdsMap_temp.put(forbiddenSkn, pageIds);
}
pageIds.add(pageId);
}
pageCountMap.put(pageId, forbiddenSknSet.size());
pageForbiddenSknCountMap_temp.put(pageId, forbiddenSknSet.size());
}
skn_forbiddenPageIds_map = temp;
sknForbiddenPageIdsMap = sknForbiddenPageIdsMap_temp;
pageForbiddenSknCountMap = pageForbiddenSknCountMap_temp;
} catch (Exception e) {
INDEX_REBUILD_LOG.error(e.getMessage(), e);
} finally {
}
return pageCountMap;
}
private Set<String> getPageForbiddenSknSet(String pageId) {
... ... @@ -78,7 +70,7 @@ public class ForbiddenPageIdsLogicService {
}
private boolean isNeedReload() {
if (skn_forbiddenPageIds_map == null || skn_forbiddenPageIds_map.isEmpty()) {
if (sknForbiddenPageIdsMap == null || sknForbiddenPageIdsMap.isEmpty()) {
return true;
}
return false;
... ... @@ -95,17 +87,29 @@ public class ForbiddenPageIdsLogicService {
}
}
public String getSknForbiddenPageIds(ProductIBO productIBO) {
public Map<String, Integer> getPageForbiddenSknCountMap() {
checkAndInit();
Integer productSkn = productIBO.getProductSkn();
if (productSkn == null) {
return this.pageForbiddenSknCountMap;
}
public String getSknForbiddenPageIds(String productSkn) {
checkAndInit();
if (StringUtils.isBlank(productSkn)) {
return "";
}
List<String> forbidPageIds = skn_forbiddenPageIds_map.get(productSkn.toString());
List<String> forbidPageIds = sknForbiddenPageIdsMap.get(productSkn);
if (forbidPageIds == null || forbidPageIds.isEmpty()) {
return "";
}
return StringUtils.join(forbidPageIds, ",");
}
public String getSknForbiddenPageIds(ProductIBO productIBO) {
Integer productSkn = productIBO.getProductSkn();
if (productSkn == null) {
return "";
}
return this.getSknForbiddenPageIds(productSkn.toString());
}
}
... ...
... ... @@ -28,8 +28,8 @@ redis.readonly.proxy.port=6379
redis.readonly.proxy.auth=
redis.notsync.twemproxy.addresses=192.168.102.222:6379
redis.notsync.twemproxy.auth=
bigDataRedis-search.proxy.address=test-bigdata-redis-1903805580.cn-north-1.elb.amazonaws.com.cn
bigDataRedis-search.proxy.port=6379
bigDataRedis-search.proxy.address=123.206.17.17
bigDataRedis-search.proxy.port=16379
bigDataRedis-search.proxy.auth=
#index rebuild
... ...