ChannelGroupRest.java
5.39 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
package com.yoho.unions.channel.restapi;
import com.yoho.service.model.union.request.ChannelGroupRequestBO;
import com.yoho.service.model.union.request.ChannelMessageRequestBO;
import com.yoho.service.model.union.request.ChannelUserRequest;
import com.yoho.service.model.union.request.UserInfoBO;
import com.yoho.service.model.union.response.PageChannelGroupRspBO;
import com.yoho.unions.channel.service.IChannelGroupService;
import com.yoho.unions.common.ApiResponse;
import org.apache.commons.lang3.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 javax.servlet.http.HttpSession;
import java.util.Map;
import static com.yoho.unions.common.utils.YHPreconditions.checkNotNull;
/**
* Created by yoho on 2017/2/15.
*/
@Controller
@RequestMapping("/channel")
public class ChannelGroupRest {
static Logger logger = LoggerFactory.getLogger(ChannelGroupRest.class);
@Autowired
private IChannelGroupService channelGroupService;
@Autowired
private HttpSession session;
@RequestMapping("/queryChannelGroupList")
@ResponseBody
public ApiResponse queryChannelGroupList( ChannelGroupRequestBO channelGroupRequestBO) {
logger.info("enter queryChannelGroupList. param channelGroupRequestBO={}", channelGroupRequestBO);
try {
PageChannelGroupRspBO pageChannelGroupRspBO = channelGroupService.queryChannelGroupList(channelGroupRequestBO);
return new ApiResponse.ApiResponseBuilder().code(200).message("成功").data(pageChannelGroupRspBO).build();
} catch (Exception e) {
logger.warn("queryChannelGroupList occurs Exception e {}",e.getMessage());
return new ApiResponse.ApiResponseBuilder().code(500).message("失败").build();
}
}
@RequestMapping("/sendMessage")
@ResponseBody
public ApiResponse sendMessage(ChannelMessageRequestBO channelGroupRequestBO,HttpSession session){
logger.info("enter sendMessage. param channelGroupRequestBO={},session={}", channelGroupRequestBO,session);
if(StringUtils.isEmpty(channelGroupRequestBO.getContent()) || channelGroupRequestBO.getGroupId()==0){
return new ApiResponse.ApiResponseBuilder().code(500).message("缺少参数").build();
}
UserInfoBO userInfoBO= (UserInfoBO) session.getAttribute("userSession");
logger.info("ChannelGroupRest.sendMessage:useinfo is {}", userInfoBO);
if(userInfoBO==null){
return new ApiResponse.ApiResponseBuilder().code(500).message("获取发送人不成功,请刷新页面!").build();
}
int result = channelGroupService.sendMessage(channelGroupRequestBO,userInfoBO.getPid());
// int result = channelGroupService.sendMessage(channelGroupRequestBO,14);
if(result==1){
return new ApiResponse.ApiResponseBuilder().code(200).message("成功").build();
}else if(result==2){
return new ApiResponse.ApiResponseBuilder().code(501).message("再次发送时间不能是当天!").build();
}
else{
return new ApiResponse.ApiResponseBuilder().code(500).message("失败").build();
}
}
/**
* 批量添加黑名单,逗号分隔手机号
* @param mobiles
* @return
*/
@RequestMapping("/addBlackList")
@ResponseBody
public ApiResponse addBlackList(String mobiles){
logger.info("enter addBlackList. param mobiles={}", mobiles);
if(StringUtils.isEmpty(mobiles)){
return new ApiResponse.ApiResponseBuilder().code(500).message("缺少参数").build();
}
channelGroupService.addBlackList(mobiles);
return new ApiResponse.ApiResponseBuilder().code(200).message("成功").build();
}
@RequestMapping("/deleteGroup")
@ResponseBody
public ApiResponse deleteGroup(int groupId){
logger.info("enter deleteGroup. param groupId={}", groupId);
if(groupId<1){
return new ApiResponse.ApiResponseBuilder().code(500).message("缺少参数").build();
}
int count = channelGroupService.deleteGroup(groupId);
if (count>0){
return new ApiResponse.ApiResponseBuilder().code(200).message("成功").build();
}else{
return new ApiResponse.ApiResponseBuilder().code(500).message("删除失败").build();
}
}
@RequestMapping("/getCondition")
@ResponseBody
public ApiResponse getCondition(String ids){
logger.info("enter getCondition. param ids={}", ids);
Map<Integer,String> result = channelGroupService.getCondition(ids);
return new ApiResponse.ApiResponseBuilder().code(200).message("成功").data(result).build();
}
/**
* 增加分组
*/
@ResponseBody
@RequestMapping("addGroup")
public ApiResponse addGroup(@RequestBody ChannelUserRequest request) {
// 设置系统管理员 ID
UserInfoBO userInfo = (UserInfoBO) session.getAttribute("userSession");
checkNotNull(userInfo, "获取当前用户信息失败,请刷新当前页面");
channelGroupService.saveGroup(request, userInfo);
return new ApiResponse.ApiResponseBuilder().build();
}
}