...
|
...
|
@@ -10,6 +10,13 @@ import java.util.List; |
|
|
import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import com.yoho.core.config.ConfigReader;
|
|
|
import com.yohobuy.ufo.model.promotion.response.CouponInfo;
|
|
|
import com.yohoufo.common.ApiResponse;
|
|
|
import com.yohoufo.common.constant.BusinessClientEnum;
|
|
|
import com.yohoufo.common.utils.MathUtil;
|
|
|
import com.yohoufo.dal.product.BrandMapper;
|
|
|
import com.yohoufo.product.constants.ProductSearchConstants;
|
|
|
import org.apache.commons.collections.MapUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
...
|
...
|
@@ -55,15 +62,8 @@ public class ProductSearchServiceImpl implements ProductSearchService { |
|
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(ProductSearchServiceImpl.class);
|
|
|
|
|
|
// 如果是NFC分享页面列表,则传1
|
|
|
private final static Integer REGULARIZE_NFC = 1;
|
|
|
private final static Integer REGULARIZE_NFC = 1; // 如果是NFC分享页面列表,则传1
|
|
|
|
|
|
@Value("${ip.port.search.server}")
|
|
|
private String searchServerIpAndPort;
|
|
|
|
|
|
@Autowired
|
|
|
private ServiceCaller serviceCaller;
|
|
|
|
|
|
@Autowired
|
|
|
private UfoServiceCaller ufoServiceCaller;
|
|
|
|
...
|
...
|
@@ -74,86 +74,13 @@ public class ProductSearchServiceImpl implements ProductSearchService { |
|
|
private BrandMapper brandMapper;
|
|
|
|
|
|
@Autowired
|
|
|
ProductSalesService productSalesService;
|
|
|
|
|
|
@Autowired
|
|
|
private ProductMapper productMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private ConfigReader configReader;
|
|
|
|
|
|
@Autowired
|
|
|
private ProductHelpService productHelpService;
|
|
|
|
|
|
|
|
|
public static final String PRODUCT_LIST_URL = "/yohosearch/ufo/productList.json";
|
|
|
|
|
|
|
|
|
public static final String FILTER_LIST_URL = "/yohosearch/ufo/selectionList.json";
|
|
|
|
|
|
|
|
|
public static final String BRAND_LIST_URL = "/yohosearch/ufo/brandList.json";
|
|
|
|
|
|
public static final String SERIES_LIST_URL = "/yohosearch/ufo/seriesList.json";
|
|
|
public static final String SOON_SALE_PRODUCT_LIST_URL = "/yohosearch/ufo/soonSaleProductList.json";
|
|
|
public static final String FAVORITE_PRODUCT_LIST_URL = "/yohosearch/ufo/favoriteProductList.json";
|
|
|
|
|
|
|
|
|
public static final String PRODUCT_RECOMMEND_LIST_URL = "/yohosearch/ufo/recommendList.json";
|
|
|
|
|
|
|
|
|
public static final String SALE_CALENDAR_LIST_URL = "/yohosearch/ufo/saleCalendarProductList.json";
|
|
|
public static final String SALE_CALENDAR_COUNT_URL = "/yohosearch/ufo/SaleDateCountList.json";
|
|
|
|
|
|
public static final String NEW_SALE_CALENDAR_LIST_URL = "/yohosearch/ufo/saleCalendarNewProductList.json";
|
|
|
public static final String NEW_SALE_CALENDAR_COUNT_URL = "/yohosearch/ufo/saleDateNewCountList.json";
|
|
|
|
|
|
public static final String HOT_SALE_LIST_URL = "/yohosearch/ufo/hotSaleProductList.json";
|
|
|
|
|
|
public static final String PRODUCT_POOL_URL = "/yohosearch/ufo/pool/productList.json";
|
|
|
public static final String PRODUCT_SEARCH_QUERY_URL = "/yohosearch/ufo/fuzzy/productList.json";
|
|
|
public static final String PRODUCT_UVSCORE_LIST_URL = "/yohosearch/ufo/uvscore/productList.json";
|
|
|
public static final String SUGGEST_URL = "/yohosearch/ufo/suggest.json";
|
|
|
|
|
|
public static final String PRODUCT_RECOMMEND_BY_SERIESBRAND_LIST_URL = "/yohosearch/ufo/recommendBySeriesBrandList.json";
|
|
|
|
|
|
public static final String SECONDHAND_SKUP_QUERY_URL = "/yohosearch/ufo/secondHand/skupList.json";
|
|
|
|
|
|
private JSONObject search(Map<String, Object> searchParams, String url) {
|
|
|
logger.info("begin invoke search.productList, param is:{}, url is :{}", searchParams, url);
|
|
|
String resultJsonStr = null;
|
|
|
try {
|
|
|
resultJsonStr = serviceCaller.get("search.productList", "http://" + searchServerIpAndPort + url, searchParams, String.class, null).get(1);
|
|
|
} catch (Exception e) {
|
|
|
logger.warn("The result of search product list find wrong. url {}: ", url, e);
|
|
|
throw new ServiceNotAvaibleException("search server!!!", e);
|
|
|
}
|
|
|
JSONObject searchResult = null;
|
|
|
try {
|
|
|
searchResult = JSONObject.parseObject(resultJsonStr);
|
|
|
} catch (Exception e) {
|
|
|
logger.warn("The result of search product list is not string of json. result:{}", resultJsonStr, e);
|
|
|
return null;
|
|
|
}
|
|
|
if (null == searchResult) {
|
|
|
logger.warn("searchResult is null. params : {} ", searchParams);
|
|
|
return null;
|
|
|
}
|
|
|
// 取出搜索接口真实查询的列表结果
|
|
|
JSONObject data;
|
|
|
try {
|
|
|
data = searchResult.getJSONObject("data");
|
|
|
} catch (Exception e) {
|
|
|
logger.warn("The result of search product list is not string of json. searchResult:{}", searchResult, e);
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
if (null == data) {
|
|
|
logger.info("The data field of search product list is null. params : {} ", searchParams);
|
|
|
return null;
|
|
|
}
|
|
|
return data;
|
|
|
}
|
|
|
@Autowired
|
|
|
private ProductSearchAssistService searchAssistService;
|
|
|
|
|
|
@Override
|
|
|
public JSONObject searchProductList(ProductSearchReq req) {
|
...
|
...
|
@@ -166,9 +93,9 @@ public class ProductSearchServiceImpl implements ProductSearchService { |
|
|
// 3,品类; 4,品牌;5,系列;
|
|
|
// 6,搜索
|
|
|
// 7, 收藏 *
|
|
|
String url = PRODUCT_LIST_URL;
|
|
|
String url = ProductSearchConstants.PRODUCT_LIST_URL;
|
|
|
if (req.getSearchType() != null && req.getSearchType() == 8) {
|
|
|
url = PRODUCT_SEARCH_QUERY_URL;
|
|
|
url = ProductSearchConstants.PRODUCT_SEARCH_QUERY_URL;
|
|
|
CouponInfo info = getCouponInfo(req.getCouponToken());
|
|
|
if (info == null) {
|
|
|
JSONObject jo = new JSONObject();
|
...
|
...
|
@@ -181,23 +108,26 @@ public class ProductSearchServiceImpl implements ProductSearchService { |
|
|
req.setId(info.getContainsProductIds());
|
|
|
req.setNot_id(info.getExcludeProductIds());
|
|
|
logger.info("contains {} ex {}",info.getContainsProductIds(), info.getExcludeProductIds());
|
|
|
searchParam = new SearchParam().buildPageSearchParam(req);
|
|
|
searchParam = new SearchParam().buildPageSearchParam(req).setShowChannel(req.getBusinessClient());
|
|
|
} else if (StringUtils.equals("Y", req.getIsSoonSale())) {
|
|
|
url = SOON_SALE_PRODUCT_LIST_URL;
|
|
|
url = ProductSearchConstants.SOON_SALE_PRODUCT_LIST_URL;
|
|
|
} else if (StringUtils.equals("Y", req.getIsIdFilter())) {
|
|
|
url = FAVORITE_PRODUCT_LIST_URL;
|
|
|
url = ProductSearchConstants.FAVORITE_PRODUCT_LIST_URL;
|
|
|
} else if (StringUtils.isNotBlank(req.getQuery())
|
|
|
|| (req.getSearchType() != null && req.getSearchType() == 6)) {
|
|
|
url = PRODUCT_SEARCH_QUERY_URL;
|
|
|
|
|
|
searchParam.setShowChannel(req.getBusinessClient());
|
|
|
url = ProductSearchConstants.PRODUCT_SEARCH_QUERY_URL;
|
|
|
} else if (StringUtils.isNotBlank(req.getPool())
|
|
|
|| (req.getSearchType() != null && (req.getSearchType() == 0 || req.getSearchType() == 1))) {
|
|
|
url = PRODUCT_POOL_URL;
|
|
|
searchParam.setShowChannel(req.getBusinessClient());
|
|
|
url = ProductSearchConstants.PRODUCT_POOL_URL;
|
|
|
}
|
|
|
JSONObject data = search(searchParam.getParam(), url);
|
|
|
JSONObject data = searchAssistService.search(searchParam.getParam(), url);
|
|
|
// 将图片的相对路径转成绝对路径
|
|
|
if (null != data) {
|
|
|
processProductList(data.getJSONArray("product_list"));
|
|
|
processProductSales(data.getJSONArray("product_list"));
|
|
|
searchAssistService.processProductList(data.getJSONArray("product_list"));
|
|
|
searchAssistService.processProductSales(data.getJSONArray("product_list"));
|
|
|
}
|
|
|
|
|
|
return data;
|
...
|
...
|
@@ -207,12 +137,12 @@ public class ProductSearchServiceImpl implements ProductSearchService { |
|
|
public JSONObject searchAppraiseProductList(ProductSearchReq req) {
|
|
|
req.setNotBrand(StringUtils.join(brandMapper.selectExcludeAppraise(), ","));
|
|
|
SearchParam searchParam = new SearchParam().buildPageSearchParam(req);
|
|
|
String url = PRODUCT_SEARCH_QUERY_URL;
|
|
|
JSONObject data = search(searchParam.getParam(), url);
|
|
|
String url = ProductSearchConstants.PRODUCT_SEARCH_QUERY_URL;
|
|
|
JSONObject data = searchAssistService.search(searchParam.getParam(), url);
|
|
|
// 将图片的相对路径转成绝对路径
|
|
|
if (null != data) {
|
|
|
processProductList(data.getJSONArray("product_list"));
|
|
|
processProductSales(data.getJSONArray("product_list"));
|
|
|
searchAssistService.processProductList(data.getJSONArray("product_list"));
|
|
|
searchAssistService.processProductSales(data.getJSONArray("product_list"));
|
|
|
}
|
|
|
|
|
|
return data;
|
...
|
...
|
@@ -221,88 +151,12 @@ public class ProductSearchServiceImpl implements ProductSearchService { |
|
|
@Override
|
|
|
public JSONObject searchSuggest(ProductSearchReq req) {
|
|
|
SearchParam searchParam = new SearchParam().buildPageSearchParam(req);
|
|
|
JSONObject data = search(searchParam.getParam(), SUGGEST_URL);
|
|
|
JSONObject data = searchAssistService.search(searchParam.getParam(), ProductSearchConstants.SUGGEST_URL);
|
|
|
return data;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 对商品列表的信息进行修改,商品图片地址URL补全
|
|
|
*
|
|
|
*/
|
|
|
protected void processProductList(JSONArray productList) {
|
|
|
if(CollectionUtils.isEmpty(productList)){
|
|
|
return;
|
|
|
}
|
|
|
// 遍历商品列表
|
|
|
for (int i = 0; i < productList.size(); i++) {
|
|
|
JSONObject product = productList.getJSONObject(i);
|
|
|
if(null == product){
|
|
|
continue;
|
|
|
}
|
|
|
// 处理图片,封面图设置
|
|
|
String default_images = fillProductImgUrl(MapUtils.getString(product, "default_images", ""));
|
|
|
product.replace("default_images", default_images);
|
|
|
//处理有货价格
|
|
|
if (StringUtils.equals(product.getString("is_yoho"), "Y")) {
|
|
|
handlerPrice(product);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 对二手商品列表的信息进行修改,商品图片地址URL补全
|
|
|
*
|
|
|
*/
|
|
|
protected void processSecondhandSkupList(JSONArray skupList) {
|
|
|
if(CollectionUtils.isEmpty(skupList)){
|
|
|
return;
|
|
|
}
|
|
|
// 遍历商品列表
|
|
|
for (int i = 0; i < skupList.size(); i++) {
|
|
|
JSONObject product = skupList.getJSONObject(i);
|
|
|
if(null == product){
|
|
|
continue;
|
|
|
}
|
|
|
// 处理图片,封面图设置
|
|
|
String secondhand_image = fillProductImgUrl(MapUtils.getString(product, "secondhand_image", ""));
|
|
|
product.replace("secondhand_image", secondhand_image);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
System.out.println(fillProductImgUrl("https://img12.static.yhbimg.com/goodsimg/2019/04/17/17/021560b1bd437ded9a66dd15c29c81c53d.jpg"));
|
|
|
}
|
|
|
|
|
|
protected void processProductSales(JSONArray productList) {
|
|
|
if(CollectionUtils.isEmpty(productList)){
|
|
|
return;
|
|
|
}
|
|
|
List<Integer> productIdList = new ArrayList<>();
|
|
|
// 遍历商品列表
|
|
|
for (int i = 0; i < productList.size(); i++) {
|
|
|
JSONObject product = productList.getJSONObject(i);
|
|
|
if(null == product){
|
|
|
continue;
|
|
|
}
|
|
|
productIdList.add(product.getInteger("id"));
|
|
|
}
|
|
|
|
|
|
Map<Integer, Integer> salesMap = productSalesService.selectAmountByProductIdList(productIdList);
|
|
|
|
|
|
// 遍历商品列表
|
|
|
for (int i = 0; i < productList.size(); i++) {
|
|
|
JSONObject product = productList.getJSONObject(i);
|
|
|
if (null == product) {
|
|
|
continue;
|
|
|
}
|
|
|
Integer amount = salesMap.get(product.getInteger("id"));
|
|
|
if (null == amount) {
|
|
|
continue;
|
|
|
}
|
|
|
product.put("sales", amount);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
@Override
|
|
|
public void processUserFavoriteProductList(JSONObject productJSON, Integer uid) {
|
...
|
...
|
@@ -344,19 +198,6 @@ public class ProductSearchServiceImpl implements ProductSearchService { |
|
|
}
|
|
|
}
|
|
|
|
|
|
private static String fillProductImgUrl(String imgUrl) {
|
|
|
if (StringUtils.isBlank(imgUrl)) {
|
|
|
return imgUrl;
|
|
|
}
|
|
|
if (imgUrl.startsWith("http://")) {
|
|
|
return imgUrl;
|
|
|
}
|
|
|
if (imgUrl.startsWith("https://")) {
|
|
|
return imgUrl;
|
|
|
}
|
|
|
return ImageUrlAssist.getAllProductPicUrl(imgUrl, "goodsimg", "center", "d2hpdGU=");
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public SearchProductListFilterResp searchProductListFilter(ProductSearchReq req) {
|
|
|
if (StringUtils.isNotBlank(req.getCouponToken())) {
|
...
|
...
|
@@ -367,11 +208,11 @@ public class ProductSearchServiceImpl implements ProductSearchService { |
|
|
req.setId(info.getContainsProductIds());
|
|
|
req.setNot_id(info.getExcludeProductIds());
|
|
|
}
|
|
|
SearchParam searchParam = new SearchParam().buildSearchParam(req);
|
|
|
SearchParam searchParam = new SearchParam().buildSearchParam(req).setShowChannel(req.getBusinessClient());;
|
|
|
/*if (req.getMaxSort() == null && req.getMidSort() == null) {
|
|
|
searchParam.setXianYuSort(req.getBusinessClient(), configReader);
|
|
|
}*/
|
|
|
JSONObject data = search(searchParam.getParam(), FILTER_LIST_URL);
|
|
|
JSONObject data = searchAssistService.search(searchParam.getParam(), ProductSearchConstants.FILTER_LIST_URL);
|
|
|
SearchProductListFilterResp resp = new SearchProductListFilterResp();
|
|
|
if (data != null) {
|
|
|
JSONObject filterData = data.getJSONObject("filter");
|
...
|
...
|
@@ -470,10 +311,10 @@ public class ProductSearchServiceImpl implements ProductSearchService { |
|
|
@Override
|
|
|
public SearchBrandListResp searchBrandList(String businessClient) {
|
|
|
SearchBrandListResp resp = new SearchBrandListResp();
|
|
|
SearchParam searchParam = new SearchParam();
|
|
|
SearchParam searchParam = new SearchParam().setShowChannel(businessClient);
|
|
|
//searchParam.setXianYuSort(businessClient, configReader); //闲鱼改成全品类 如果是闲鱼请求,则设置大品类
|
|
|
|
|
|
JSONObject data = search(searchParam.getParam(), BRAND_LIST_URL);
|
|
|
JSONObject data = searchAssistService.search(searchParam.getParam(), ProductSearchConstants.BRAND_LIST_URL);
|
|
|
if(data != null && !CollectionUtils.isEmpty(data.getJSONArray("brand_list"))) {
|
|
|
resp = JSON.toJavaObject(data, SearchBrandListResp.class);
|
|
|
|
...
|
...
|
@@ -488,16 +329,16 @@ public class ProductSearchServiceImpl implements ProductSearchService { |
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public SearchProductRecommendResp searchProductRecommendById(Integer productId) {
|
|
|
public SearchProductRecommendResp searchProductRecommendById(Integer productId, String businessClient) {
|
|
|
SearchProductRecommendResp resp = new SearchProductRecommendResp();
|
|
|
Product product = productMapper.selectByPrimaryKey(productId);
|
|
|
Product product = productHelpService.selectByIdCache(productId);
|
|
|
if (product != null) {
|
|
|
ProductSearchReq req = new ProductSearchReq().setNot_id(productId + "").setMidSort(product.getMidSortId() + "").setBrand(product.getBrandId() + "").setQuery(product.getProductName());
|
|
|
SearchParam searchParam = new SearchParam().buildSearchParam(req);
|
|
|
|
|
|
JSONObject data = search(searchParam.getParam(), PRODUCT_RECOMMEND_LIST_URL);
|
|
|
JSONObject data = searchAssistService.search(searchParam.getParam(), ProductSearchConstants.PRODUCT_RECOMMEND_LIST_URL);
|
|
|
if(data != null && !CollectionUtils.isEmpty(data.getJSONArray("product_list"))) {
|
|
|
processProductSales(data.getJSONArray("product_list"));
|
|
|
searchAssistService.processProductSales(data.getJSONArray("product_list"));
|
|
|
resp = JSON.toJavaObject(data, SearchProductRecommendResp.class);
|
|
|
|
|
|
// 对品牌的log 进行相对路径转绝对路径
|
...
|
...
|
@@ -537,7 +378,7 @@ public class ProductSearchServiceImpl implements ProductSearchService { |
|
|
public List<ProductBrandSeriesResp> searchSeriesList() {
|
|
|
List<ProductBrandSeriesResp> respList = new ArrayList<>();
|
|
|
SearchParam searchParam = new SearchParam();
|
|
|
JSONObject data = search(searchParam.getParam(), SERIES_LIST_URL);
|
|
|
JSONObject data = searchAssistService.search(searchParam.getParam(), ProductSearchConstants.SERIES_LIST_URL);
|
|
|
JSONArray series;
|
|
|
if (data != null && !CollectionUtils.isEmpty(series = data.getJSONArray("series_list"))) {
|
|
|
for (int i = 0; i < series.size(); i++) {
|
...
|
...
|
@@ -566,12 +407,12 @@ public class ProductSearchServiceImpl implements ProductSearchService { |
|
|
|
|
|
@Override
|
|
|
public JSONObject getSaleCalendarCountData() {
|
|
|
return getSaleCalendarCountData(SALE_CALENDAR_COUNT_URL, null);
|
|
|
return getSaleCalendarCountData(ProductSearchConstants.SALE_CALENDAR_COUNT_URL, null);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public JSONObject getNewSaleCalendarCountData(String type) {
|
|
|
return getSaleCalendarCountData(NEW_SALE_CALENDAR_COUNT_URL, type);
|
|
|
return getSaleCalendarCountData(ProductSearchConstants.NEW_SALE_CALENDAR_COUNT_URL, type);
|
|
|
}
|
|
|
|
|
|
private JSONObject getSaleCalendarCountData(String url, String type) {
|
...
|
...
|
@@ -583,7 +424,7 @@ public class ProductSearchServiceImpl implements ProductSearchService { |
|
|
type = "";
|
|
|
}
|
|
|
searchParam.setType(type);
|
|
|
countMap = search(searchParam.getParam(), url).getJSONObject("sale_date_count_list");
|
|
|
countMap = searchAssistService.search(searchParam.getParam(), url).getJSONObject("sale_date_count_list");
|
|
|
} catch (Exception e) {
|
|
|
logger.error("调用销售日历汇总数据出错: " + e.getMessage(), e);
|
|
|
}
|
...
|
...
|
@@ -618,10 +459,10 @@ public class ProductSearchServiceImpl implements ProductSearchService { |
|
|
ProductSearchReq req = new ProductSearchReq();
|
|
|
req.setStartTime(startTime).setEndTime(endTime);
|
|
|
SearchParam searchParam = new SearchParam().buildPageSearchParam(req);
|
|
|
JSONObject data = search(searchParam.getParam(), SALE_CALENDAR_LIST_URL);
|
|
|
JSONObject data = searchAssistService.search(searchParam.getParam(), ProductSearchConstants.SALE_CALENDAR_LIST_URL);
|
|
|
// 将图片的相对路径转成绝对路径
|
|
|
if (null != data) {
|
|
|
processProductList(data.getJSONArray("product_list"));
|
|
|
searchAssistService.processProductList(data.getJSONArray("product_list"));
|
|
|
}
|
|
|
return data;
|
|
|
}
|
...
|
...
|
@@ -636,129 +477,50 @@ public class ProductSearchServiceImpl implements ProductSearchService { |
|
|
type = "";
|
|
|
}
|
|
|
searchParam.setType(type);
|
|
|
JSONObject data = search(searchParam.getParam(), NEW_SALE_CALENDAR_LIST_URL);
|
|
|
JSONObject data = searchAssistService.search(searchParam.getParam(), ProductSearchConstants.NEW_SALE_CALENDAR_LIST_URL);
|
|
|
// 将图片的相对路径转成绝对路径
|
|
|
if (null != data) {
|
|
|
processProductList(data.getJSONArray("product_list"));
|
|
|
searchAssistService.processProductList(data.getJSONArray("product_list"));
|
|
|
}
|
|
|
return data;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public JSONObject searchHotSale(Integer page, Integer limit) {
|
|
|
public JSONObject searchHotSale(Integer page, Integer limit, String businessClient) {
|
|
|
ProductSearchReq req = new ProductSearchReq().setViewNum(limit).setPage(page);
|
|
|
SearchParam searchParam = new SearchParam().buildPageSearchParam(req);
|
|
|
JSONObject data = search(searchParam.getParam(), HOT_SALE_LIST_URL);
|
|
|
SearchParam searchParam = new SearchParam().buildPageSearchParam(req).setShowChannel(businessClient);
|
|
|
JSONObject data = searchAssistService.search(searchParam.getParam(), ProductSearchConstants.HOT_SALE_LIST_URL);
|
|
|
// 将图片的相对路径转成绝对路径
|
|
|
if (null != data) {
|
|
|
processProductList(data.getJSONArray("product_list"));
|
|
|
processProductSales(data.getJSONArray("product_list"));
|
|
|
searchAssistService.processProductList(data.getJSONArray("product_list"));
|
|
|
searchAssistService.processProductSales(data.getJSONArray("product_list"));
|
|
|
}
|
|
|
return data;
|
|
|
}
|
|
|
|
|
|
public void handlerPrice(JSONObject product) {
|
|
|
product.put("price", getIntCeilPrice(product.getDouble("price")));
|
|
|
JSONArray planList = product.getJSONArray("product_price_plan_list");
|
|
|
if(CollectionUtils.isEmpty(planList)){
|
|
|
return;
|
|
|
}
|
|
|
JSONObject effectPlan = getEffectProductPricePlan(planList);
|
|
|
//没有符合的价格计划,直接返回
|
|
|
if(null==effectPlan){
|
|
|
return;
|
|
|
}
|
|
|
if(null!=effectPlan.get("current_saleprice")){
|
|
|
product.replace("sales_price", getIntCeilPrice(effectPlan.getDouble("current_saleprice")));
|
|
|
}
|
|
|
if(null!=effectPlan.get("vip1_price")){
|
|
|
product.replace("vip1_price", effectPlan.getDouble("vip1_price"));
|
|
|
}
|
|
|
|
|
|
if(null!=effectPlan.get("vip2_price")){
|
|
|
product.replace("vip2_price", effectPlan.getDouble("vip2_price"));
|
|
|
}
|
|
|
|
|
|
if(null!=effectPlan.get("vip3_price")){
|
|
|
product.replace("vip3_price", effectPlan.getDouble("vip3_price"));
|
|
|
}
|
|
|
|
|
|
if(null!=effectPlan.get("vip_discount_type")){
|
|
|
product.replace("vip_discount_type", effectPlan.getInteger("vip_discount_type"));
|
|
|
}
|
|
|
if(null!=effectPlan.get("student_price") && !"Y".equalsIgnoreCase(product.getString("is_student_price"))){
|
|
|
product.replace("student_price", product.getBigDecimal("sales_price").multiply(new BigDecimal("0.9")));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取一个生效的变价计划
|
|
|
* @param list
|
|
|
* @return
|
|
|
*/
|
|
|
private JSONObject getEffectProductPricePlan(JSONArray planList){
|
|
|
if(CollectionUtils.isEmpty(planList)){
|
|
|
return null;
|
|
|
}
|
|
|
//先计算匹配到的价格计划,然后根据匹配到的价格计划求优先级
|
|
|
int currentTime= DateUtil.getCurrentTimeSecond();
|
|
|
logger.info("currentTime: {}", currentTime);
|
|
|
List<JSONObject> fitProductPricePlanList=Lists.newArrayList();
|
|
|
for (int i=0; i < planList.size(); i++) {
|
|
|
JSONObject item = planList.getJSONObject(i);
|
|
|
//当前时间大于等于生效时间且当前时间小于结束时间或没有结束时间的
|
|
|
if(currentTime>=item.getIntValue("effect_time") && (currentTime<=item.getIntValue("end_time")||item.getIntValue("end_time")==0)){
|
|
|
fitProductPricePlanList.add(item);
|
|
|
}
|
|
|
}
|
|
|
if(!CollectionUtils.isEmpty(fitProductPricePlanList)){
|
|
|
//在多个价格计划都满足的情况下,生效时间越大越靠前
|
|
|
Collections.sort(fitProductPricePlanList, new Comparator<JSONObject>() {
|
|
|
@Override
|
|
|
public int compare(JSONObject o1, JSONObject o2) {
|
|
|
if(o2.getInteger("effect_time").compareTo(o1.getInteger("effect_time"))==0
|
|
|
&& null!=o2.getInteger("create_time") && null!=o1.getInteger("create_time")){
|
|
|
return o2.getInteger("create_time").compareTo(o1.getInteger("create_time"));
|
|
|
}
|
|
|
return o2.getInteger("effect_time").compareTo(o1.getInteger("effect_time"));
|
|
|
}
|
|
|
});
|
|
|
return fitProductPricePlanList.get(0);
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
//获取取整的价格
|
|
|
public static Integer getIntCeilPrice(Double price){
|
|
|
if(null == price) {
|
|
|
return 0;
|
|
|
}
|
|
|
return Double.valueOf(Math.ceil(price)).intValue();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public JSONObject searchUvscoreProductList(ProductSearchReq req, Integer regularize) {
|
|
|
if (REGULARIZE_NFC.equals(regularize)) { // NFC分享页列表 需要返回18个商品
|
|
|
req.setViewNum(18);
|
|
|
}
|
|
|
SearchParam searchParam = new SearchParam().buildPageSearchParam(req);
|
|
|
String url = PRODUCT_UVSCORE_LIST_URL;
|
|
|
JSONObject data = search(searchParam.getParam(), url);
|
|
|
SearchParam searchParam = new SearchParam().buildPageSearchParam(req).setShowChannel(req.getBusinessClient());
|
|
|
String url = ProductSearchConstants.PRODUCT_UVSCORE_LIST_URL;
|
|
|
JSONObject data = searchAssistService.search(searchParam.getParam(), url);
|
|
|
// 将图片的相对路径转成绝对路径
|
|
|
if (null != data) {
|
|
|
processProductList(data.getJSONArray("product_list"));
|
|
|
searchAssistService.processProductList(data.getJSONArray("product_list"));
|
|
|
|
|
|
if (REGULARIZE_NFC.equals(regularize)) { // NFC分享页列表 需要返回 3的倍数的列表且不需要销量
|
|
|
regularize(data.getJSONArray("product_list"));
|
|
|
searchAssistService.regularize(data.getJSONArray("product_list"));
|
|
|
} else {
|
|
|
processProductSales(data.getJSONArray("product_list")); // NFC分享页列表不需要销量
|
|
|
searchAssistService.processProductSales(data.getJSONArray("product_list")); // NFC分享页列表不需要销量
|
|
|
}
|
|
|
}
|
|
|
return data;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public SearchProductRecommendResp searchProductRecommendByIdAndSeriesBrand(Integer productId) {
|
|
|
public SearchProductRecommendResp searchProductRecommendByIdAndSeriesBrand(Integer productId, String businessClient) {
|
|
|
SearchProductRecommendResp resp = new SearchProductRecommendResp();
|
|
|
|
|
|
Product product = productHelpService.selectByIdCache(productId);
|
...
|
...
|
@@ -769,11 +531,11 @@ public class ProductSearchServiceImpl implements ProductSearchService { |
|
|
if(null != product.getSeriesId() && product.getSeriesId().intValue() != 0) {
|
|
|
req.setSeries(product.getSeriesId() + "");
|
|
|
}
|
|
|
SearchParam searchParam = new SearchParam().buildSearchParam(req);
|
|
|
SearchParam searchParam = new SearchParam().buildSearchParam(req).setShowChannel(businessClient);
|
|
|
|
|
|
JSONObject data = search(searchParam.getParam(), PRODUCT_RECOMMEND_BY_SERIESBRAND_LIST_URL);
|
|
|
JSONObject data = searchAssistService.search(searchParam.getParam(), ProductSearchConstants.PRODUCT_RECOMMEND_BY_SERIESBRAND_LIST_URL);
|
|
|
if(data != null && !CollectionUtils.isEmpty(data.getJSONArray("product_list"))) {
|
|
|
processProductSales(data.getJSONArray("product_list"));
|
|
|
searchAssistService.processProductSales(data.getJSONArray("product_list"));
|
|
|
resp = JSON.toJavaObject(data, SearchProductRecommendResp.class);
|
|
|
|
|
|
// 对品牌的log 进行相对路径转绝对路径
|
...
|
...
|
@@ -789,31 +551,17 @@ public class ProductSearchServiceImpl implements ProductSearchService { |
|
|
|
|
|
@Override
|
|
|
public JSONObject searchSecondhandSkupList(ProductSearchReq req) {
|
|
|
SearchParam searchParam = new SearchParam().buildPageSearchParam(req);
|
|
|
String url = SECONDHAND_SKUP_QUERY_URL;
|
|
|
JSONObject data = search(searchParam.getParam(), url);
|
|
|
SearchParam searchParam = new SearchParam().buildPageSearchParam(req).setShowChannel(req.getBusinessClient());
|
|
|
String url = ProductSearchConstants.SECONDHAND_SKUP_QUERY_URL;
|
|
|
JSONObject data = searchAssistService.search(searchParam.getParam(), url);
|
|
|
// 将图片的相对路径转成绝对路径
|
|
|
if (null != data) {
|
|
|
processSecondhandSkupList(data.getJSONArray("skup_list"));
|
|
|
searchAssistService.processSecondhandSkupList(data.getJSONArray("skup_list"));
|
|
|
}
|
|
|
|
|
|
return data;
|
|
|
}
|
|
|
|
|
|
// NFC详情分享页列表要保证 3的倍数,这里做最后的保证
|
|
|
private void regularize(JSONArray productList) {
|
|
|
if(CollectionUtils.isEmpty(productList)){
|
|
|
return;
|
|
|
}
|
|
|
logger.info("method regularize in. productList.size() is {}", productList.size());
|
|
|
if (productList.size() % 3 == 1) {
|
|
|
productList.remove(productList.size() - 1);
|
|
|
} else if (productList.size() % 3 == 2) {
|
|
|
productList.remove(productList.size() - 1);
|
|
|
productList.remove(productList.size() - 2);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private CouponInfo getCouponInfo(String token) {
|
|
|
ApiResponse resp = ufoServiceCaller.call("ufo.coupons.getProductIds", ApiResponse.class, token);
|
|
|
return (CouponInfo) resp.getData();
|
...
|
...
|
|