...
|
...
|
@@ -2,13 +2,17 @@ package com.yoho.search.common.productlist.aop; |
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.yoho.search.common.utils.SearchApiResultUtils;
|
|
|
import com.yoho.search.models.ProductListWithSkn;
|
|
|
import com.yoho.search.models.SearchApiResult;
|
|
|
import com.yoho.search.recall.scene.beans.cache.SknReturnInfoCacheBean;
|
|
|
import com.yoho.search.recall.scene.beans.strategy.StrategyEnum;
|
|
|
import org.aspectj.lang.ProceedingJoinPoint;
|
|
|
import org.aspectj.lang.annotation.Around;
|
|
|
import org.aspectj.lang.annotation.Aspect;
|
|
|
import org.aspectj.lang.reflect.MethodSignature;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.core.annotation.Order;
|
|
|
import org.springframework.stereotype.Component;
|
...
|
...
|
@@ -18,8 +22,10 @@ import java.util.Map; |
|
|
|
|
|
@Component
|
|
|
@Aspect
|
|
|
@Order(Integer.MIN_VALUE+1)
|
|
|
public class ProductListWithSknAspect{
|
|
|
@Order(Integer.MIN_VALUE + 1)
|
|
|
public class ProductListWithSknAspect {
|
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(ProductListWithSknAspect.class);
|
|
|
|
|
|
@Autowired
|
|
|
private SknReturnInfoCacheBean sknReturnInfoCacheBean;
|
...
|
...
|
@@ -32,47 +38,61 @@ public class ProductListWithSknAspect{ |
|
|
return pjp.proceed();
|
|
|
}
|
|
|
Object result = pjp.proceed();
|
|
|
if (result == null){
|
|
|
if (result == null) {
|
|
|
return result;
|
|
|
}
|
|
|
SearchApiResult searchApiResult = (SearchApiResult)result;
|
|
|
SearchApiResult searchApiResult = (SearchApiResult) result;
|
|
|
Object data = searchApiResult.getData();
|
|
|
if(data==null){
|
|
|
if (data == null) {
|
|
|
return result;
|
|
|
}
|
|
|
if(data instanceof ProductListWithSkn){
|
|
|
return this.buildSearchApiResultFromProductListWithSkn(searchApiResult,(ProductListWithSkn)data);
|
|
|
if (data instanceof ProductListWithSkn) {
|
|
|
return this.buildSearchApiResultFromProductListWithSkn(searchApiResult, (ProductListWithSkn) data);
|
|
|
}
|
|
|
if(data instanceof JSONObject){
|
|
|
return this.buildSearchApiResultFromProductListWithSkn(searchApiResult,(JSONObject)data);
|
|
|
if (data instanceof JSONObject) {
|
|
|
return this.buildSearchApiResultFromProductListWithSkn(searchApiResult, (JSONObject) data);
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
private SearchApiResult buildSearchApiResultFromProductListWithSkn(SearchApiResult searchApiResult,ProductListWithSkn productListWithSkn ){
|
|
|
private SearchApiResult buildSearchApiResultFromProductListWithSkn(SearchApiResult searchApiResult, ProductListWithSkn productListWithSkn) {
|
|
|
try {
|
|
|
JSONObject productListResult = new JSONObject();
|
|
|
productListResult.put("total",productListWithSkn.getTotal());
|
|
|
productListResult.put("total", productListWithSkn.getTotal());
|
|
|
productListResult.put("page", productListWithSkn.getPage());
|
|
|
productListResult.put("page_size", productListWithSkn.getPage_size());
|
|
|
productListResult.put("page_total", productListWithSkn.getPage_total());
|
|
|
List<Map<String, Object>> productReturnInfoList = sknReturnInfoCacheBean.queryProductListBySkn(productListWithSkn.getSkn_list(),productListWithSkn.getSkn_list().size());
|
|
|
List<Map<String, Object>> productReturnInfoList = sknReturnInfoCacheBean.queryProductListBySkn(productListWithSkn.getSkn_list(), productListWithSkn.getSkn_list().size());
|
|
|
String recall_type = productListWithSkn.getRecall_type();
|
|
|
for (Map<String, Object> productInfo : productReturnInfoList) {
|
|
|
productInfo.put("recall_type", recall_type);
|
|
|
}
|
|
|
productListResult.put("product_list", productReturnInfoList);
|
|
|
return searchApiResult.setData(productListResult);
|
|
|
}catch (Exception e){
|
|
|
logger.error(e.getMessage(),e);
|
|
|
return SearchApiResultUtils.defaultErrorSearchApiResult(e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private SearchApiResult buildSearchApiResultFromProductListWithSkn(SearchApiResult searchApiResult,JSONObject jsonObject){
|
|
|
private SearchApiResult buildSearchApiResultFromProductListWithSkn(SearchApiResult searchApiResult, JSONObject jsonObject) {
|
|
|
try {
|
|
|
JSONArray jsonArray = jsonObject.getJSONArray("skn_list");
|
|
|
if(jsonArray==null){
|
|
|
if (jsonArray == null) {
|
|
|
return searchApiResult;
|
|
|
}
|
|
|
String recall_type = jsonObject.getString("recall_type");
|
|
|
List<Integer> skn_list = JSONArray.parseArray(jsonArray.toJSONString(), Integer.class);
|
|
|
List<Map<String, Object>> productReturnInfoList = sknReturnInfoCacheBean.queryProductListBySkn(skn_list,skn_list.size());
|
|
|
List<Map<String, Object>> productReturnInfoList = sknReturnInfoCacheBean.queryProductListBySkn(skn_list, skn_list.size());
|
|
|
for (Map<String, Object> productInfo : productReturnInfoList) {
|
|
|
productInfo.put("recall_type", recall_type);
|
|
|
}
|
|
|
jsonObject.put("product_list", productReturnInfoList);
|
|
|
jsonObject.remove("skn_list");
|
|
|
return searchApiResult.setData(jsonObject);
|
|
|
}catch (Exception e){
|
|
|
return searchApiResult;
|
|
|
} catch (Exception e) {
|
|
|
logger.error(e.getMessage(),e);
|
|
|
return SearchApiResultUtils.defaultErrorSearchApiResult(e);
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
|