|
@@ -2,13 +2,17 @@ package com.yoho.search.common.productlist.aop; |
|
@@ -2,13 +2,17 @@ package com.yoho.search.common.productlist.aop; |
2
|
|
2
|
|
3
|
import com.alibaba.fastjson.JSONArray;
|
3
|
import com.alibaba.fastjson.JSONArray;
|
4
|
import com.alibaba.fastjson.JSONObject;
|
4
|
import com.alibaba.fastjson.JSONObject;
|
|
|
5
|
+import com.yoho.search.common.utils.SearchApiResultUtils;
|
5
|
import com.yoho.search.models.ProductListWithSkn;
|
6
|
import com.yoho.search.models.ProductListWithSkn;
|
6
|
import com.yoho.search.models.SearchApiResult;
|
7
|
import com.yoho.search.models.SearchApiResult;
|
7
|
import com.yoho.search.recall.scene.beans.cache.SknReturnInfoCacheBean;
|
8
|
import com.yoho.search.recall.scene.beans.cache.SknReturnInfoCacheBean;
|
|
|
9
|
+import com.yoho.search.recall.scene.beans.strategy.StrategyEnum;
|
8
|
import org.aspectj.lang.ProceedingJoinPoint;
|
10
|
import org.aspectj.lang.ProceedingJoinPoint;
|
9
|
import org.aspectj.lang.annotation.Around;
|
11
|
import org.aspectj.lang.annotation.Around;
|
10
|
import org.aspectj.lang.annotation.Aspect;
|
12
|
import org.aspectj.lang.annotation.Aspect;
|
11
|
import org.aspectj.lang.reflect.MethodSignature;
|
13
|
import org.aspectj.lang.reflect.MethodSignature;
|
|
|
14
|
+import org.slf4j.Logger;
|
|
|
15
|
+import org.slf4j.LoggerFactory;
|
12
|
import org.springframework.beans.factory.annotation.Autowired;
|
16
|
import org.springframework.beans.factory.annotation.Autowired;
|
13
|
import org.springframework.core.annotation.Order;
|
17
|
import org.springframework.core.annotation.Order;
|
14
|
import org.springframework.stereotype.Component;
|
18
|
import org.springframework.stereotype.Component;
|
|
@@ -18,8 +22,10 @@ import java.util.Map; |
|
@@ -18,8 +22,10 @@ import java.util.Map; |
18
|
|
22
|
|
19
|
@Component
|
23
|
@Component
|
20
|
@Aspect
|
24
|
@Aspect
|
21
|
-@Order(Integer.MIN_VALUE+1)
|
|
|
22
|
-public class ProductListWithSknAspect{
|
25
|
+@Order(Integer.MIN_VALUE + 1)
|
|
|
26
|
+public class ProductListWithSknAspect {
|
|
|
27
|
+
|
|
|
28
|
+ private static final Logger logger = LoggerFactory.getLogger(ProductListWithSknAspect.class);
|
23
|
|
29
|
|
24
|
@Autowired
|
30
|
@Autowired
|
25
|
private SknReturnInfoCacheBean sknReturnInfoCacheBean;
|
31
|
private SknReturnInfoCacheBean sknReturnInfoCacheBean;
|
|
@@ -32,47 +38,61 @@ public class ProductListWithSknAspect{ |
|
@@ -32,47 +38,61 @@ public class ProductListWithSknAspect{ |
32
|
return pjp.proceed();
|
38
|
return pjp.proceed();
|
33
|
}
|
39
|
}
|
34
|
Object result = pjp.proceed();
|
40
|
Object result = pjp.proceed();
|
35
|
- if (result == null){
|
41
|
+ if (result == null) {
|
36
|
return result;
|
42
|
return result;
|
37
|
}
|
43
|
}
|
38
|
- SearchApiResult searchApiResult = (SearchApiResult)result;
|
44
|
+ SearchApiResult searchApiResult = (SearchApiResult) result;
|
39
|
Object data = searchApiResult.getData();
|
45
|
Object data = searchApiResult.getData();
|
40
|
- if(data==null){
|
46
|
+ if (data == null) {
|
41
|
return result;
|
47
|
return result;
|
42
|
}
|
48
|
}
|
43
|
- if(data instanceof ProductListWithSkn){
|
|
|
44
|
- return this.buildSearchApiResultFromProductListWithSkn(searchApiResult,(ProductListWithSkn)data);
|
49
|
+ if (data instanceof ProductListWithSkn) {
|
|
|
50
|
+ return this.buildSearchApiResultFromProductListWithSkn(searchApiResult, (ProductListWithSkn) data);
|
45
|
}
|
51
|
}
|
46
|
- if(data instanceof JSONObject){
|
|
|
47
|
- return this.buildSearchApiResultFromProductListWithSkn(searchApiResult,(JSONObject)data);
|
52
|
+ if (data instanceof JSONObject) {
|
|
|
53
|
+ return this.buildSearchApiResultFromProductListWithSkn(searchApiResult, (JSONObject) data);
|
48
|
}
|
54
|
}
|
49
|
return result;
|
55
|
return result;
|
50
|
}
|
56
|
}
|
51
|
|
57
|
|
52
|
- private SearchApiResult buildSearchApiResultFromProductListWithSkn(SearchApiResult searchApiResult,ProductListWithSkn productListWithSkn ){
|
|
|
53
|
- JSONObject productListResult = new JSONObject();
|
|
|
54
|
- productListResult.put("total",productListWithSkn.getTotal());
|
|
|
55
|
- productListResult.put("page", productListWithSkn.getPage());
|
|
|
56
|
- productListResult.put("page_size", productListWithSkn.getPage_size());
|
|
|
57
|
- productListResult.put("page_total", productListWithSkn.getPage_total());
|
|
|
58
|
- List<Map<String, Object>> productReturnInfoList = sknReturnInfoCacheBean.queryProductListBySkn(productListWithSkn.getSkn_list(),productListWithSkn.getSkn_list().size());
|
|
|
59
|
- productListResult.put("product_list", productReturnInfoList);
|
|
|
60
|
- return searchApiResult.setData(productListResult);
|
58
|
+ private SearchApiResult buildSearchApiResultFromProductListWithSkn(SearchApiResult searchApiResult, ProductListWithSkn productListWithSkn) {
|
|
|
59
|
+ try {
|
|
|
60
|
+ JSONObject productListResult = new JSONObject();
|
|
|
61
|
+ productListResult.put("total", productListWithSkn.getTotal());
|
|
|
62
|
+ productListResult.put("page", productListWithSkn.getPage());
|
|
|
63
|
+ productListResult.put("page_size", productListWithSkn.getPage_size());
|
|
|
64
|
+ productListResult.put("page_total", productListWithSkn.getPage_total());
|
|
|
65
|
+ List<Map<String, Object>> productReturnInfoList = sknReturnInfoCacheBean.queryProductListBySkn(productListWithSkn.getSkn_list(), productListWithSkn.getSkn_list().size());
|
|
|
66
|
+ String recall_type = productListWithSkn.getRecall_type();
|
|
|
67
|
+ for (Map<String, Object> productInfo : productReturnInfoList) {
|
|
|
68
|
+ productInfo.put("recall_type", recall_type);
|
|
|
69
|
+ }
|
|
|
70
|
+ productListResult.put("product_list", productReturnInfoList);
|
|
|
71
|
+ return searchApiResult.setData(productListResult);
|
|
|
72
|
+ }catch (Exception e){
|
|
|
73
|
+ logger.error(e.getMessage(),e);
|
|
|
74
|
+ return SearchApiResultUtils.defaultErrorSearchApiResult(e);
|
|
|
75
|
+ }
|
61
|
}
|
76
|
}
|
62
|
|
77
|
|
63
|
- private SearchApiResult buildSearchApiResultFromProductListWithSkn(SearchApiResult searchApiResult,JSONObject jsonObject){
|
78
|
+ private SearchApiResult buildSearchApiResultFromProductListWithSkn(SearchApiResult searchApiResult, JSONObject jsonObject) {
|
64
|
try {
|
79
|
try {
|
65
|
JSONArray jsonArray = jsonObject.getJSONArray("skn_list");
|
80
|
JSONArray jsonArray = jsonObject.getJSONArray("skn_list");
|
66
|
- if(jsonArray==null){
|
81
|
+ if (jsonArray == null) {
|
67
|
return searchApiResult;
|
82
|
return searchApiResult;
|
68
|
}
|
83
|
}
|
|
|
84
|
+ String recall_type = jsonObject.getString("recall_type");
|
69
|
List<Integer> skn_list = JSONArray.parseArray(jsonArray.toJSONString(), Integer.class);
|
85
|
List<Integer> skn_list = JSONArray.parseArray(jsonArray.toJSONString(), Integer.class);
|
70
|
- List<Map<String, Object>> productReturnInfoList = sknReturnInfoCacheBean.queryProductListBySkn(skn_list,skn_list.size());
|
86
|
+ List<Map<String, Object>> productReturnInfoList = sknReturnInfoCacheBean.queryProductListBySkn(skn_list, skn_list.size());
|
|
|
87
|
+ for (Map<String, Object> productInfo : productReturnInfoList) {
|
|
|
88
|
+ productInfo.put("recall_type", recall_type);
|
|
|
89
|
+ }
|
71
|
jsonObject.put("product_list", productReturnInfoList);
|
90
|
jsonObject.put("product_list", productReturnInfoList);
|
72
|
jsonObject.remove("skn_list");
|
91
|
jsonObject.remove("skn_list");
|
73
|
return searchApiResult.setData(jsonObject);
|
92
|
return searchApiResult.setData(jsonObject);
|
74
|
- }catch (Exception e){
|
|
|
75
|
- return searchApiResult;
|
93
|
+ } catch (Exception e) {
|
|
|
94
|
+ logger.error(e.getMessage(),e);
|
|
|
95
|
+ return SearchApiResultUtils.defaultErrorSearchApiResult(e);
|
76
|
}
|
96
|
}
|
77
|
}
|
97
|
}
|
78
|
|
98
|
|