|
|
package com.yoho.search.service.scene.ufo;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.yoho.search.aop.cache.SearchCacheAble;
|
|
|
import com.yoho.search.base.constants.ISearchConstants;
|
|
|
import com.yoho.search.base.constants.UfoProductIndexEsField;
|
|
|
import com.yoho.search.base.utils.SearchConvertUtils;
|
|
|
import com.yoho.search.cache.CacheInMinute;
|
|
|
import com.yoho.search.common.SearchCommonService;
|
|
|
import com.yoho.search.common.UfoSearchRequestParams;
|
|
|
import com.yoho.search.common.utils.SearchApiResultUtils;
|
|
|
import com.yoho.search.core.es.model.SearchParam;
|
|
|
import com.yoho.search.core.es.model.SearchResult;
|
|
|
import com.yoho.search.models.SearchApiResult;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.collections.MapUtils;
|
|
|
import org.elasticsearch.index.query.BoolQueryBuilder;
|
|
|
import org.elasticsearch.index.query.QueryBuilders;
|
|
|
import org.elasticsearch.search.sort.SortBuilder;
|
|
|
import org.elasticsearch.search.sort.SortBuilders;
|
|
|
import org.elasticsearch.search.sort.SortOrder;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* 二手列表通用
|
|
|
*/
|
|
|
@Component
|
|
|
public class UfoSecondhandService {
|
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(UfoSecondhandService.class);
|
|
|
|
|
|
@Autowired
|
|
|
private SearchCommonService searchCommonService;
|
|
|
|
|
|
//@SearchCacheAble(cacheName = "SECONDEHAND_PRODUCT_LIST", cacheInMinute = CacheInMinute.Minute_UFO, includeParams = {"page", "viewNum", "preSaleFlag"})
|
|
|
public SearchApiResult secondHandProductList(Map<String, String> paramMap) {
|
|
|
try {
|
|
|
// 1、参数校验
|
|
|
int page = MapUtils.getIntValue(paramMap, UfoSearchRequestParams.UFO_PARAM_SEARCH_PAGE, 1);
|
|
|
int pageSize = MapUtils.getIntValue(paramMap, UfoSearchRequestParams.UFO_PARAM_SEARCH_VIEWNUM, 10);
|
|
|
pageSize = Math.min(pageSize, 100);
|
|
|
if (page < 1 || pageSize < 0 || page * pageSize > 100000) {
|
|
|
return new SearchApiResult().setCode(400).setMessage("分页参数不合法");
|
|
|
}
|
|
|
|
|
|
// 2、构造SearchParam
|
|
|
SearchParam searchParam = new SearchParam();
|
|
|
BoolQueryBuilder boolFilter = this.builderFilter(paramMap);
|
|
|
searchParam.setFiter(boolFilter);
|
|
|
searchParam.setQuery(QueryBuilders.matchAllQuery());
|
|
|
|
|
|
// 3、构建分页参数
|
|
|
searchParam.setSize(pageSize);
|
|
|
searchParam.setOffset((page - 1) * pageSize);
|
|
|
|
|
|
// 4、设置排序字段
|
|
|
searchParam.setSortBuilders(this.builderSortBuilders(paramMap));
|
|
|
|
|
|
// 5、执行搜索
|
|
|
SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_UFO_STORAGE_PRICE, searchParam);
|
|
|
List<Map<String, Object>> skupResultList = new ArrayList<>();
|
|
|
for (Map<String, Object> productEsSource : searchResult.getResultList()) {
|
|
|
skupResultList.add(this.buildSkupResult(productEsSource));
|
|
|
}
|
|
|
|
|
|
// 6、构造返回结果
|
|
|
JSONObject dataMap = new JSONObject();
|
|
|
dataMap.put("total", searchResult.getTotal());
|
|
|
dataMap.put("page", searchResult.getPage());
|
|
|
dataMap.put("page_size", pageSize);
|
|
|
dataMap.put("page_total", searchResult.getTotalPage());
|
|
|
dataMap.put("skup_list", skupResultList);
|
|
|
return new SearchApiResult().setData(dataMap);
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
return SearchApiResultUtils.defaultErrorSearchApiResult(logger, e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private Map<String, Object> buildSkupResult(Map<String, Object> map) {
|
|
|
Map<String, Object> skupResult = new HashMap<>();
|
|
|
skupResult.put("skup", MapUtils.getIntValue(map, "skup", 0));
|
|
|
skupResult.put("product_id", MapUtils.getIntValue(map, "productId", 0));
|
|
|
skupResult.put("product_name", "待处理");
|
|
|
skupResult.put("goods_id", MapUtils.getIntValue(map, "goodsId", 0));
|
|
|
skupResult.put("storage_id", MapUtils.getIntValue(map, "storageId", 0));
|
|
|
skupResult.put("seller_uid", MapUtils.getIntValue(map, "sellerUid", 0));
|
|
|
|
|
|
//价格
|
|
|
Double price = MapUtils.getDouble(map, "price");
|
|
|
skupResult.put("price", price == null || price == -1d ? null : price);
|
|
|
skupResult.put("down_price", "待处理");
|
|
|
|
|
|
skupResult.put("status", MapUtils.getIntValue(map, "status", 0));
|
|
|
skupResult.put("is_hide", MapUtils.getIntValue(map, "isHide", 0));
|
|
|
skupResult.put("pre_sale_flag", MapUtils.getIntValue(map, "preSaleFlag", 0));
|
|
|
skupResult.put("region", MapUtils.getIntValue(map, "region", 0));
|
|
|
|
|
|
//图片
|
|
|
String secondhand_image = MapUtils.getString(map, "secondhandImage","");
|
|
|
skupResult.put("secondhand_image", secondhand_image == null ? "" : secondhand_image);
|
|
|
|
|
|
//尺码
|
|
|
Integer size_id = MapUtils.getIntValue(map, "sizeId",0);
|
|
|
skupResult.put("size_id", size_id == null || size_id<=0 ? 0 : size_id);
|
|
|
String sizeName = MapUtils.getString(map, "sizeName","");
|
|
|
skupResult.put("size_name", sizeName == null ? "" : sizeName);
|
|
|
return skupResult;
|
|
|
|
|
|
}
|
|
|
|
|
|
private BoolQueryBuilder builderFilter(Map<String, String> paramMap) {
|
|
|
BoolQueryBuilder filter = QueryBuilders.boolQuery();
|
|
|
List<Integer> preSaleFlags = SearchConvertUtils.stringToIntList(MapUtils.getString(paramMap, "preSaleFlag"), ",");
|
|
|
if (CollectionUtils.isNotEmpty(preSaleFlags)) {
|
|
|
filter.must(QueryBuilders.termsQuery("preSaleFlag", preSaleFlags));
|
|
|
} else {
|
|
|
filter.must(QueryBuilders.termsQuery("preSaleFlag", Arrays.asList(5, 6)));
|
|
|
}
|
|
|
filter.must(QueryBuilders.termQuery("isHide", 0));
|
|
|
filter.must(QueryBuilders.termQuery("status", 1));
|
|
|
return filter;
|
|
|
}
|
|
|
|
|
|
private List<SortBuilder<?>> builderSortBuilders(Map<String, String> paramMap) {
|
|
|
List<SortBuilder<?>> sortList = new ArrayList<>();
|
|
|
sortList.add(SortBuilders.fieldSort("id").order(SortOrder.DESC));
|
|
|
return sortList;
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|