Authored by wangnan9279

Merge branch 'wn_ufosalecalendar' into gray0125

... ... @@ -170,6 +170,9 @@ public class SearchRequestParams {
public static final String PARAM_SEARCH_CONTAIN_UFO = "contain_ufo";
// 是否只过滤UFO
public static final String PARAM_SEARCH_IS_UFO = "is_ufo";
// ufo日历开始结束时间
public static final String UFO_PARAM_STRAT_TIME = "startTime";
public static final String UFO_PARAM_END_TIME = "endTime";
//Collage index
... ...
... ... @@ -6,12 +6,12 @@ import com.yoho.search.base.utils.DateUtil;
import com.yoho.search.base.utils.ISearchConstants;
import com.yoho.search.base.utils.UfoProductIndexEsField;
import com.yoho.search.common.SearchCommonService;
import com.yoho.search.common.SearchRequestParams;
import com.yoho.search.core.es.model.SearchParam;
import com.yoho.search.core.es.model.SearchResult;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.index.UfoProductIndexBaseService;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.sort.SortBuilder;
... ... @@ -46,22 +46,13 @@ public class UfoSaleCalendarService {
@SearchCacheAble(cacheName = "UFO_SALE_CALENDAR_PRODUCT_LIST", cacheInMinute = 3)
public SearchApiResult SaleCalendarProductList(Map<String, String> paramMap) {
try {
// 参数校验
int pageSize = StringUtils.isBlank(paramMap.get("viewNum")) ? 10 : Integer.parseInt(paramMap.get("viewNum"));
int page = StringUtils.isBlank(paramMap.get("page")) ? 1 : Integer.parseInt(paramMap.get("page"));
if (page < 1 || pageSize < 0 || page * pageSize > 1000000) {
return new SearchApiResult().setCode(400).setMessage("分页参数不合法");
}
if (pageSize > 100) {
pageSize = 100;
}
// 构建SearchParam
SearchParam searchParam = new SearchParam();
searchParam.setSize(pageSize);
searchParam.setOffset((page - 1) * pageSize);
searchParam.setSize(1000);
searchParam.setOffset(0);
searchParam.setAggregationBuilders(null);
// 过滤
searchParam.setFiter(constructSaleCalendarFilterBuilder());
searchParam.setFiter(constructSaleCalendarFilterBuilder(paramMap));
// 设置排序字段
List<SortBuilder<?>> sortBuilder = new ArrayList<>();
sortBuilder.add(SortBuilders.fieldSort(UfoProductIndexEsField.saleTime).order(SortOrder.ASC));
... ... @@ -74,11 +65,7 @@ public class UfoSaleCalendarService {
// 构造返回结果
List<Map<String, Object>> returnInfoList = buildSaleCalendarProductReturnInfoList(searchResult.getResultList());
JSONObject dataMap = new JSONObject();
dataMap.put("month", getThisMonth());
dataMap.put("total", searchResult.getTotal());
dataMap.put("page", searchResult.getPage());
dataMap.put("page_size", pageSize);
dataMap.put("page_total", searchResult.getTotalPage());
dataMap.put(RETURN_LIST_NAME, returnInfoList);
return new SearchApiResult().setData(dataMap);
} catch (Exception e) {
... ... @@ -87,14 +74,16 @@ public class UfoSaleCalendarService {
}
}
private BoolQueryBuilder constructSaleCalendarFilterBuilder() throws Exception {
private BoolQueryBuilder constructSaleCalendarFilterBuilder(Map<String, String> paramMap) throws Exception {
BoolQueryBuilder boolFilter = QueryBuilders.boolQuery();
//硬过滤
boolFilter.must(QueryBuilders.termQuery(UfoProductIndexEsField.delStatus, 0));
boolFilter.must(QueryBuilders.termQuery(UfoProductIndexEsField.shelveStatus, 1));
//发售时间过滤
boolFilter.must(QueryBuilders.rangeQuery(UfoProductIndexEsField.saleTime).gte(DateUtil.getCurrentMonthStartTime()));
boolFilter.must(QueryBuilders.rangeQuery(UfoProductIndexEsField.saleTime).lte(DateUtil.getCurrentMonthEndTime()));
int startTime = MapUtils.getIntValue(paramMap, SearchRequestParams.UFO_PARAM_STRAT_TIME, 0);
int endTime = MapUtils.getIntValue(paramMap, SearchRequestParams.UFO_PARAM_END_TIME, 0);
boolFilter.must(QueryBuilders.rangeQuery(UfoProductIndexEsField.saleTime).gte(startTime));
boolFilter.must(QueryBuilders.rangeQuery(UfoProductIndexEsField.saleTime).lte(endTime));
return boolFilter;
}
... ... @@ -116,17 +105,7 @@ public class UfoSaleCalendarService {
Integer saleTime = MapUtils.getInteger(map, UfoProductIndexEsField.saleTime, 0);
String month = DateUtil.TimeStamp2DateWithFormat(Long.valueOf(saleTime), "MM");
String day = DateUtil.TimeStamp2DateWithFormat(Long.valueOf(saleTime), "dd");
productMap.put("sale_time_month", month);
productMap.put("sale_time_day", day);
productMap.put("sale_time", month + "." + day);
return productMap;
}
private String getThisMonth() {
long monthBeginTime = DateUtil.getCurrentMonthStartTime();
String month = DateUtil.TimeStamp2DateWithFormat(monthBeginTime, "MM");
if (month.charAt(0) == '0') {
return month.charAt(1) + "";
}
return month;
}
}
... ...