InBoxRest.java
7.37 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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
package com.yoho.yhmessage.inbox.restapi;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
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.ResponseBody;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yoho.core.common.restbean.ResponseBean;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yoho.message.dal.model.InBox;
import com.yoho.service.model.inbox.request.BatchInboxReqBO;
import com.yoho.service.model.inbox.request.GetListReqBO;
import com.yoho.service.model.inbox.request.InboxReqBO;
import com.yoho.service.model.inbox.request.SetIsReadRequestBO;
import com.yoho.service.model.inbox.response.GetListRespBO;
import com.yoho.service.model.inbox.response.PageResponseBO;
import com.yoho.service.model.response.CommonRspBO;
import com.yoho.yhmessage.inbox.service.IInBoxService;
import com.yoho.yhmessage.inbox.service.model.CouponInBox;
/**
* 类的描述
*
* @author CaoQi
* @Time 2015/11/11
*/
//@Controller
//@RequestMapping("/InBoxRest")
public class InBoxRest {
private static Logger logger = LoggerFactory.getLogger(InBoxRest.class);
@Autowired
private IInBoxService iInBoxService;
@RequestMapping("/queryListById")
@ResponseBody
public Map<String, Object> queryListById(@RequestBody InboxReqBO inboxReqBO) {
Integer count = iInBoxService.countById(inboxReqBO.getUid());
List<InBox> inBoxList = iInBoxService.queryListById(inboxReqBO.getUid());
Map<String, Object> result = new HashMap<>();
result.put("total", count);
result.put("list", inBoxList);
return result;
}
@RequestMapping("/getInboxCount")
@ResponseBody
public Integer getInboxCount(@RequestBody InboxReqBO inboxReqBO) {
logger.info("Begin Enter getInboxCount. inboxReqBO is {}", inboxReqBO);
// (1)判断用户id是否存在
if (null == inboxReqBO || inboxReqBO.getUid() < 1) {
logger.warn("Uid is null or 0.");
throw new ServiceException(ServiceError.SMS_INBOX_UID_NULL);
}
// (2)判断是否未读
String isRead = (null == inboxReqBO.getIsRead()) ? "N" : inboxReqBO.getIsRead();
// (2)调用服务获取inbox的数量
int count = iInBoxService.countByParam(inboxReqBO.getUid(), isRead, "N");
logger.info("End getInboxCount. inboxReqBO is {}", inboxReqBO);
return count;
}
@RequestMapping("/saveInbox")
@ResponseBody
public ResponseBean saveInbox(@RequestBody InboxReqBO inboxReqBO) {
InBox inBox = new InBox();
inBox.setUid(inboxReqBO.getUid());
inBox.setSendUid(inboxReqBO.getSendUid());
inBox.setType(StringUtils.isEmpty(inboxReqBO.getType()) ? CouponInBox.TYPE : inboxReqBO.getType());
inBox.setIsRead("N");
inBox.setIsDel("N");
inBox.setTitle(inboxReqBO.getTitle());
inBox.setCreateTime(new Date().getTime() / 1000);
inBox.setContent(inboxReqBO.getContent());
inBox.setVerifyKey(inboxReqBO.getVerifyKey());
iInBoxService.saveInbox(inBox);
ResponseBean responseBean = new ResponseBean();
responseBean.setCode("200");
responseBean.setMessage("保存成功");
return responseBean;
}
/**
* 批量发送站内信
* @param bo
* @return
*/
@RequestMapping("/insertBatch")
@ResponseBody
public CommonRspBO insertBatch(@RequestBody BatchInboxReqBO bo) throws ServiceException {
logger.info("insertBatch with bo={}", bo);
CommonRspBO response = iInBoxService.insertBatch(bo);
logger.info("insertBatch success with bo={}", bo);
return response;
}
@RequestMapping("/updateInbox")
@ResponseBody
public ResponseBean updateInbox(@RequestBody InBox inBox) {
iInBoxService.updateById(inBox);
ResponseBean responseBean = new ResponseBean();
responseBean.setCode("200");
responseBean.setMessage("更新成功");
return responseBean;
}
@RequestMapping("/delByIdsAndUid")
@ResponseBody
public ResponseBean delByIdsAndUid(@RequestBody InboxReqBO inboxReqBO) {
logger.info("Begin Enter delByIdsAndUid. InboxReqBO is {}", inboxReqBO);
if(inboxReqBO.getIds()==null){
ResponseBean responseBean = new ResponseBean();
responseBean.setCode("404");
responseBean.setMessage("message is null");
return responseBean;
}
if("".equals(inboxReqBO.getIds())){
ResponseBean responseBean = new ResponseBean();
responseBean.setCode("405");
responseBean.setMessage("id is null");
return responseBean;
}
JSONArray js = new JSONArray();
for(String i:inboxReqBO.getIds().split(",")){
JSONObject obj = new JSONObject();
obj.put("id", i);
js.add(obj);
}
iInBoxService.delByIdsAndUid(inboxReqBO.getUid(),inboxReqBO.getIds());
ResponseBean responseBean = new ResponseBean();
responseBean.setCode("200");
responseBean.setData(js);
responseBean.setMessage("success");
return responseBean;
}
/**
* 老接口,获得用户未读取的消息列表
* @param page当前第几页,size分页长度,uid用户id
*/
@RequestMapping("/messageCount")
@ResponseBody
public ResponseBean messageCount(@RequestBody GetListReqBO reqBO){
logger.info("messageCount with param is {}", reqBO);
Integer uid = reqBO.getUid();
ResponseBean responseBean = new ResponseBean();
JSONObject obj = new JSONObject();
if(uid<1){
responseBean.setCode("400");
responseBean.setMessage("Message Count");
obj.put("count",0);
responseBean.setData(obj);
return responseBean;
}
PageResponseBO<GetListRespBO> pageList = iInBoxService.getInBoxList(reqBO, true);
obj.put("count",pageList.getTotal());
// pageList.getList()
responseBean.setCode("200");
responseBean.setMessage("success");
responseBean.setData(pageList);
logger.info("messageCount success with param is {}", reqBO);
return responseBean;
}
/**
* 批量设置消息为已读
* @param req
* @return
*/
@RequestMapping("/setIsRead")
@ResponseBody
public CommonRspBO setIsRead(@RequestBody SetIsReadRequestBO req) {
logger.info("setIsRead with param is {}", req);
iInBoxService.setIsRead(req.getUid(), req.getIds());
logger.info("setIsRead success with param is {}", req);
return new CommonRspBO();
}
/**
* 获取消息列表(分页)
* 该接口用来兼容老版本app
*
* @param request
* @return
* @throws ServiceException
*/
@RequestMapping(value = "/getInBoxList")
@ResponseBody
public PageResponseBO<GetListRespBO> getInBoxList(@RequestBody GetListReqBO request) throws ServiceException {
logger.info("enter getInBoxList with param is {}", request);
PageResponseBO<GetListRespBO> pageList = iInBoxService.getInBoxList(request, true);
return pageList;
}
/**
* 获取消息列表(分页)
* 新接口
*
* @param request
* @return
* @throws ServiceException
*/
@RequestMapping(value = "/getInBoxListNew")
@ResponseBody
public PageResponseBO<GetListRespBO> getInBoxListNew(@RequestBody GetListReqBO request) throws ServiceException {
logger.info("enter getInBoxListForH5 with param is {}", request);
return iInBoxService.getInBoxList(request, false);
}
}