Authored by zhaojun2

add recommendlist

... ... @@ -3,7 +3,6 @@ package com.yohoufo.product.controller;
import com.alibaba.fastjson.JSONObject;
import com.yoho.tools.docs.ApiOperation;
import com.yohoufo.common.annotation.IgnoreSignature;
import com.yohoufo.common.utils.UfoJsonUtil;
import com.yohoufo.product.helper.SearchHelpService;
import com.yohoufo.product.request.ProductSearchReq;
import com.yohoufo.product.request.SortIdLevel;
... ... @@ -62,18 +61,14 @@ public class ProductSearchController {
@ApiOperation(name = "ufo.product.data.search.recommend", desc="商品详情页的相似商品推荐")
@RequestMapping(params = "method=ufo.product.data.search.recommend")
@IgnoreSession
@Cachable(expire = 300)
public ApiResponse searchProductRecommendById(
@RequestParam(value = "product_id", required = false) Integer productId) {
ProductSearchReq req = new ProductSearchReq().setId(productId);
return new ApiResponse.ApiResponseBuilder().code(200).message("Category Product List.").data(mockSearchProductRecommendById(req)).build();
}
private SearchProductRecommendResp mockSearchProductRecommendById(ProductSearchReq req){
String mockJson = "{\"product_list\":[{\"product_id\":51189414,\"price\":350,\"product_name\":\"Carrots by Anwar X AKOP. X Champion  LOGO鞋\",\"default_images\":\"http://img10.static.yhbimg.com/goodsimg/2015/12/31/04/01d1f809fded2473409a0ae2a3b4d57bc2.jpg?imageMogr2/thumbnail/{width}x{height}/background/d2hpdGU=/position/center/quality/80\"},{\"product_id\":51189413,\"price\":350,\"product_name\":\"Carrots by Anwar X AKOP. X Champion  LOGO鞋\",\"default_images\":\"http://img10.static.yhbimg.com/goodsimg/2015/12/31/04/01d1f809fded2473409a0ae2a3b4d57bc2.jpg?imageMogr2/thumbnail/{width}x{height}/background/d2hpdGU=/position/center/quality/80\"},{\"product_id\":51189412,\"price\":350,\"product_name\":\"Carrots by Anwar X AKOP. X Champion  LOGO鞋\",\"default_images\":\"http://img10.static.yhbimg.com/goodsimg/2015/12/31/04/01d1f809fded2473409a0ae2a3b4d57bc2.jpg?imageMogr2/thumbnail/{width}x{height}/background/d2hpdGU=/position/center/quality/80\"},{\"product_id\":51189411,\"price\":350,\"product_name\":\"Carrots by Anwar X AKOP. X Champion  LOGO鞋\",\"default_images\":\"http://img10.static.yhbimg.com/goodsimg/2015/12/31/04/01d1f809fded2473409a0ae2a3b4d57bc2.jpg?imageMogr2/thumbnail/{width}x{height}/background/d2hpdGU=/position/center/quality/80\"}]}";
SearchProductRecommendResp data = UfoJsonUtil.safelyParseObject(mockJson, SearchProductRecommendResp.class);
return data;
@Cachable
public ApiResponse searchProductRecommendById(@RequestParam(value = "product_id") Integer productId) {
if (null == productId) {
return new ApiResponse(400, "product_id Is Null", null);
}
SearchProductRecommendResp resp = productSearchService.searchProductRecommendById(productId);
return new ApiResponse.ApiResponseBuilder().code(200).message("product.data.search.recommend").data(resp).build();
}
@IgnoreSignature
... ...
... ... @@ -80,6 +80,8 @@ public final class SearchConstants {
String SOON_SALE = "isSoonSale";
String NOT_ID = "not_id";
}
}
... ...
... ... @@ -54,7 +54,7 @@ public class SearchParam {
setOrder(req.getOrder()).setBrand(req.getBrand()).setSize(req.getSize())
.setMaxSort(req.getMaxSort()).setMidSort(req.getMidSort())
.setQuery(req.getQuery()).setSoonSale(req.getIsSoonSale())
.setProductPool(req.getPool()).setBrandSeries(req.getSeries()).setGender(req.getGender());
.setProductPool(req.getPool()).setBrandSeries(req.getSeries()).setGender(req.getGender()).setNotId(req.getNot_id());
return this;
}
... ... @@ -173,6 +173,18 @@ public class SearchParam {
}
/**
* 设置id
*
* @return
*/
public SearchParam setNotId(String notId) {
if (StringUtils.isNotBlank(notId)) {
param.put(SearchConstants.IndexNameConstant.NOT_ID, notId);
}
return this;
}
/**
* 每次查询的条数
*
* @param viewNum
... ...
... ... @@ -15,7 +15,7 @@ public class ProductSearchReq {
private String pool;
private String order;
private String isSoonSale; //Y saletime查了大于now的
private Integer not_id;
private String not_id;
public Integer getId() {
... ... @@ -136,11 +136,12 @@ public class ProductSearchReq {
}
public Integer getNot_id() {
public String getNot_id() {
return not_id;
}
public void setNot_id(Integer not_id) {
public ProductSearchReq setNot_id(String not_id) {
this.not_id = not_id;
return this;
}
}
... ...
... ... @@ -6,6 +6,7 @@ import com.yohoufo.product.request.ProductSearchReq;
import com.yohoufo.product.request.SortIdLevel;
import com.yohoufo.product.response.SearchBrandListResp;
import com.yohoufo.product.response.SearchProductListFilterResp;
import com.yohoufo.product.response.SearchProductRecommendResp;
public interface ProductSearchService {
... ... @@ -17,4 +18,6 @@ public interface ProductSearchService {
SearchBrandListResp searchBrandList();
SearchProductRecommendResp searchProductRecommendById(Integer productId);
}
... ...
... ... @@ -8,7 +8,9 @@ import java.util.stream.Collectors;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.yohoufo.common.utils.UfoStringUtils;
import com.yohoufo.dal.product.ProductMapper;
import com.yohoufo.dal.product.ProductSortMapper;
import com.yohoufo.dal.product.model.Product;
import com.yohoufo.dal.product.model.ProductSort;
import com.yohoufo.product.helper.SearchParam;
import com.yohoufo.product.model.FilterItem;
... ... @@ -16,6 +18,7 @@ import com.yohoufo.product.request.ProductSearchReq;
import com.yohoufo.product.request.SortIdLevel;
import com.yohoufo.product.response.SearchBrandListResp;
import com.yohoufo.product.response.SearchProductListFilterResp;
import com.yohoufo.product.response.SearchProductRecommendResp;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -43,6 +46,9 @@ public class ProductSearchServiceImpl implements ProductSearchService {
@Autowired
private ProductSortMapper productSortMapper;
@Autowired
private ProductMapper productMapper;
public static final String PRODUCT_LIST_URL = "/yohosearch/ufo/productList.json";
... ... @@ -198,6 +204,22 @@ public class ProductSearchServiceImpl implements ProductSearchService {
}
@Override
public SearchProductRecommendResp searchProductRecommendById(Integer productId) {
SearchProductRecommendResp resp = new SearchProductRecommendResp();
Product product = productMapper.selectByPrimaryKey(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);
if(data != null && !CollectionUtils.isEmpty(data.getJSONArray("product_list"))) {
resp = JSON.toJavaObject(data, SearchProductRecommendResp.class);
}
}
return resp;
}
@Override
public SortIdLevel getSortLevelById(String sortId) {
SortIdLevel sortIdLevel = new SortIdLevel();
if (StringUtils.isNotBlank(sortId)) {
... ...