PromotionSceneController.java
6.27 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
package com.yoho.search.restapi.scene;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yoho.search.common.downgrade.persional.PersionalRateLimit;
import com.yoho.search.models.PromotionConditions;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.scene.promotion.PromotionSceneService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.HashMap;
import java.util.Map;
/**
* 商品详情页的促销列表接口
*
* @author gufei.hu
*/
@Controller
public class PromotionSceneController {
private static Logger PROMOTION = LoggerFactory.getLogger("PROMOTION");
private static final Logger logger = LoggerFactory.getLogger(PromotionSceneController.class);
@Autowired
private PromotionSceneService promotionService;
/**
* 促销列表接口[新]
*/
@PersionalRateLimit(isOrderUseable = true)
@RequestMapping(method = RequestMethod.POST, value = "/promotion/productList")
@ResponseBody
public SearchApiResult productList(@RequestBody JSONObject param) {
try {
PROMOTION.info("get /promotion/productList.json,params is{}", param.toJSONString());
PromotionConditions promotionConditions = this.genPromotionConditions(param);
Map<String, String> paramMap = this.genOtherParamMap(param);
return promotionService.list(promotionConditions, paramMap);
} catch (Exception e) {
logger.error(e.getMessage(), e);
return new SearchApiResult().setCode(400).setMessage("参数解析错误");
}
}
/**
* 促销列表接口[旧]
*/
@PersionalRateLimit(isOrderUseable = true, name = "/promotion/productList")
@RequestMapping(method = RequestMethod.POST, value = "/promotion/list")
@ResponseBody
public SearchApiResult list(@RequestBody JSONObject param) {
try {
PROMOTION.info("get /promotion/list.json,params is{}", param.toJSONString());
PromotionConditions promotionConditions = this.genPromotionConditions(param);
Map<String, String> paramMap = this.genOtherParamMap(param);
return promotionService.list(promotionConditions, paramMap);
} catch (Exception e) {
logger.error(e.getMessage(), e);
return new SearchApiResult().setCode(400).setMessage("参数解析错误");
}
}
/**
* 促销列表接口[新]
*/
@PersionalRateLimit(isOrderUseable = false)
@RequestMapping(method = RequestMethod.POST, value = "/promotion/aggregations")
@ResponseBody
public SearchApiResult promotionAggregations(@RequestBody JSONObject param) {
try {
PROMOTION.info("get /promotion/aggregations.json,params is{}", param.toJSONString());
PromotionConditions promotionConditions = this.genPromotionConditions(param);
Map<String, String> paramMap = this.genOtherParamMap(param);
return promotionService.aggregations(promotionConditions, paramMap);
} catch (Exception e) {
logger.error(e.getMessage(), e);
return new SearchApiResult().setCode(400).setMessage("参数解析错误");
}
}
/**
* 促销聚合接口[for app]
*/
@RequestMapping(method = RequestMethod.POST, value = "/promotion/selectionsForApp")
@ResponseBody
public SearchApiResult selectionsForApp(@RequestBody JSONObject param) {
try {
PROMOTION.info("get /promotion/selectionsForApp.json,params is{}", param.toJSONString());
PromotionConditions promotionConditions = this.genPromotionConditions(param);
Map<String, String> paramMap = this.genOtherParamMap(param);
return promotionService.selectionsForApp(promotionConditions, paramMap);
} catch (Exception e) {
logger.error(e.getMessage(), e);
return new SearchApiResult().setCode(400).setMessage("参数解析错误");
}
}
/**
* 促销聚合接口[for pc]
*/
@RequestMapping(method = RequestMethod.POST, value = "/promotion/selectionsForPc")
@ResponseBody
public SearchApiResult selectionsForPc(@RequestBody JSONObject param) {
try {
PROMOTION.info("get /promotion/selectionsForPc.json,params is{}", param.toJSONString());
PromotionConditions promotionConditions = this.genPromotionConditions(param);
Map<String, String> paramMap = this.genOtherParamMap(param);
return promotionService.selectionsForPc(promotionConditions, paramMap);
} catch (Exception e) {
logger.error(e.getMessage(), e);
return new SearchApiResult().setCode(400).setMessage("参数解析错误");
}
}
/**
* 促销聚合品牌的接口
* @return
*/
@RequestMapping(method = RequestMethod.POST, value = "/promotion/aggBrands")
@ResponseBody
public SearchApiResult aggBrands(@RequestBody JSONObject param) {
try {
PROMOTION.info("get /promotion/aggBrands.json,params is{}", param.toJSONString());
PromotionConditions promotionConditions = this.genPromotionConditions(param);
Map<String, String> paramMap = this.genOtherParamMap(param);
return promotionService.aggPromotionBrands(promotionConditions, paramMap);
} catch (Exception e) {
logger.error(e.getMessage(), e);
return new SearchApiResult().setCode(400).setMessage("参数解析错误");
}
}
@RequestMapping(method = RequestMethod.POST, value = "/promotion/selections")
@ResponseBody
public SearchApiResult selections(@RequestBody JSONObject param) {
return selectionsForApp(param);
}
private PromotionConditions genPromotionConditions(JSONObject param) {
try {
JSONObject jsonObject = param.getJSONObject("promotion_condition");
if (jsonObject == null) {
return null;
}
return JSON.parseObject(jsonObject.toJSONString(), PromotionConditions.class);
} catch (Exception e) {
logger.error(e.getMessage(), e);
return null;
} finally {
// param.remove("promotion_condition");
}
}
private Map<String, String> genOtherParamMap(JSONObject param) {
Map<String, String> map = new HashMap<String, String>();
for (Map.Entry<String, Object> entry : param.entrySet()) {
try {
Object value = entry.getValue();
String valueString = value == null ? null : value.toString();
map.put(entry.getKey(), valueString);
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
}
return map;
}
}