ReducePriceSceneService.java
2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package com.yoho.search.service.scene;
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yoho.search.base.utils.DateUtil;
import com.yoho.search.base.utils.SearchPageIdDefine;
import com.yoho.search.common.utils.SearchApiResultUtils;
import com.yoho.search.core.es.agg.IAggregation;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.common.SearchRequestParams;
import com.yoho.search.service.scene.common.AbstractSceneService;
import com.yoho.search.service.scene.list.ProductListSwitchService;
import com.yoho.search.service.scene.aggregations.SceneSelectionsService;
@Service
public class ReducePriceSceneService extends AbstractSceneService {
private static final Logger logger = LoggerFactory.getLogger(ReducePriceSceneService.class);
@Autowired
private ProductListSwitchService sceneProductListService;
@Autowired
private SceneSelectionsService sceneSelectionsService;
@Override
public String pageId() {
return SearchPageIdDefine.PAGE_ID_REDUCE_PRICE;
}
@Override
public void addParamsToParamMap(Map<String, String> paramMap) {
super.addDefaultParamsToParamMap(paramMap);
// 默认打折
paramMap.put(SearchRequestParams.PARAM_SEARCH_ISDISCOUNT, "Y");
// 默认一周降价
long end = DateUtil.getLastTimeSecond(new Date());
long begin = DateUtil.getFirstTimeSecond(DateUtil.addDay(new Date(), -7));
paramMap.put(SearchRequestParams.PARAM_SEARCH_PRICE_UPDATE_TIME, begin + "," + end);
}
@Override
public SearchApiResult productList(Map<String, String> paramMap) {
try {
// 1、添加默认参数
this.addParamsToParamMap(paramMap);
// 2、返回商品列表
return sceneProductListService.productList(paramMap);
} catch (Exception e) {
logger.error("[func=NewArrivalProductList][params=" + paramMap + "]", e);
return SearchApiResultUtils.errorSearchApiResult("NewArrivalProductList", paramMap, e);
}
}
@Override
public SearchApiResult aggregations(Map<String, String> paramMap) {
try {
// 1、添加默认参数
this.addParamsToParamMap(paramMap);
// 2、返回聚合结果
List<IAggregation> aggregation = sceneSelectionsService.getReducePriceAggregations(paramMap);
return sceneSelectionsService.aggregations(paramMap, aggregation);
} catch (Exception e) {
logger.error("[func=NewArrivalAggregations][params=" + paramMap + "]", e);
return SearchApiResultUtils.errorSearchApiResult("NewArrivalAggregations", paramMap, e);
}
}
}