Authored by zhaojun2

add 筛选项接口

... ... @@ -81,9 +81,26 @@ public class ProductSearchController {
@RequestMapping(params = "method=ufo.product.search.list.filter")
@IgnoreSession
//@Cachable
public ApiResponse searchProductListFilter() {
public ApiResponse searchProductListFilter(
@RequestParam(value = "productPool", required = false) String productPool,
@RequestParam(value = "sort", required = false)String sort,
@RequestParam(value = "brand", required = false)String brand,
@RequestParam(value = "series", required = false)String series,
@RequestParam(value = "gender", required = false) String gender,
@RequestParam(value = "size", required = false) String size,
@RequestParam(value = "isSoonSale", required = false) String isSoonSale,
@RequestParam(value = "query", required = false)String query
) {
SortIdLevel sortIdLevel = productSearchService.getSortLevelById(sort);
ProductSearchReq req = new ProductSearchReq().setPool(productPool).setBrand(brand).setMidSort(sortIdLevel.getMidSortId()).setMaxSort(sortIdLevel.getMaxSortId())
.setSeries(series).setGender(gender).setSize(size).setIsSoonSale(isSoonSale);
searchHelpService.setQuery(query, req);
SearchProductListFilterResp resp = productSearchService.searchProductListFilter(req);
return new ApiResponse.ApiResponseBuilder().code(200).message("product.search.list.filter").data(mockSearchProductListFilter()).build();
return new ApiResponse.ApiResponseBuilder().code(200).message("product.search.list.filter").data(resp).build();
}
private SearchProductListFilterResp mockSearchProductListFilter(){
... ...
... ... @@ -40,7 +40,7 @@ public class SearchParam {
* @param req
* @return
*/
public SearchParam buildSearchParam(ProductSearchReq req) {
public SearchParam buildPageSearchParam(ProductSearchReq req) {
setOrder(req.getOrder()).setBrand(req.getBrand()).setSize(req.getSize())
.setMaxSort(req.getMaxSort()).setMidSort(req.getMidSort())
.setQuery(req.getQuery()).setSoonSale(req.getIsSoonSale())
... ... @@ -50,6 +50,14 @@ public class SearchParam {
return this;
}
public SearchParam buildSearchParam(ProductSearchReq req) {
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());
return this;
}
/**
* 设置排序
*
... ...
... ... @@ -16,6 +16,7 @@ public class FilterItem {
private String itemId;
private String itemName;
private String itemUrl;
public String getItemId() {
... ... @@ -33,6 +34,14 @@ public class FilterItem {
public void setItemName(String itemName) {
this.itemName = itemName;
}
public String getItemUrl() {
return itemUrl;
}
public void setItemUrl(String itemUrl) {
this.itemUrl = itemUrl;
}
}
... ...
... ... @@ -4,6 +4,7 @@ package com.yohoufo.product.service;
import com.alibaba.fastjson.JSONObject;
import com.yohoufo.product.request.ProductSearchReq;
import com.yohoufo.product.request.SortIdLevel;
import com.yohoufo.product.response.SearchProductListFilterResp;
public interface ProductSearchService {
... ... @@ -11,4 +12,6 @@ public interface ProductSearchService {
SortIdLevel getSortLevelById(String sortId);
SearchProductListFilterResp searchProductListFilter(ProductSearchReq req);
}
... ...
package com.yohoufo.product.service.impl;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.alibaba.fastjson.JSONArray;
import com.yohoufo.common.utils.UfoStringUtils;
import com.yohoufo.dal.product.ProductSortMapper;
import com.yohoufo.dal.product.model.ProductSort;
import com.yohoufo.product.helper.SearchParam;
import com.yohoufo.product.model.FilterItem;
import com.yohoufo.product.request.ProductSearchReq;
import com.yohoufo.product.request.SortIdLevel;
import com.yohoufo.product.response.SearchProductListFilterResp;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -80,12 +84,107 @@ public class ProductSearchServiceImpl implements ProductSearchService {
@Override
public JSONObject searchProductList(ProductSearchReq req) {
SearchParam searchParam = new SearchParam().buildSearchParam(req);
SearchParam searchParam = new SearchParam().buildPageSearchParam(req);
JSONObject data = search(searchParam.getParam(), PRODUCT_LIST_URL);
return data;
}
@Override
public SearchProductListFilterResp searchProductListFilter(ProductSearchReq req) {
SearchParam searchParam = new SearchParam().buildSearchParam(req);
JSONObject data = search(searchParam.getParam(), FILTER_LIST_URL);
SearchProductListFilterResp resp = new SearchProductListFilterResp();
if (data != null) {
JSONObject filterData = data.getJSONObject("filter");
if (filterData != null) {
List<FilterItem> filterItems = new ArrayList<>();
if (!CollectionUtils.isEmpty(filterData.getJSONArray("sort"))) {
JSONArray sortArray = filterData.getJSONArray("sort");
FilterItem sortFilterItem = new FilterItem();
sortFilterItem.setFilterId("sort");
sortFilterItem.setFilterName("品类");
sortFilterItem.setMultiSelect(false);
List<FilterItem.Item> itemList = new ArrayList<>();
for (Object sort : sortArray) {
FilterItem.Item item = new FilterItem.Item();
item.setItemName(((JSONObject)sort).getString("sort_name"));
item.setItemId(((JSONObject)sort).getString("id"));
itemList.add(item);
}
sortFilterItem.setItemList(itemList);
filterItems.add(sortFilterItem);
}
if (!filterData.getJSONObject("gender").isEmpty()) {
JSONObject gender = filterData.getJSONObject("gender");
FilterItem genderFilterItem = new FilterItem();
genderFilterItem.setFilterId("gender");
genderFilterItem.setFilterName("性别");
genderFilterItem.setMultiSelect(false);
List<FilterItem.Item> itemList = new ArrayList<>();
if (StringUtils.isNotBlank(gender.getString("MEN"))) {
FilterItem.Item menItem = new FilterItem.Item();
menItem.setItemId(gender.getString("MEN"));
menItem.setItemName("MEN");
itemList.add(menItem);
}
if (StringUtils.isNotBlank(gender.getString("WOMEN"))) {
FilterItem.Item womenItem = new FilterItem.Item();
womenItem.setItemId(gender.getString("WOMEN"));
womenItem.setItemName("WOMEN");
itemList.add(womenItem);
}
genderFilterItem.setItemList(itemList);
filterItems.add(genderFilterItem);
}
if (!CollectionUtils.isEmpty(filterData.getJSONArray("size"))) {
JSONArray sizeArray = filterData.getJSONArray("size");
FilterItem sizeFilterItem = new FilterItem();
sizeFilterItem.setFilterId("size");
sizeFilterItem.setFilterName("尺码");
sizeFilterItem.setMultiSelect(false);
List<FilterItem.Item> itemList = new ArrayList<>();
for (Object size : sizeArray) {
FilterItem.Item item = new FilterItem.Item();
item.setItemName(((JSONObject)size).getString("size_name"));
item.setItemId(((JSONObject)size).getString("size_id"));
itemList.add(item);
}
sizeFilterItem.setItemList(itemList);
filterItems.add(sizeFilterItem);
}
if (!CollectionUtils.isEmpty(filterData.getJSONArray("brand"))) {
JSONArray brandArray = filterData.getJSONArray("brand");
FilterItem brandFilterItem = new FilterItem();
brandFilterItem.setFilterId("brand");
brandFilterItem.setFilterName("品牌");
brandFilterItem.setMultiSelect(false);
List<FilterItem.Item> itemList = new ArrayList<>();
for (Object brand : brandArray) {
FilterItem.Item item = new FilterItem.Item();
item.setItemName(((JSONObject)brand).getString("brand_name"));
item.setItemId(((JSONObject)brand).getString("id"));
item.setItemUrl(((JSONObject)brand).getString("brand_logo"));
itemList.add(item);
}
brandFilterItem.setItemList(itemList);
filterItems.add(brandFilterItem);
}
resp.setFilter(filterItems);
}
}
return resp;
}
@Override
public SortIdLevel getSortLevelById(String sortId) {
SortIdLevel sortIdLevel = new SortIdLevel();
if (StringUtils.isNotBlank(sortId)) {
... ...