Authored by mali

展示渠道

@@ -4,6 +4,8 @@ import com.alibaba.fastjson.JSONArray; @@ -4,6 +4,8 @@ import com.alibaba.fastjson.JSONArray;
4 import com.alibaba.fastjson.JSONObject; 4 import com.alibaba.fastjson.JSONObject;
5 import com.google.common.collect.Lists; 5 import com.google.common.collect.Lists;
6 import com.yoho.core.common.utils.DateUtil; 6 import com.yoho.core.common.utils.DateUtil;
  7 +import com.yoho.core.rest.client.ServiceCaller;
  8 +import com.yoho.core.rest.exception.ServiceNotAvaibleException;
7 import com.yohoufo.common.helper.ImageUrlAssist; 9 import com.yohoufo.common.helper.ImageUrlAssist;
8 import com.yohoufo.common.utils.MathUtil; 10 import com.yohoufo.common.utils.MathUtil;
9 import org.apache.commons.collections.MapUtils; 11 import org.apache.commons.collections.MapUtils;
@@ -11,6 +13,7 @@ import org.apache.commons.lang3.StringUtils; @@ -11,6 +13,7 @@ import org.apache.commons.lang3.StringUtils;
11 import org.slf4j.Logger; 13 import org.slf4j.Logger;
12 import org.slf4j.LoggerFactory; 14 import org.slf4j.LoggerFactory;
13 import org.springframework.beans.factory.annotation.Autowired; 15 import org.springframework.beans.factory.annotation.Autowired;
  16 +import org.springframework.beans.factory.annotation.Value;
