|
|
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)) {
|
...
|
...
|
|