Authored by 胡古飞

fix

1 package com.yoho.search.consumer.restapi; 1 package com.yoho.search.consumer.restapi;
2 2
3 -import java.util.ArrayList;  
4 import java.util.HashMap; 3 import java.util.HashMap;
5 -import java.util.List;  
6 import java.util.Map; 4 import java.util.Map;
7 5
8 import org.springframework.beans.factory.annotation.Autowired; 6 import org.springframework.beans.factory.annotation.Autowired;
@@ -26,7 +24,8 @@ public class ForbiddenPageIdsController { @@ -26,7 +24,8 @@ public class ForbiddenPageIdsController {
26 public Map<String, Object> reloadForbiddenPageIds() { 24 public Map<String, Object> reloadForbiddenPageIds() {
27 Map<String, Object> testResult = new HashMap<String, Object>(); 25 Map<String, Object> testResult = new HashMap<String, Object>();
28 try { 26 try {
29 - testResult.put("data", forbiddenPageIdsLogicService.reloadForbiddenPageIds()); 27 + forbiddenPageIdsLogicService.reloadForbiddenPageIds();
  28 + testResult.put("pageForbiddenSknCountMap",forbiddenPageIdsLogicService.getPageForbiddenSknCountMap());
30 testResult.put("code", 200); 29 testResult.put("code", 200);
31 testResult.put("message", "success"); 30 testResult.put("message", "success");
32 } catch (Exception e) { 31 } catch (Exception e) {
@@ -36,33 +35,13 @@ public class ForbiddenPageIdsController { @@ -36,33 +35,13 @@ public class ForbiddenPageIdsController {
36 } 35 }
37 return testResult; 36 return testResult;
38 } 37 }
39 -  
40 - @RequestMapping(value = "/getPageIdForbiddenSkns")  
41 - @ResponseBody  
42 - public Map<String, Object> getPageIdForbiddenSkns(@RequestParam String pageId) {  
43 - Map<String, Object> testResult = new HashMap<String, Object>();  
44 - try {  
45 - testResult.put("data", forbiddenPageIdsLogicService.getPageIdForbiddenSkns(pageId));  
46 - testResult.put("code", 200);  
47 - testResult.put("message", "success");  
48 - } catch (Exception e) {  
49 - e.printStackTrace();  
50 - testResult.put("code", 400);  
51 - testResult.put("message", e.getMessage());  
52 - }  
53 - return testResult;  
54 - }  
55 -  
56 - @RequestMapping(value = "/existPageIdForbiddenSkns") 38 +
  39 + @RequestMapping(value = "/getSknForbiddenPageIds")
57 @ResponseBody 40 @ResponseBody
58 - public Map<String, Object> existPageIdForbiddenSkns(@RequestParam String pageId, @RequestParam String productSkn) { 41 + public Map<String, Object> getSknForbiddenPageIds(@RequestParam String productSkn) {
59 Map<String, Object> testResult = new HashMap<String, Object>(); 42 Map<String, Object> testResult = new HashMap<String, Object>();
60 try { 43 try {
61 - List<String> skns = forbiddenPageIdsLogicService.getPageIdForbiddenSkns(pageId);  
62 - if(skns==null){  
63 - skns = new ArrayList<String>();  
64 - }  
65 - testResult.put("data",skns.contains(productSkn)); 44 + testResult.put("data", forbiddenPageIdsLogicService.getSknForbiddenPageIds(productSkn));
66 testResult.put("code", 200); 45 testResult.put("code", 200);
67 testResult.put("message", "success"); 46 testResult.put("message", "success");
68 } catch (Exception e) { 47 } catch (Exception e) {
@@ -29,40 +29,32 @@ public class ForbiddenPageIdsLogicService { @@ -29,40 +29,32 @@ public class ForbiddenPageIdsLogicService {
29 29
30 private static final String key = "SEARCH_FORBIDDEN_SKNLIST_%s"; 30 private static final String key = "SEARCH_FORBIDDEN_SKNLIST_%s";
31 31
32 - private Map<String, List<String>> skn_forbiddenPageIds_map = null; 32 + private Map<String, List<String>> sknForbiddenPageIdsMap = null;
  33 + private Map<String, Integer> pageForbiddenSknCountMap = null;
33 34
34 - public List<String> getPageIdForbiddenSkns(String pageId) {  
35 - if (skn_forbiddenPageIds_map == null || skn_forbiddenPageIds_map.isEmpty()) {  
36 - return new ArrayList<String>();  
37 - }  
38 - return skn_forbiddenPageIds_map.get(pageId);  
39 - }  
40 -  
41 - public synchronized Map<String, Integer> reloadForbiddenPageIds() {  
42 - Map<String, Integer> pageCountMap = new HashMap<String, Integer>(); 35 + public synchronized void reloadForbiddenPageIds() {
43 try { 36 try {
44 INDEX_REBUILD_LOG.info("do reloadForbiddenPageIds ........."); 37 INDEX_REBUILD_LOG.info("do reloadForbiddenPageIds .........");
45 List<String> allPageIds = SearchPageIdDefine.getAllPgeIds(); 38 List<String> allPageIds = SearchPageIdDefine.getAllPgeIds();
46 - Map<String, List<String>> temp = new HashMap<String, List<String>>(); 39 + Map<String, List<String>> sknForbiddenPageIdsMap_temp = new HashMap<String, List<String>>();
  40 + Map<String, Integer> pageForbiddenSknCountMap_temp = new HashMap<String, Integer>();
47 for (String pageId : allPageIds) { 41 for (String pageId : allPageIds) {
48 Set<String> forbiddenSknSet = this.getPageForbiddenSknSet(pageId); 42 Set<String> forbiddenSknSet = this.getPageForbiddenSknSet(pageId);
49 for (String forbiddenSkn : forbiddenSknSet) { 43 for (String forbiddenSkn : forbiddenSknSet) {
50 - List<String> pageIds = temp.get(forbiddenSkn); 44 + List<String> pageIds = sknForbiddenPageIdsMap_temp.get(forbiddenSkn);
51 if (pageIds == null) { 45 if (pageIds == null) {
52 pageIds = new ArrayList<String>(); 46 pageIds = new ArrayList<String>();
53 - temp.put(forbiddenSkn, pageIds); 47 + sknForbiddenPageIdsMap_temp.put(forbiddenSkn, pageIds);
54 } 48 }
55 pageIds.add(pageId); 49 pageIds.add(pageId);
56 } 50 }
57 - pageCountMap.put(pageId, forbiddenSknSet.size()); 51 + pageForbiddenSknCountMap_temp.put(pageId, forbiddenSknSet.size());
58 } 52 }
59 - skn_forbiddenPageIds_map = temp; 53 + sknForbiddenPageIdsMap = sknForbiddenPageIdsMap_temp;
  54 + pageForbiddenSknCountMap = pageForbiddenSknCountMap_temp;
60 } catch (Exception e) { 55 } catch (Exception e) {
61 INDEX_REBUILD_LOG.error(e.getMessage(), e); 56 INDEX_REBUILD_LOG.error(e.getMessage(), e);
62 - } finally {  
63 -  
64 } 57 }
65 - return pageCountMap;  
66 } 58 }
67 59
68 private Set<String> getPageForbiddenSknSet(String pageId) { 60 private Set<String> getPageForbiddenSknSet(String pageId) {
@@ -78,7 +70,7 @@ public class ForbiddenPageIdsLogicService { @@ -78,7 +70,7 @@ public class ForbiddenPageIdsLogicService {
78 } 70 }
79 71
80 private boolean isNeedReload() { 72 private boolean isNeedReload() {
81 - if (skn_forbiddenPageIds_map == null || skn_forbiddenPageIds_map.isEmpty()) { 73 + if (sknForbiddenPageIdsMap == null || sknForbiddenPageIdsMap.isEmpty()) {
82 return true; 74 return true;
83 } 75 }
84 return false; 76 return false;
@@ -95,17 +87,29 @@ public class ForbiddenPageIdsLogicService { @@ -95,17 +87,29 @@ public class ForbiddenPageIdsLogicService {
95 } 87 }
96 } 88 }
97 89
98 - public String getSknForbiddenPageIds(ProductIBO productIBO) { 90 + public Map<String, Integer> getPageForbiddenSknCountMap() {
99 checkAndInit(); 91 checkAndInit();
100 - Integer productSkn = productIBO.getProductSkn();  
101 - if (productSkn == null) { 92 + return this.pageForbiddenSknCountMap;
  93 + }
  94 +
  95 + public String getSknForbiddenPageIds(String productSkn) {
  96 + checkAndInit();
  97 + if (StringUtils.isBlank(productSkn)) {
102 return ""; 98 return "";
103 } 99 }
104 - List<String> forbidPageIds = skn_forbiddenPageIds_map.get(productSkn.toString()); 100 + List<String> forbidPageIds = sknForbiddenPageIdsMap.get(productSkn);
105 if (forbidPageIds == null || forbidPageIds.isEmpty()) { 101 if (forbidPageIds == null || forbidPageIds.isEmpty()) {
106 return ""; 102 return "";
107 } 103 }
108 return StringUtils.join(forbidPageIds, ","); 104 return StringUtils.join(forbidPageIds, ",");
109 } 105 }
110 106
  107 + public String getSknForbiddenPageIds(ProductIBO productIBO) {
  108 + Integer productSkn = productIBO.getProductSkn();
  109 + if (productSkn == null) {
  110 + return "";
  111 + }
  112 + return this.getSknForbiddenPageIds(productSkn.toString());
  113 + }
  114 +
111 } 115 }
@@ -28,8 +28,8 @@ redis.readonly.proxy.port=6379 @@ -28,8 +28,8 @@ redis.readonly.proxy.port=6379
28 redis.readonly.proxy.auth= 28 redis.readonly.proxy.auth=
29 redis.notsync.twemproxy.addresses=192.168.102.222:6379 29 redis.notsync.twemproxy.addresses=192.168.102.222:6379
30 redis.notsync.twemproxy.auth= 30 redis.notsync.twemproxy.auth=
31 -bigDataRedis-search.proxy.address=test-bigdata-redis-1903805580.cn-north-1.elb.amazonaws.com.cn  
32 -bigDataRedis-search.proxy.port=6379 31 +bigDataRedis-search.proxy.address=123.206.17.17
  32 +bigDataRedis-search.proxy.port=16379
33 bigDataRedis-search.proxy.auth= 33 bigDataRedis-search.proxy.auth=
34 34
35 #index rebuild 35 #index rebuild