ChannelServiceImpl.java
8.86 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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
package com.cnlive.shenhe.serviceImpl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.cnlive.shenhe.dto.ChannelDTO;
import com.cnlive.shenhe.entity.ShyChannel;
import com.cnlive.shenhe.entity.ShyUsers;
import com.cnlive.shenhe.mapper.ShyChannelMapper;
import com.cnlive.shenhe.mapper.ShyUsersMapper;
import com.cnlive.shenhe.utils.AuditPass;
import com.cnlive.shenhe.utils.CommonConst;
import com.cnlive.shenhe.utils.CommonUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.session.RowBounds;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import java.util.List;
/**
* @Auther: chenhao
* @Date: 2018/12/4 17:30
* @Description:
*/
@Service
public class ChannelServiceImpl {
private static Logger logger = LoggerFactory.getLogger(ChannelServiceImpl.class);
@Autowired
ShyChannelMapper shyChannelMapper;
@Autowired
ShyUsersMapper shyUsersMapper;
@Autowired
AuditPass pass;
@Autowired
SitesServiceImpl sitesService;
/**
* 根据条件查询频道集合
*
* @param shyChannel
* @return
*/
public List<ShyChannel> findshyChannel(ShyChannel shyChannel) {
return shyChannelMapper.selectByRowBounds(shyChannel, new RowBounds(0, 100));
}
/**
* 修改频道 返回布尔类型
*
* @param shyChannel
* @return
*/
public boolean updateshyChannel(ShyChannel shyChannel) {
int result = shyChannelMapper.updateByPrimaryKey(shyChannel);
if (result == 0) {
return false;
}
return true;
}
/**
* 导入频道 返回布尔类型
*
* @param shyChannel
* @return
*/
public boolean impotChannel(ShyChannel shyChannel) {
int result = shyChannelMapper.insertSelective(shyChannel);
if (result == 0) {
return false;
}
return true;
}
/**
* 获取分页、条件查询结果集
*
* @param channelDTO
* @return
*/
public PageInfo<ShyChannel> getPage(ChannelDTO channelDTO) {
logger.info("接受参数对象为,ChannelDTO:{}", JSON.toJSONString(channelDTO));
Example example = new Example(ShyChannel.class);
Example.Criteria criteria = example.createCriteria();
if (CommonUtils.isNotEmpty(channelDTO.getOrderByClause())) {
example.setOrderByClause(channelDTO.getOrderByClause());
} else {
example.setOrderByClause("created_at desc");
}
if (CommonUtils.isNotEmpty(channelDTO.getStart_date())) {
criteria.andGreaterThanOrEqualTo("created_at", channelDTO.getStart_date());
}
if (CommonUtils.isNotEmpty(channelDTO.getEnd_date())) {
criteria.andLessThanOrEqualTo("created_at", channelDTO.getEnd_date());
}
if (CommonUtils.isNotEmpty(channelDTO.getChannel_name())) {
criteria.andLike("channel_name", "%" + channelDTO.getChannel_name() + "%");
}
if (CommonUtils.isNotEmpty(channelDTO.getUpdater())) {
criteria.andEqualTo("updater", channelDTO.getUpdater());
}
if (CommonUtils.isNotNull(channelDTO.getSpid())) {
criteria.andEqualTo("sp_id", channelDTO.getSpid());
}
if (CommonUtils.isNotEmpty(channelDTO.getChannel_id())) {
criteria.andLike("channel_id", "%" + channelDTO.getChannel_id() + "%");
}
//已认领 加上用户id
if (CommonUtils.isNotNull(channelDTO.getReceive()) && channelDTO.getReceive() == 1) {
criteria.andEqualTo("auditor", channelDTO.getUserId());
}
//不是 我的已审 进来的,只查一种状态
if (CommonUtils.isNotNull(channelDTO.getShenhe_status()) && channelDTO.getShenhe_status() != 3) {
criteria.andEqualTo("shenhe_status", channelDTO.getShenhe_status());
//是 我的已审,查通过和拒绝的两种状态
} else if (CommonUtils.isNotNull(channelDTO.getShenhe_status()) && channelDTO.getShenhe_status() == 3) {
criteria.andBetween("shenhe_status", CommonConst.AUDIT_SUCCESS, CommonConst.AUDIT_REFUSE);
}
PageHelper.startPage(channelDTO.getPage(), channelDTO.getPageSize(), true);
List<ShyChannel> channelList = shyChannelMapper.selectByExample(example);
PageInfo<ShyChannel> pageInfo = new PageInfo<>(channelList);
return pageInfo;
}
/**
* 获取频道详情
*
* @param id
* @return
*/
public ShyChannel getDetailsChannel(Integer id) {
ShyChannel comment = shyChannelMapper.selectByPrimaryKey(id);
if (!comment.getShenhe_status().equals(CommonConst.AUDIT_INTT)) {
String updater = CommonUtils.isEmpty(comment.getUpdater()) || "null".equals(comment.getUpdater()) ? "白名单" : comment.getUpdater();
String auditorId = comment.getAuditor();
if (CommonUtils.isNotEmpty(auditorId)) {
ShyUsers user = new ShyUsers();
user.setUser_id(auditorId);
user = shyUsersMapper.selectOne(user);
String email = CommonUtils.isEmpty(user.getEmail()) || "null".equals(user.getEmail()) ? "" : user.getEmail();
String userName = CommonUtils.isEmpty(user.getUsername()) ? email : user.getUsername();
updater = userName;
}
comment.setUpdater(updater);
}
return comment;
}
/**
* 修改频道状态
*
* @param ids
* @param state
* @param userId
* @param updater
* @param msg
* @return
*/
public boolean updateState(String ids, Integer state, String userId, String updater, String msg) {
boolean success = true;
String[] channelIds = ids.split(",");
for (String channelId : channelIds) {
ShyChannel channel = shyChannelMapper.selectByPrimaryKey(Integer.parseInt(channelId));
JSONObject json = new JSONObject();
json.put("state", state + 2);
json.put("channel_id", channel.getChannel_id());
json.put("msg", msg);
JSONObject result;
try {
result = pass.channelPass(json, channel.getCallback());
} catch (Exception e) {
logger.error("频道回调失败,id:{},channel_id:{}", channel.getId(), channel.getChannel_id());
success = false;
break;
}
if (result == null) {
logger.error("频道回调错误,且无返回信息。id:{},channel_id:{}", channel.getId(), channel.getChannel_id());
success = false;
break;
} else {
Integer code = result.getInteger("errorCode");
if (code != 0) {
logger.error("频道回调错误,id:{},channel_id:{},errorCode:{},errorMessage:{}", channel.getId(), channel.getChannel_id(), code, result.getString("errorMessage"));
success = false;
break;
}
channel.setShenhe_status(state);
channel.setShenhe_msg(msg);
if (CommonUtils.isEmpty(userId)) {
channel.setUpdater(updater);
channel.setAuditor(null);
} else {
channel.setAuditor(userId);
channel.setUpdater(null);
}
int i = shyChannelMapper.updateByPrimaryKey(channel);
if (i != 1) {
success = false;
}
}
}
return success;
}
/**
* 根据主键查询频道对象
*
* @param id
* @return
*/
public ShyChannel selectByPrimaryKey(Integer id) {
ShyChannel shyChannel = shyChannelMapper.selectByPrimaryKey(id);
return shyChannel;
}
/**
* 根据主键修改频道对象
*
* @param channel
* @return
*/
public int updateByPrimaryKeySelective(ShyChannel channel) {
return shyChannelMapper.updateByPrimaryKeySelective(channel);
}
/**
* 获得审核类型
*
* @param shyChannel
*/
public void getShenheType(ShyChannel shyChannel) {
//获取直播频道免审sp
List<Integer> sites = sitesService.getBusinessList(CommonConst.BUSINESS_CHANNEL);
//初始化一个审核状态
//审核类型,1:免审,2:机审,3:人工审
Integer shenheType = CommonConst.AUDIT_TYPE_USER;
//如果当前sp是免审sp
if (sites.contains(shyChannel.getSp_id())) {
//免审
shenheType = CommonConst.AUDIT_TYPE_FREE;
}
shyChannel.setShenhe_type(shenheType);
}
}