Authored by wangnan9279

Merge branch 'wn_ufosalecalendar' into gray0125

@@ -170,6 +170,9 @@ public class SearchRequestParams { @@ -170,6 +170,9 @@ public class SearchRequestParams {
170 public static final String PARAM_SEARCH_CONTAIN_UFO = "contain_ufo"; 170 public static final String PARAM_SEARCH_CONTAIN_UFO = "contain_ufo";
171 // 是否只过滤UFO 171 // 是否只过滤UFO
172 public static final String PARAM_SEARCH_IS_UFO = "is_ufo"; 172 public static final String PARAM_SEARCH_IS_UFO = "is_ufo";
  173 + // ufo日历开始结束时间
  174 + public static final String UFO_PARAM_STRAT_TIME = "startTime";
  175 + public static final String UFO_PARAM_END_TIME = "endTime";
173 176
174 177
175 //Collage index 178 //Collage index
@@ -6,12 +6,12 @@ import com.yoho.search.base.utils.DateUtil; @@ -6,12 +6,12 @@ import com.yoho.search.base.utils.DateUtil;
6 import com.yoho.search.base.utils.ISearchConstants; 6 import com.yoho.search.base.utils.ISearchConstants;
7 import com.yoho.search.base.utils.UfoProductIndexEsField; 7 import com.yoho.search.base.utils.UfoProductIndexEsField;
8 import com.yoho.search.common.SearchCommonService; 8 import com.yoho.search.common.SearchCommonService;
  9 +import com.yoho.search.common.SearchRequestParams;
9 import com.yoho.search.core.es.model.SearchParam; 10 import com.yoho.search.core.es.model.SearchParam;
10 import com.yoho.search.core.es.model.SearchResult; 11 import com.yoho.search.core.es.model.SearchResult;
11 import com.yoho.search.models.SearchApiResult; 12 import com.yoho.search.models.SearchApiResult;
12 import com.yoho.search.service.index.UfoProductIndexBaseService; 13 import com.yoho.search.service.index.UfoProductIndexBaseService;
13 import org.apache.commons.collections.MapUtils; 14 import org.apache.commons.collections.MapUtils;
14 -import org.apache.commons.lang.StringUtils;  
15 import org.elasticsearch.index.query.BoolQueryBuilder; 15 import org.elasticsearch.index.query.BoolQueryBuilder;
16 import org.elasticsearch.index.query.QueryBuilders; 16 import org.elasticsearch.index.query.QueryBuilders;
17 import org.elasticsearch.search.sort.SortBuilder; 17 import org.elasticsearch.search.sort.SortBuilder;
@@ -46,22 +46,13 @@ public class UfoSaleCalendarService { @@ -46,22 +46,13 @@ public class UfoSaleCalendarService {
46 @SearchCacheAble(cacheName = "UFO_SALE_CALENDAR_PRODUCT_LIST", cacheInMinute = 3) 46 @SearchCacheAble(cacheName = "UFO_SALE_CALENDAR_PRODUCT_LIST", cacheInMinute = 3)
47 public SearchApiResult SaleCalendarProductList(Map<String, String> paramMap) { 47 public SearchApiResult SaleCalendarProductList(Map<String, String> paramMap) {
48 try { 48 try {
49 - // 参数校验  
50 - int pageSize = StringUtils.isBlank(paramMap.get("viewNum")) ? 10 : Integer.parseInt(paramMap.get("viewNum"));  
51 - int page = StringUtils.isBlank(paramMap.get("page")) ? 1 : Integer.parseInt(paramMap.get("page"));  
52 - if (page < 1 || pageSize < 0 || page * pageSize > 1000000) {  
53 - return new SearchApiResult().setCode(400).setMessage("分页参数不合法");  
54 - }  
55 - if (pageSize > 100) {  
56 - pageSize = 100;  
57 - }  
58 // 构建SearchParam 49 // 构建SearchParam
59 SearchParam searchParam = new SearchParam(); 50 SearchParam searchParam = new SearchParam();
60 - searchParam.setSize(pageSize);  
61 - searchParam.setOffset((page - 1) * pageSize); 51 + searchParam.setSize(1000);
  52 + searchParam.setOffset(0);
62 searchParam.setAggregationBuilders(null); 53 searchParam.setAggregationBuilders(null);
63 // 过滤 54 // 过滤
64 - searchParam.setFiter(constructSaleCalendarFilterBuilder()); 55 + searchParam.setFiter(constructSaleCalendarFilterBuilder(paramMap));
65 // 设置排序字段 56 // 设置排序字段
66 List<SortBuilder<?>> sortBuilder = new ArrayList<>(); 57 List<SortBuilder<?>> sortBuilder = new ArrayList<>();
67 sortBuilder.add(SortBuilders.fieldSort(UfoProductIndexEsField.saleTime).order(SortOrder.ASC)); 58 sortBuilder.add(SortBuilders.fieldSort(UfoProductIndexEsField.saleTime).order(SortOrder.ASC));
@@ -74,11 +65,7 @@ public class UfoSaleCalendarService { @@ -74,11 +65,7 @@ public class UfoSaleCalendarService {
74 // 构造返回结果 65 // 构造返回结果
75 List<Map<String, Object>> returnInfoList = buildSaleCalendarProductReturnInfoList(searchResult.getResultList()); 66 List<Map<String, Object>> returnInfoList = buildSaleCalendarProductReturnInfoList(searchResult.getResultList());
76 JSONObject dataMap = new JSONObject(); 67 JSONObject dataMap = new JSONObject();
77 - dataMap.put("month", getThisMonth());  
78 dataMap.put("total", searchResult.getTotal()); 68 dataMap.put("total", searchResult.getTotal());
79 - dataMap.put("page", searchResult.getPage());  
80 - dataMap.put("page_size", pageSize);  
81 - dataMap.put("page_total", searchResult.getTotalPage());  
82 dataMap.put(RETURN_LIST_NAME, returnInfoList); 69 dataMap.put(RETURN_LIST_NAME, returnInfoList);
83 return new SearchApiResult().setData(dataMap); 70 return new SearchApiResult().setData(dataMap);
84 } catch (Exception e) { 71 } catch (Exception e) {
@@ -87,14 +74,16 @@ public class UfoSaleCalendarService { @@ -87,14 +74,16 @@ public class UfoSaleCalendarService {
87 } 74 }
88 } 75 }
89 76
90 - private BoolQueryBuilder constructSaleCalendarFilterBuilder() throws Exception { 77 + private BoolQueryBuilder constructSaleCalendarFilterBuilder(Map<String, String> paramMap) throws Exception {
91 BoolQueryBuilder boolFilter = QueryBuilders.boolQuery(); 78 BoolQueryBuilder boolFilter = QueryBuilders.boolQuery();
92 //硬过滤 79 //硬过滤
93 boolFilter.must(QueryBuilders.termQuery(UfoProductIndexEsField.delStatus, 0)); 80 boolFilter.must(QueryBuilders.termQuery(UfoProductIndexEsField.delStatus, 0));
94 boolFilter.must(QueryBuilders.termQuery(UfoProductIndexEsField.shelveStatus, 1)); 81 boolFilter.must(QueryBuilders.termQuery(UfoProductIndexEsField.shelveStatus, 1));
95 //发售时间过滤 82 //发售时间过滤
96 - boolFilter.must(QueryBuilders.rangeQuery(UfoProductIndexEsField.saleTime).gte(DateUtil.getCurrentMonthStartTime()));  
97 - boolFilter.must(QueryBuilders.rangeQuery(UfoProductIndexEsField.saleTime).lte(DateUtil.getCurrentMonthEndTime())); 83 + int startTime = MapUtils.getIntValue(paramMap, SearchRequestParams.UFO_PARAM_STRAT_TIME, 0);
  84 + int endTime = MapUtils.getIntValue(paramMap, SearchRequestParams.UFO_PARAM_END_TIME, 0);
  85 + boolFilter.must(QueryBuilders.rangeQuery(UfoProductIndexEsField.saleTime).gte(startTime));
  86 + boolFilter.must(QueryBuilders.rangeQuery(UfoProductIndexEsField.saleTime).lte(endTime));
98 return boolFilter; 87 return boolFilter;
99 } 88 }
100 89
@@ -116,17 +105,7 @@ public class UfoSaleCalendarService { @@ -116,17 +105,7 @@ public class UfoSaleCalendarService {
116 Integer saleTime = MapUtils.getInteger(map, UfoProductIndexEsField.saleTime, 0); 105 Integer saleTime = MapUtils.getInteger(map, UfoProductIndexEsField.saleTime, 0);
117 String month = DateUtil.TimeStamp2DateWithFormat(Long.valueOf(saleTime), "MM"); 106 String month = DateUtil.TimeStamp2DateWithFormat(Long.valueOf(saleTime), "MM");
118 String day = DateUtil.TimeStamp2DateWithFormat(Long.valueOf(saleTime), "dd"); 107 String day = DateUtil.TimeStamp2DateWithFormat(Long.valueOf(saleTime), "dd");
119 - productMap.put("sale_time_month", month);  
120 - productMap.put("sale_time_day", day); 108 + productMap.put("sale_time", month + "." + day);
121 return productMap; 109 return productMap;
122 } 110 }
123 -  
124 - private String getThisMonth() {  
125 - long monthBeginTime = DateUtil.getCurrentMonthStartTime();  
126 - String month = DateUtil.TimeStamp2DateWithFormat(monthBeginTime, "MM");  
127 - if (month.charAt(0) == '0') {  
128 - return month.charAt(1) + "";  
129 - }  
130 - return month;  
131 - }  
132 } 111 }