Showing
6 changed files
with
52 additions
and
17 deletions
@@ -3,7 +3,6 @@ package com.yohoufo.product.controller; | @@ -3,7 +3,6 @@ package com.yohoufo.product.controller; | ||
3 | import com.alibaba.fastjson.JSONObject; | 3 | import com.alibaba.fastjson.JSONObject; |
4 | import com.yoho.tools.docs.ApiOperation; | 4 | import com.yoho.tools.docs.ApiOperation; |
5 | import com.yohoufo.common.annotation.IgnoreSignature; | 5 | import com.yohoufo.common.annotation.IgnoreSignature; |
6 | -import com.yohoufo.common.utils.UfoJsonUtil; | ||
7 | import com.yohoufo.product.helper.SearchHelpService; | 6 | import com.yohoufo.product.helper.SearchHelpService; |
8 | import com.yohoufo.product.request.ProductSearchReq; | 7 | import com.yohoufo.product.request.ProductSearchReq; |
9 | import com.yohoufo.product.request.SortIdLevel; | 8 | import com.yohoufo.product.request.SortIdLevel; |
@@ -62,18 +61,14 @@ public class ProductSearchController { | @@ -62,18 +61,14 @@ public class ProductSearchController { | ||
62 | @ApiOperation(name = "ufo.product.data.search.recommend", desc="商品详情页的相似商品推荐") | 61 | @ApiOperation(name = "ufo.product.data.search.recommend", desc="商品详情页的相似商品推荐") |
63 | @RequestMapping(params = "method=ufo.product.data.search.recommend") | 62 | @RequestMapping(params = "method=ufo.product.data.search.recommend") |
64 | @IgnoreSession | 63 | @IgnoreSession |
65 | - @Cachable(expire = 300) | ||
66 | - public ApiResponse searchProductRecommendById( | ||
67 | - @RequestParam(value = "product_id", required = false) Integer productId) { | ||
68 | - | ||
69 | - ProductSearchReq req = new ProductSearchReq().setId(productId); | ||
70 | - return new ApiResponse.ApiResponseBuilder().code(200).message("Category Product List.").data(mockSearchProductRecommendById(req)).build(); | ||
71 | - } | ||
72 | - | ||
73 | - private SearchProductRecommendResp mockSearchProductRecommendById(ProductSearchReq req){ | ||
74 | - 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\"}]}"; | ||
75 | - SearchProductRecommendResp data = UfoJsonUtil.safelyParseObject(mockJson, SearchProductRecommendResp.class); | ||
76 | - return data; | 64 | + @Cachable |
65 | + public ApiResponse searchProductRecommendById(@RequestParam(value = "product_id") Integer productId) { | ||
66 | + | ||
67 | + if (null == productId) { | ||
68 | + return new ApiResponse(400, "product_id Is Null", null); | ||
69 | + } | ||
70 | + SearchProductRecommendResp resp = productSearchService.searchProductRecommendById(productId); | ||
71 | + return new ApiResponse.ApiResponseBuilder().code(200).message("product.data.search.recommend").data(resp).build(); | ||
77 | } | 72 | } |
78 | 73 | ||
79 | @IgnoreSignature | 74 | @IgnoreSignature |
@@ -54,7 +54,7 @@ public class SearchParam { | @@ -54,7 +54,7 @@ public class SearchParam { | ||
54 | setOrder(req.getOrder()).setBrand(req.getBrand()).setSize(req.getSize()) | 54 | setOrder(req.getOrder()).setBrand(req.getBrand()).setSize(req.getSize()) |
55 | .setMaxSort(req.getMaxSort()).setMidSort(req.getMidSort()) | 55 | .setMaxSort(req.getMaxSort()).setMidSort(req.getMidSort()) |
56 | .setQuery(req.getQuery()).setSoonSale(req.getIsSoonSale()) | 56 | .setQuery(req.getQuery()).setSoonSale(req.getIsSoonSale()) |
57 | - .setProductPool(req.getPool()).setBrandSeries(req.getSeries()).setGender(req.getGender()); | 57 | + .setProductPool(req.getPool()).setBrandSeries(req.getSeries()).setGender(req.getGender()).setNotId(req.getNot_id()); |
58 | return this; | 58 | return this; |
59 | } | 59 | } |
60 | 60 | ||
@@ -173,6 +173,18 @@ public class SearchParam { | @@ -173,6 +173,18 @@ public class SearchParam { | ||
173 | } | 173 | } |
174 | 174 | ||
175 | /** | 175 | /** |
176 | + * 设置id | ||
177 | + * | ||
178 | + * @return | ||
179 | + */ | ||
180 | + public SearchParam setNotId(String notId) { | ||
181 | + if (StringUtils.isNotBlank(notId)) { | ||
182 | + param.put(SearchConstants.IndexNameConstant.NOT_ID, notId); | ||
183 | + } | ||
184 | + return this; | ||
185 | + } | ||
186 | + | ||
187 | + /** | ||
176 | * 每次查询的条数 | 188 | * 每次查询的条数 |
177 | * | 189 | * |
178 | * @param viewNum | 190 | * @param viewNum |
@@ -15,7 +15,7 @@ public class ProductSearchReq { | @@ -15,7 +15,7 @@ public class ProductSearchReq { | ||
15 | private String pool; | 15 | private String pool; |
16 | private String order; | 16 | private String order; |
17 | private String isSoonSale; //Y saletime查了大于now的 | 17 | private String isSoonSale; //Y saletime查了大于now的 |
18 | - private Integer not_id; | 18 | + private String not_id; |
19 | 19 | ||
20 | 20 | ||
21 | public Integer getId() { | 21 | public Integer getId() { |
@@ -136,11 +136,12 @@ public class ProductSearchReq { | @@ -136,11 +136,12 @@ public class ProductSearchReq { | ||
136 | } | 136 | } |
137 | 137 | ||
138 | 138 | ||
139 | - public Integer getNot_id() { | 139 | + public String getNot_id() { |
140 | return not_id; | 140 | return not_id; |
141 | } | 141 | } |
142 | 142 | ||
143 | - public void setNot_id(Integer not_id) { | 143 | + public ProductSearchReq setNot_id(String not_id) { |
144 | this.not_id = not_id; | 144 | this.not_id = not_id; |
145 | + return this; | ||
145 | } | 146 | } |
146 | } | 147 | } |
@@ -6,6 +6,7 @@ import com.yohoufo.product.request.ProductSearchReq; | @@ -6,6 +6,7 @@ import com.yohoufo.product.request.ProductSearchReq; | ||
6 | import com.yohoufo.product.request.SortIdLevel; | 6 | import com.yohoufo.product.request.SortIdLevel; |
7 | import com.yohoufo.product.response.SearchBrandListResp; | 7 | import com.yohoufo.product.response.SearchBrandListResp; |
8 | import com.yohoufo.product.response.SearchProductListFilterResp; | 8 | import com.yohoufo.product.response.SearchProductListFilterResp; |
9 | +import com.yohoufo.product.response.SearchProductRecommendResp; | ||
9 | 10 | ||
10 | public interface ProductSearchService { | 11 | public interface ProductSearchService { |
11 | 12 | ||
@@ -17,4 +18,6 @@ public interface ProductSearchService { | @@ -17,4 +18,6 @@ public interface ProductSearchService { | ||
17 | 18 | ||
18 | SearchBrandListResp searchBrandList(); | 19 | SearchBrandListResp searchBrandList(); |
19 | 20 | ||
21 | + SearchProductRecommendResp searchProductRecommendById(Integer productId); | ||
22 | + | ||
20 | } | 23 | } |
@@ -8,7 +8,9 @@ import java.util.stream.Collectors; | @@ -8,7 +8,9 @@ import java.util.stream.Collectors; | ||
8 | import com.alibaba.fastjson.JSON; | 8 | import com.alibaba.fastjson.JSON; |
9 | import com.alibaba.fastjson.JSONArray; | 9 | import com.alibaba.fastjson.JSONArray; |
10 | import com.yohoufo.common.utils.UfoStringUtils; | 10 | import com.yohoufo.common.utils.UfoStringUtils; |
11 | +import com.yohoufo.dal.product.ProductMapper; | ||
11 | import com.yohoufo.dal.product.ProductSortMapper; | 12 | import com.yohoufo.dal.product.ProductSortMapper; |
13 | +import com.yohoufo.dal.product.model.Product; | ||
12 | import com.yohoufo.dal.product.model.ProductSort; | 14 | import com.yohoufo.dal.product.model.ProductSort; |
13 | import com.yohoufo.product.helper.SearchParam; | 15 | import com.yohoufo.product.helper.SearchParam; |
14 | import com.yohoufo.product.model.FilterItem; | 16 | import com.yohoufo.product.model.FilterItem; |
@@ -16,6 +18,7 @@ import com.yohoufo.product.request.ProductSearchReq; | @@ -16,6 +18,7 @@ import com.yohoufo.product.request.ProductSearchReq; | ||
16 | import com.yohoufo.product.request.SortIdLevel; | 18 | import com.yohoufo.product.request.SortIdLevel; |
17 | import com.yohoufo.product.response.SearchBrandListResp; | 19 | import com.yohoufo.product.response.SearchBrandListResp; |
18 | import com.yohoufo.product.response.SearchProductListFilterResp; | 20 | import com.yohoufo.product.response.SearchProductListFilterResp; |
21 | +import com.yohoufo.product.response.SearchProductRecommendResp; | ||
19 | import org.apache.commons.lang3.StringUtils; | 22 | import org.apache.commons.lang3.StringUtils; |
20 | import org.slf4j.Logger; | 23 | import org.slf4j.Logger; |
21 | import org.slf4j.LoggerFactory; | 24 | import org.slf4j.LoggerFactory; |
@@ -43,6 +46,9 @@ public class ProductSearchServiceImpl implements ProductSearchService { | @@ -43,6 +46,9 @@ public class ProductSearchServiceImpl implements ProductSearchService { | ||
43 | @Autowired | 46 | @Autowired |
44 | private ProductSortMapper productSortMapper; | 47 | private ProductSortMapper productSortMapper; |
45 | 48 | ||
49 | + @Autowired | ||
50 | + private ProductMapper productMapper; | ||
51 | + | ||
46 | 52 | ||
47 | public static final String PRODUCT_LIST_URL = "/yohosearch/ufo/productList.json"; | 53 | public static final String PRODUCT_LIST_URL = "/yohosearch/ufo/productList.json"; |
48 | 54 | ||
@@ -198,6 +204,22 @@ public class ProductSearchServiceImpl implements ProductSearchService { | @@ -198,6 +204,22 @@ public class ProductSearchServiceImpl implements ProductSearchService { | ||
198 | } | 204 | } |
199 | 205 | ||
200 | @Override | 206 | @Override |
207 | + public SearchProductRecommendResp searchProductRecommendById(Integer productId) { | ||
208 | + SearchProductRecommendResp resp = new SearchProductRecommendResp(); | ||
209 | + Product product = productMapper.selectByPrimaryKey(productId); | ||
210 | + if (product != null) { | ||
211 | + ProductSearchReq req = new ProductSearchReq().setNot_id(productId + "").setMidSort(product.getMidSortId() + "").setBrand(product.getBrandId() + "").setQuery(product.getProductName()); | ||
212 | + SearchParam searchParam = new SearchParam().buildSearchParam(req); | ||
213 | + | ||
214 | + JSONObject data = search(searchParam.getParam(), PRODUCT_RECOMMEND_LIST_URL); | ||
215 | + if(data != null && !CollectionUtils.isEmpty(data.getJSONArray("product_list"))) { | ||
216 | + resp = JSON.toJavaObject(data, SearchProductRecommendResp.class); | ||
217 | + } | ||
218 | + } | ||
219 | + return resp; | ||
220 | + } | ||
221 | + | ||
222 | + @Override | ||
201 | public SortIdLevel getSortLevelById(String sortId) { | 223 | public SortIdLevel getSortLevelById(String sortId) { |
202 | SortIdLevel sortIdLevel = new SortIdLevel(); | 224 | SortIdLevel sortIdLevel = new SortIdLevel(); |
203 | if (StringUtils.isNotBlank(sortId)) { | 225 | if (StringUtils.isNotBlank(sortId)) { |
-
Please register or login to post a comment