Authored by hugufei

解决循环引用反序列化,list返回null的问题

@@ -38,6 +38,23 @@ public class BigdataSimilarSknService { @@ -38,6 +38,23 @@ public class BigdataSimilarSknService {
38 @Autowired 38 @Autowired
39 private ProductIndexBaseService productIndexBaseService; 39 private ProductIndexBaseService productIndexBaseService;
40 40
  41 + /**
  42 + * 获取非重复skn
  43 + * @param productSknStr
  44 + * @return
  45 + */
  46 + private List<String> getDistinctSknList(String productSknStr){
  47 + List<String> results = new ArrayList<>();
  48 + String [] productSkns = productSknStr.split(",");
  49 + for (String productSkn : productSkns){
  50 + if(!results.contains(productSkn) && StringUtils.isNumeric(productSkn)){
  51 + results.add(productSkn);
  52 + }
  53 + }
  54 + return results;
  55 + }
  56 +
  57 +
41 @SearchCacheAble(cacheInMinute = 600, cacheName = "SEARCH_LIKE_NOT_IN_SHOP_SIMILAR", includeParams = { "product_skn", "viewNum" }) 58 @SearchCacheAble(cacheInMinute = 600, cacheName = "SEARCH_LIKE_NOT_IN_SHOP_SIMILAR", includeParams = { "product_skn", "viewNum" })
42 public SearchApiResult searchLikeSimilarSknNotInShop(Map<String, String> paramMap) { 59 public SearchApiResult searchLikeSimilarSknNotInShop(Map<String, String> paramMap) {
43 try { 60 try {
@@ -62,14 +79,14 @@ public class BigdataSimilarSknService { @@ -62,14 +79,14 @@ public class BigdataSimilarSknService {
62 //5.1)图片[性别+不同店铺] 79 //5.1)图片[性别+不同店铺]
63 List<String> diffShopImgSimilarSkns = new ArrayList<>(); 80 List<String> diffShopImgSimilarSkns = new ArrayList<>();
64 if (StringUtils.isNotEmpty(similarSkn.getDiffShopImgSimilarSkns())) { 81 if (StringUtils.isNotEmpty(similarSkn.getDiffShopImgSimilarSkns())) {
65 - diffShopImgSimilarSkns = CollectionUtils.arrayToList(similarSkn.getDiffShopImgSimilarSkns().split(",")); 82 + diffShopImgSimilarSkns = this.getDistinctSknList(similarSkn.getDiffShopImgSimilarSkns());
66 } 83 }
67 searchParams.add(this.builderSimilarSknSearchParam(productInfoInEs, diffShopImgSimilarSkns, true)); 84 searchParams.add(this.builderSimilarSknSearchParam(productInfoInEs, diffShopImgSimilarSkns, true));
68 85
69 //5.2)行为[性别+不同店铺+同品类] 86 //5.2)行为[性别+不同店铺+同品类]
70 List<String> diffShopActionSimilarSkns = new ArrayList<>(); 87 List<String> diffShopActionSimilarSkns = new ArrayList<>();
71 if (StringUtils.isNotEmpty(similarSkn.getDiffShopActionSimilarSkns())) { 88 if (StringUtils.isNotEmpty(similarSkn.getDiffShopActionSimilarSkns())) {
72 - diffShopActionSimilarSkns = CollectionUtils.arrayToList(similarSkn.getDiffShopActionSimilarSkns().split(",")); 89 + diffShopActionSimilarSkns = this.getDistinctSknList(similarSkn.getDiffShopActionSimilarSkns());
73 } 90 }
74 searchParams.add(this.builderSimilarSknSearchParam(productInfoInEs, diffShopActionSimilarSkns, true)); 91 searchParams.add(this.builderSimilarSknSearchParam(productInfoInEs, diffShopActionSimilarSkns, true));
75 92
@@ -115,7 +132,7 @@ public class BigdataSimilarSknService { @@ -115,7 +132,7 @@ public class BigdataSimilarSknService {
115 } 132 }
116 133
117 /** 134 /**
118 - * 按productSkn顺序截取商品条数 135 + * 按productSkn顺序截取商品条数-注意循环引用的问题
119 * @param esProductList 136 * @param esProductList
120 * @param sortedProductSkns 137 * @param sortedProductSkns
121 * @param size 138 * @param size
@@ -137,7 +154,7 @@ public class BigdataSimilarSknService { @@ -137,7 +154,7 @@ public class BigdataSimilarSknService {
137 }); 154 });
138 for (String productSkn : sortedProductSkns){ 155 for (String productSkn : sortedProductSkns){
139 if(productMap.containsKey(productSkn)){ 156 if(productMap.containsKey(productSkn)){
140 - results.add(productMap.get(productSkn)); 157 + results.add(new HashMap<>(productMap.get(productSkn)));//注意循环引用
141 } 158 }
142 if(results.size()>=size){ 159 if(results.size()>=size){
143 break; 160 break;