14 import org.springframework.stereotype.Service; 17 import org.springframework.stereotype.Service;
15 import org.springframework.util.CollectionUtils; 18 import org.springframework.util.CollectionUtils;
16 19
@@ -28,6 +31,48 @@ public class ProductSearchAssistService { @@ -28,6 +31,48 @@ public class ProductSearchAssistService {
28 @Autowired 31 @Autowired
29 ProductSalesService productSalesService; 32 ProductSalesService productSalesService;
30 33
  34 + @Value("${ip.port.search.server}")
  35 + private String searchServerIpAndPort;
  36 +
  37 + @Autowired
  38 + private ServiceCaller serviceCaller;
  39 +
  40 + public JSONObject search(Map<String, Object> searchParams, String url) {
  41 + logger.info("begin invoke search.productList, param is:{}, url is :{}", searchParams, url);
  42 + String resultJsonStr = null;
  43 + try {
  44 + resultJsonStr = serviceCaller.get("search.productList", "http://" + searchServerIpAndPort + url, searchParams, String.class, null).get(1);
  45 + } catch (Exception e) {
  46 + logger.warn("The result of search product list find wrong. url {}: ", url, e);
  47 + throw new ServiceNotAvaibleException("search server!!!", e);
  48 + }
  49 + JSONObject searchResult = null;
  50 + try {
  51 + searchResult = JSONObject.parseObject(resultJsonStr);
  52 + } catch (Exception e) {
  53 + logger.warn("The result of search product list is not string of json. result:{}", resultJsonStr, e);
  54 + return null;
  55 + }
  56 + if (null == searchResult) {
  57 + logger.warn("searchResult is null. params : {} ", searchParams);
  58 + return null;
  59 + }
  60 + // 取出搜索接口真实查询的列表结果
  61 + JSONObject data;
  62 + try {
  63 + data = searchResult.getJSONObject("data");
  64 + } catch (Exception e) {
  65 + logger.warn("The result of search product list is not string of json. searchResult:{}", searchResult, e);
  66 + return null;
  67 + }
  68 +
  69 + if (null == data) {
  70 + logger.info("The data field of search product list is null. params : {} ", searchParams);
  71 + return null;
  72 + }
  73 + return data;
  74 + }
  75 +
31 public Integer getValidTimestamp(String dateStr, boolean start) { 76 public Integer getValidTimestamp(String dateStr, boolean start) {
32 try { 77 try {
33 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM"); 78 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
@@ -62,14 +62,7 @@ public class ProductSearchServiceImpl implements ProductSearchService { @@ -62,14 +62,7 @@ public class ProductSearchServiceImpl implements ProductSearchService {
62 62
63 private static Logger logger = LoggerFactory.getLogger(ProductSearchServiceImpl.class); 63 private static Logger logger = LoggerFactory.getLogger(ProductSearchServiceImpl.class);
64 64
65 - // 如果是NFC分享页面列表,则传1  
66 - private final static Integer REGULARIZE_NFC = 1;  
67 -  
68 - @Value("${ip.port.search.server}")  
69 - private String searchServerIpAndPort;  
70 -  
71 - @Autowired  
72 - private ServiceCaller serviceCaller; 65 + private final static Integer REGULARIZE_NFC = 1; // 如果是NFC分享页面列表,则传1
73 66
74 @Autowired 67 @Autowired
75 private UfoServiceCaller ufoServiceCaller; 68 private UfoServiceCaller ufoServiceCaller;
@@ -89,42 +82,6 @@ public class ProductSearchServiceImpl implements ProductSearchService { @@ -89,42 +82,6 @@ public class ProductSearchServiceImpl implements ProductSearchService {
89 @Autowired 82 @Autowired
90 private ProductSearchAssistService searchAssistService; 83 private ProductSearchAssistService searchAssistService;
91 84
92 - private JSONObject search(Map<String, Object> searchParams, String url) {  
93 - logger.info("begin invoke search.productList, param is:{}, url is :{}", searchParams, url);  
94 - String resultJsonStr = null;  
95 - try {  
96 - resultJsonStr = serviceCaller.get("search.productList", "http://" + searchServerIpAndPort + url, searchParams, String.class, null).get(1);  
97 - } catch (Exception e) {  
98 - logger.warn("The result of search product list find wrong. url {}: ", url, e);  
99 - throw new ServiceNotAvaibleException("search server!!!", e);  
100 - }  
101 - JSONObject searchResult = null;  
102 - try {  
103 - searchResult = JSONObject.parseObject(resultJsonStr);  
104 - } catch (Exception e) {  
105 - logger.warn("The result of search product list is not string of json. result:{}", resultJsonStr, e);  
106 - return null;  
107 - }  
108 - if (null == searchResult) {  
109 - logger.warn("searchResult is null. params : {} ", searchParams);  
110 - return null;  
111 - }  
112 - // 取出搜索接口真实查询的列表结果  
113 - JSONObject data;  
114 - try {  
115 - data = searchResult.getJSONObject("data");  
116 - } catch (Exception e) {  
117 - logger.warn("The result of search product list is not string of json. searchResult:{}", searchResult, e);  
118 - return null;  
119 - }  
120 -  
121 - if (null == data) {  
122 - logger.info("The data field of search product list is null. params : {} ", searchParams);  
123 - return null;  
124 - }  
125 - return data;  
126 - }  
127 -  
128 @Override 85 @Override
129 public JSONObject searchProductList(ProductSearchReq req) { 86 public JSONObject searchProductList(ProductSearchReq req) {
130 SearchParam searchParam = new SearchParam().buildPageSearchParam(req); 87 SearchParam searchParam = new SearchParam().buildPageSearchParam(req);
@@ -166,7 +123,7 @@ public class ProductSearchServiceImpl implements ProductSearchService { @@ -166,7 +123,7 @@ public class ProductSearchServiceImpl implements ProductSearchService {
166 searchParam.setShowChannel(req.getBusinessClient()); 123 searchParam.setShowChannel(req.getBusinessClient());
167 url = ProductSearchConstants.PRODUCT_POOL_URL; 124 url = ProductSearchConstants.PRODUCT_POOL_URL;
168 } 125 }
169 - JSONObject data = search(searchParam.getParam(), url); 126 + JSONObject data = searchAssistService.search(searchParam.getParam(), url);
170 // 将图片的相对路径转成绝对路径 127 // 将图片的相对路径转成绝对路径
171 if (null != data) { 128 if (null != data) {
172 searchAssistService.processProductList(data.getJSONArray("product_list")); 129 searchAssistService.processProductList(data.getJSONArray("product_list"));
@@ -181,7 +138,7 @@ public class ProductSearchServiceImpl implements ProductSearchService { @@ -181,7 +138,7 @@ public class ProductSearchServiceImpl implements ProductSearchService {
181 req.setNotBrand(StringUtils.join(brandMapper.selectExcludeAppraise(), ",")); 138 req.setNotBrand(StringUtils.join(brandMapper.selectExcludeAppraise(), ","));
182 SearchParam searchParam = new SearchParam().buildPageSearchParam(req); 139 SearchParam searchParam = new SearchParam().buildPageSearchParam(req);
183 String url = ProductSearchConstants.PRODUCT_SEARCH_QUERY_URL; 140 String url = ProductSearchConstants.PRODUCT_SEARCH_QUERY_URL;
184 - JSONObject data = search(searchParam.getParam(), url); 141 + JSONObject data = searchAssistService.search(searchParam.getParam(), url);
185 // 将图片的相对路径转成绝对路径 142 // 将图片的相对路径转成绝对路径
186 if (null != data) { 143 if (null != data) {
187 searchAssistService.processProductList(data.getJSONArray("product_list")); 144 searchAssistService.processProductList(data.getJSONArray("product_list"));
@@ -194,7 +151,7 @@ public class ProductSearchServiceImpl implements ProductSearchService { @@ -194,7 +151,7 @@ public class ProductSearchServiceImpl implements ProductSearchService {
194 @Override 151 @Override
195 public JSONObject searchSuggest(ProductSearchReq req) { 152 public JSONObject searchSuggest(ProductSearchReq req) {
196 SearchParam searchParam = new SearchParam().buildPageSearchParam(req); 153 SearchParam searchParam = new SearchParam().buildPageSearchParam(req);
197 - JSONObject data = search(searchParam.getParam(), ProductSearchConstants.SUGGEST_URL); 154 + JSONObject data = searchAssistService.search(searchParam.getParam(), ProductSearchConstants.SUGGEST_URL);
198 return data; 155 return data;
199 } 156 }
200 157
@@ -255,7 +212,7 @@ public class ProductSearchServiceImpl implements ProductSearchService { @@ -255,7 +212,7 @@ public class ProductSearchServiceImpl implements ProductSearchService {
255 /*if (req.getMaxSort() == null && req.getMidSort() == null) { 212 /*if (req.getMaxSort() == null && req.getMidSort() == null) {
256 searchParam.setXianYuSort(req.getBusinessClient(), configReader); 213 searchParam.setXianYuSort(req.getBusinessClient(), configReader);
257 }*/ 214 }*/
258 - JSONObject data = search(searchParam.getParam(), ProductSearchConstants.FILTER_LIST_URL); 215 + JSONObject data = searchAssistService.search(searchParam.getParam(), ProductSearchConstants.FILTER_LIST_URL);
259 SearchProductListFilterResp resp = new SearchProductListFilterResp(); 216 SearchProductListFilterResp resp = new SearchProductListFilterResp();
260 if (data != null) { 217 if (data != null) {
261 JSONObject filterData = data.getJSONObject("filter"); 218 JSONObject filterData = data.getJSONObject("filter");
@@ -357,7 +314,7 @@ public class ProductSearchServiceImpl implements ProductSearchService { @@ -357,7 +314,7 @@ public class ProductSearchServiceImpl implements ProductSearchService {
357 SearchParam searchParam = new SearchParam().setShowChannel(businessClient); 314 SearchParam searchParam = new SearchParam().setShowChannel(businessClient);
358 //searchParam.setXianYuSort(businessClient, configReader); //闲鱼改成全品类 如果是闲鱼请求,则设置大品类 315 //searchParam.setXianYuSort(businessClient, configReader); //闲鱼改成全品类 如果是闲鱼请求,则设置大品类
359 316
360 - JSONObject data = search(searchParam.getParam(), ProductSearchConstants.BRAND_LIST_URL); 317 + JSONObject data = searchAssistService.search(searchParam.getParam(), ProductSearchConstants.BRAND_LIST_URL);
361 if(data != null && !CollectionUtils.isEmpty(data.getJSONArray("brand_list"))) { 318 if(data != null && !CollectionUtils.isEmpty(data.getJSONArray("brand_list"))) {
362 resp = JSON.toJavaObject(data, SearchBrandListResp.class); 319 resp = JSON.toJavaObject(data, SearchBrandListResp.class);
363 320
@@ -379,7 +336,7 @@ public class ProductSearchServiceImpl implements ProductSearchService { @@ -379,7 +336,7 @@ public class ProductSearchServiceImpl implements ProductSearchService {
379 ProductSearchReq req = new ProductSearchReq().setNot_id(productId + "").setMidSort(product.getMidSortId() + "").setBrand(product.getBrandId() + "").setQuery(product.getProductName()); 336 ProductSearchReq req = new ProductSearchReq().setNot_id(productId + "").setMidSort(product.getMidSortId() + "").setBrand(product.getBrandId() + "").setQuery(product.getProductName());
380 SearchParam searchParam = new SearchParam().buildSearchParam(req); 337 SearchParam searchParam = new SearchParam().buildSearchParam(req);
381 338
382 - JSONObject data = search(searchParam.getParam(), ProductSearchConstants.PRODUCT_RECOMMEND_LIST_URL); 339 + JSONObject data = searchAssistService.search(searchParam.getParam(), ProductSearchConstants.PRODUCT_RECOMMEND_LIST_URL);
383 if(data != null && !CollectionUtils.isEmpty(data.getJSONArray("product_list"))) { 340 if(data != null && !CollectionUtils.isEmpty(data.getJSONArray("product_list"))) {
384 searchAssistService.processProductSales(data.getJSONArray("product_list")); 341 searchAssistService.processProductSales(data.getJSONArray("product_list"));
385 resp = JSON.toJavaObject(data, SearchProductRecommendResp.class); 342 resp = JSON.toJavaObject(data, SearchProductRecommendResp.class);
@@ -421,7 +378,7 @@ public class ProductSearchServiceImpl implements ProductSearchService { @@ -421,7 +378,7 @@ public class ProductSearchServiceImpl implements ProductSearchService {
421 public List<ProductBrandSeriesResp> searchSeriesList() { 378 public List<ProductBrandSeriesResp> searchSeriesList() {
422 List<ProductBrandSeriesResp> respList = new ArrayList<>(); 379 List<ProductBrandSeriesResp> respList = new ArrayList<>();
423 SearchParam searchParam = new SearchParam(); 380 SearchParam searchParam = new SearchParam();
424 - JSONObject data = search(searchParam.getParam(), ProductSearchConstants.SERIES_LIST_URL); 381 + JSONObject data = searchAssistService.search(searchParam.getParam(), ProductSearchConstants.SERIES_LIST_URL);
425 JSONArray series; 382 JSONArray series;
426 if (data != null && !CollectionUtils.isEmpty(series = data.getJSONArray("series_list"))) { 383 if (data != null && !CollectionUtils.isEmpty(series = data.getJSONArray("series_list"))) {
427 for (int i = 0; i < series.size(); i++) { 384 for (int i = 0; i < series.size(); i++) {
@@ -467,7 +424,7 @@ public class ProductSearchServiceImpl implements ProductSearchService { @@ -467,7 +424,7 @@ public class ProductSearchServiceImpl implements ProductSearchService {
467 type = ""; 424 type = "";
468 } 425 }
469 searchParam.setType(type); 426 searchParam.setType(type);
470 - countMap = search(searchParam.getParam(), url).getJSONObject("sale_date_count_list"); 427 + countMap = searchAssistService.search(searchParam.getParam(), url).getJSONObject("sale_date_count_list");
471 } catch (Exception e) { 428 } catch (Exception e) {
472 logger.error("调用销售日历汇总数据出错: " + e.getMessage(), e); 429 logger.error("调用销售日历汇总数据出错: " + e.getMessage(), e);
473 } 430 }
@@ -502,7 +459,7 @@ public class ProductSearchServiceImpl implements ProductSearchService { @@ -502,7 +459,7 @@ public class ProductSearchServiceImpl implements ProductSearchService {
502 ProductSearchReq req = new ProductSearchReq(); 459 ProductSearchReq req = new ProductSearchReq();
503 req.setStartTime(startTime).setEndTime(endTime); 460 req.setStartTime(startTime).setEndTime(endTime);
504 SearchParam searchParam = new SearchParam().buildPageSearchParam(req); 461 SearchParam searchParam = new SearchParam().buildPageSearchParam(req);
505 - JSONObject data = search(searchParam.getParam(), ProductSearchConstants.SALE_CALENDAR_LIST_URL); 462 + JSONObject data = searchAssistService.search(searchParam.getParam(), ProductSearchConstants.SALE_CALENDAR_LIST_URL);
506 // 将图片的相对路径转成绝对路径 463 // 将图片的相对路径转成绝对路径
507 if (null != data) { 464 if (null != data) {
508 searchAssistService.processProductList(data.getJSONArray("product_list")); 465 searchAssistService.processProductList(data.getJSONArray("product_list"));
@@ -520,7 +477,7 @@ public class ProductSearchServiceImpl implements ProductSearchService { @@ -520,7 +477,7 @@ public class ProductSearchServiceImpl implements ProductSearchService {
520 type = ""; 477 type = "";
521 } 478 }
522 searchParam.setType(type); 479 searchParam.setType(type);
523 - JSONObject data = search(searchParam.getParam(), ProductSearchConstants.NEW_SALE_CALENDAR_LIST_URL); 480 + JSONObject data = searchAssistService.search(searchParam.getParam(), ProductSearchConstants.NEW_SALE_CALENDAR_LIST_URL);
524 // 将图片的相对路径转成绝对路径 481 // 将图片的相对路径转成绝对路径
525 if (null != data) { 482 if (null != data) {
526 searchAssistService.processProductList(data.getJSONArray("product_list")); 483 searchAssistService.processProductList(data.getJSONArray("product_list"));
@@ -532,7 +489,7 @@ public class ProductSearchServiceImpl implements ProductSearchService { @@ -532,7 +489,7 @@ public class ProductSearchServiceImpl implements ProductSearchService {
532 public JSONObject searchHotSale(Integer page, Integer limit, String businessClient) { 489 public JSONObject searchHotSale(Integer page, Integer limit, String businessClient) {
533 ProductSearchReq req = new ProductSearchReq().setViewNum(limit).setPage(page); 490 ProductSearchReq req = new ProductSearchReq().setViewNum(limit).setPage(page);
534 SearchParam searchParam = new SearchParam().buildPageSearchParam(req).setShowChannel(businessClient); 491 SearchParam searchParam = new SearchParam().buildPageSearchParam(req).setShowChannel(businessClient);
535 - JSONObject data = search(searchParam.getParam(), ProductSearchConstants.HOT_SALE_LIST_URL); 492 + JSONObject data = searchAssistService.search(searchParam.getParam(), ProductSearchConstants.HOT_SALE_LIST_URL);
536 // 将图片的相对路径转成绝对路径 493 // 将图片的相对路径转成绝对路径
537 if (null != data) { 494 if (null != data) {
538 searchAssistService.processProductList(data.getJSONArray("product_list")); 495 searchAssistService.processProductList(data.getJSONArray("product_list"));
@@ -548,7 +505,7 @@ public class ProductSearchServiceImpl implements ProductSearchService { @@ -548,7 +505,7 @@ public class ProductSearchServiceImpl implements ProductSearchService {
548 } 505 }
549 SearchParam searchParam = new SearchParam().buildPageSearchParam(req).setShowChannel(req.getBusinessClient()); 506 SearchParam searchParam = new SearchParam().buildPageSearchParam(req).setShowChannel(req.getBusinessClient());
550 String url = ProductSearchConstants.PRODUCT_UVSCORE_LIST_URL; 507 String url = ProductSearchConstants.PRODUCT_UVSCORE_LIST_URL;
551 - JSONObject data = search(searchParam.getParam(), url); 508 + JSONObject data = searchAssistService.search(searchParam.getParam(), url);
552 // 将图片的相对路径转成绝对路径 509 // 将图片的相对路径转成绝对路径
553 if (null != data) { 510 if (null != data) {
554 searchAssistService.processProductList(data.getJSONArray("product_list")); 511 searchAssistService.processProductList(data.getJSONArray("product_list"));
@@ -576,7 +533,7 @@ public class ProductSearchServiceImpl implements ProductSearchService { @@ -576,7 +533,7 @@ public class ProductSearchServiceImpl implements ProductSearchService {
576 } 533 }
577 SearchParam searchParam = new SearchParam().buildSearchParam(req).setShowChannel(businessClient); 534 SearchParam searchParam = new SearchParam().buildSearchParam(req).setShowChannel(businessClient);
578 535
579 - JSONObject data = search(searchParam.getParam(), ProductSearchConstants.PRODUCT_RECOMMEND_BY_SERIESBRAND_LIST_URL); 536 + JSONObject data = searchAssistService.search(searchParam.getParam(), ProductSearchConstants.PRODUCT_RECOMMEND_BY_SERIESBRAND_LIST_URL);
580 if(data != null && !CollectionUtils.isEmpty(data.getJSONArray("product_list"))) { 537 if(data != null && !CollectionUtils.isEmpty(data.getJSONArray("product_list"))) {
581 searchAssistService.processProductSales(data.getJSONArray("product_list")); 538 searchAssistService.processProductSales(data.getJSONArray("product_list"));
582 resp = JSON.toJavaObject(data, SearchProductRecommendResp.class); 539 resp = JSON.toJavaObject(data, SearchProductRecommendResp.class);
@@ -596,7 +553,7 @@ public class ProductSearchServiceImpl implements ProductSearchService { @@ -596,7 +553,7 @@ public class ProductSearchServiceImpl implements ProductSearchService {
596 public JSONObject searchSecondhandSkupList(ProductSearchReq req) { 553 public JSONObject searchSecondhandSkupList(ProductSearchReq req) {
597 SearchParam searchParam = new SearchParam().buildPageSearchParam(req).setShowChannel(req.getBusinessClient()); 554 SearchParam searchParam = new SearchParam().buildPageSearchParam(req).setShowChannel(req.getBusinessClient());
598 String url = ProductSearchConstants.SECONDHAND_SKUP_QUERY_URL; 555 String url = ProductSearchConstants.SECONDHAND_SKUP_QUERY_URL;
599 - JSONObject data = search(searchParam.getParam(), url); 556 + JSONObject data = searchAssistService.search(searchParam.getParam(), url);
600 // 将图片的相对路径转成绝对路径 557 // 将图片的相对路径转成绝对路径
601 if (null != data) { 558 if (null != data) {
602 searchAssistService.processSecondhandSkupList(data.getJSONArray("skup_list")); 559 searchAssistService.processSecondhandSkupList(data.getJSONArray("skup_list"));