NotspeakServiceImpl.java
13.1 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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
package com.cnlive.shenhe.service.serviceImpl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.cnlive.shenhe.bean.ResponseBean;
import com.cnlive.shenhe.dto.NotSpeakDTO;
import com.cnlive.shenhe.entity.ShyComments;
import com.cnlive.shenhe.entity.ShyNotspeak;
import com.cnlive.shenhe.mapper.ShyCommentsMapper;
import com.cnlive.shenhe.mapper.ShyNotspeakMapper;
import com.cnlive.shenhe.service.NotspeakService;
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.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import java.util.List;
/**
* @author Administrator
* @Date: 2019/1/2 11:30
* @Description:
*/
@Service
public class NotspeakServiceImpl implements NotspeakService {
private static Logger logger = LoggerFactory.getLogger(NotspeakServiceImpl.class);
@Autowired
ShyCommentsMapper shyCommentsMapper;
@Autowired
ShyNotspeakMapper shyNotspeakMapper;
@Autowired
AuditPass pass;
@Value("${speak_comment}")
String speak_comment;
/**
* 根据条件获取禁言集合列表
*
* @param shyNotspeak
* @return
*/
@Override
public List<ShyNotspeak> findShyNotSpeak(ShyNotspeak shyNotspeak) {
return shyNotspeakMapper.selectByRowBounds(shyNotspeak, new RowBounds(0, 100));
}
/**
* 根据主键修改禁言 返回布尔类型
*
* @param shyNotspeak
* @return
*/
@Override
public boolean updateShyNotSpeak(ShyNotspeak shyNotspeak) {
int result = shyNotspeakMapper.updateByPrimaryKey(shyNotspeak);
return result != 0;
}
/**
* 导入禁言对象 返货布尔类型
*
* @param shyNotspeak
* @return
*/
@Override
public boolean impotShyNotSpeak(ShyNotspeak shyNotspeak) {
int result = shyNotspeakMapper.insertSelective(shyNotspeak);
return result != 0;
}
/**
* 根据评论禁言
*
* @param commentId
* @param time
* @param userId
* @return
*/
@Override
public ResponseBean notSpeakByComment(Integer commentId, Integer time, String userId) {
ResponseBean success;
ShyComments comment = shyCommentsMapper.selectByPrimaryKey(commentId);
JSONObject json = new JSONObject();
json.put("sid", comment.getComment_user_id().toString());
json.put("type", CommonConst.SPEAK_NOT);
json.put("minute", time);
JSONObject result = new JSONObject();
try {
result = pass.commentSpeak(json, speak_comment);
} catch (Exception e) {
logger.error("评论禁言失败,comments_id:{}", comment.getId());
success = new ResponseBean(500, "评论禁言调用互动云服务器失败!");
return success;
}
if (result == null) {
logger.error("评论禁言错误,且无返回信息。comments_id:{}", comment.getId());
success = new ResponseBean(500, "评论禁言调用互动云返回结果为空!");
return success;
} else {
Integer errorCode = result.getInteger("errorCode");
String errorMessage = result.getString("errorMessage");
if (errorCode != 0) {
logger.error("评论禁言错误,comments_id:{},errorCode:{},errorMessage:{}", comment.getId(), errorCode, errorMessage);
success = new ResponseBean(500, "评论禁言调用互动云返回结果errorCode不为0!");
return success;
}
comment.setState(CommonConst.AUDIT_REFUSE);
comment.setMsg("评论禁言操作");
comment.setAuditor_id(userId);
//已领取
comment.setReceive(1);
comment.setReceive_user_id(userId);
int i = shyCommentsMapper.updateByPrimaryKeySelective(comment);
if (i != 1) {
success = new ResponseBean(500, "评论禁言修改当前评论数据失败!");
return success;
}
boolean res = writeNotSpeakByComment(commentId, time, userId);
if (!res) {
success = new ResponseBean(500, "评论禁言修改禁言表失败!");
return success;
}
}
return new ResponseBean();
}
/**
* 查询禁言状态
*
* @param commentId
* @param userId
* @return
*/
@Override
public ResponseBean querySpeakState(Integer commentId, String userId) {
ShyComments comment = shyCommentsMapper.selectByPrimaryKey(commentId);
ShyNotspeak shyNotspeak = new ShyNotspeak();
shyNotspeak.setUser_id(comment.getComment_user_id());
shyNotspeak.setState(CommonConst.SPEAK_NOT);
List<ShyNotspeak> shyNotspeakList = findShyNotSpeak(shyNotspeak);
if (shyNotspeakList.size() > 0) {
shyNotspeak = shyNotspeakList.get(0);
return new ResponseBean(500, "当前用户已被禁言,禁言剩余时长:" + (shyNotspeak.getEnd_time().getTime() - System.currentTimeMillis()) / (1000 * 60) + "分钟,解禁时间:" + CommonUtils.formatDate(shyNotspeak.getEnd_time(), "yyyy-MM-dd HH:mm:ss"));
}
return new ResponseBean();
}
/**
* 禁言回调
*
* @param notSpeakId
* @param type
* @param time
* @param userId
* @return
*/
@Override
public ResponseBean speak(Integer notSpeakId, Integer type, Integer time, String userId) {
ResponseBean success;
ShyNotspeak shyNotspeak = selectByPrimaryKey(notSpeakId);
JSONObject json = new JSONObject();
json.put("sid", shyNotspeak.getUser_id().toString());
json.put("type", type);
json.put("minute", time);
JSONObject result = new JSONObject();
try {
result = pass.commentSpeak(json, speak_comment);
} catch (Exception e) {
logger.error("评论禁言失败,shyNotspeak_id:{}", shyNotspeak.getId());
success = new ResponseBean(500, "评论禁言调用互动云服务器失败!");
return success;
}
if (result == null) {
logger.error("评论禁言错误,且无返回信息。shyNotspeak_id:{}", shyNotspeak.getId());
success = new ResponseBean(500, "评论禁言调用互动云返回结果为空!");
return success;
} else {
Integer errorCode = result.getInteger("errorCode");
String errorMessage = result.getString("errorMessage");
if (errorCode != 0) {
logger.error("评论禁言错误,shyNotspeak_id:{},errorCode:{},errorMessage:{}", shyNotspeak.getId(), errorCode, errorMessage);
success = new ResponseBean(500, "评论禁言调用互动云返回结果errorCode不为0!");
return success;
}
String msg = CommonUtils.getCurrentDate("yyyy-MM-dd HH:mm:ss") + "解除禁言";
shyNotspeak.setState(type);
if (type.equals(CommonConst.SPEAK_NOT)) {
shyNotspeak.setStart_time(CommonUtils.getCurrentTime());
shyNotspeak.setTime(time);
shyNotspeak.setEnd_time(CommonUtils.getAddTime(time));
shyNotspeak.setCount(shyNotspeak.getCount() + 1);
msg = CommonUtils.getCurrentDate("yyyy-MM-dd HH:mm:ss") + "开始禁言,禁言时长为" + time + "分钟,禁言管理里面禁言的";
}
if (CommonUtils.isNotEmpty(userId)) {
shyNotspeak.setAuditor(userId);
shyNotspeak.setUpdater("");
} else {
shyNotspeak.setAuditor(null);
shyNotspeak.setUpdater("自动解除");
}
shyNotspeak.setUpdated_at(CommonUtils.getCurrentTime());
shyNotspeak.setMsg(shyNotspeak.getMsg() + "\n" + msg);
boolean res = updateShyNotSpeak(shyNotspeak);
if (!res) {
success = new ResponseBean(500, "评论禁言修改禁言表失败!");
return success;
}
}
return new ResponseBean();
}
/**
* 根据评论进行禁言
*
* @param commentId
* @param time
* @param userId
* @return
*/
@Override
public boolean writeNotSpeakByComment(Integer commentId, Integer time, String userId) {
boolean result = false;
ShyComments comment = shyCommentsMapper.selectByPrimaryKey(commentId);
ShyNotspeak shyNotspeak = new ShyNotspeak();
shyNotspeak.setUser_id(comment.getComment_user_id());
String msg = CommonUtils.getCurrentDate("yyyy-MM-dd HH:mm:ss") + "开始禁言,禁言时长为" + time + "分钟,禁言的评论为:'" + comment.getComment_content() + "'";
List<ShyNotspeak> shyNotspeakList = shyNotspeakMapper.select(shyNotspeak);
if (CommonUtils.isNotNull(shyNotspeakList) && shyNotspeakList.size() > 0) {
ShyNotspeak notspeak = shyNotspeakList.get(0);
notspeak.setUser_name(comment.getComment_user_name());
notspeak.setUser_avatar(comment.getComment_user_avatar());
notspeak.setSp_id(comment.getSpid());
notspeak.setState(CommonConst.SPEAK_NOT);
notspeak.setStart_time(CommonUtils.getCurrentTime());
notspeak.setTime(time);
notspeak.setEnd_time(CommonUtils.getAddTime(time));
notspeak.setUpdated_at(CommonUtils.getCurrentTime());
notspeak.setMsg(notspeak.getMsg() + "\n" + msg);
notspeak.setCount(notspeak.getCount() + 1);
notspeak.setUpdater("");
notspeak.setAuditor(userId);
result = updateShyNotSpeak(notspeak);
} else {
shyNotspeak.setUser_name(comment.getComment_user_name());
shyNotspeak.setUser_id(comment.getComment_user_id());
shyNotspeak.setUser_avatar(comment.getComment_user_avatar());
shyNotspeak.setSp_id(comment.getSpid());
shyNotspeak.setState(CommonConst.SPEAK_NOT);
shyNotspeak.setStart_time(CommonUtils.getCurrentTime());
shyNotspeak.setTime(time);
shyNotspeak.setEnd_time(CommonUtils.getAddTime(time));
shyNotspeak.setCreated_at(CommonUtils.getCurrentTime());
shyNotspeak.setUpdated_at(CommonUtils.getCurrentTime());
shyNotspeak.setMsg(msg);
shyNotspeak.setCount(1);
shyNotspeak.setUpdater("");
shyNotspeak.setAuditor(userId);
result = impotShyNotSpeak(shyNotspeak);
}
return result;
}
/**
* 获取禁言分页、条件查询列表
*
* @param notSpeakDTO
* @return
*/
@Override
public PageInfo<ShyNotspeak> getPage(NotSpeakDTO notSpeakDTO) {
logger.info("接受参数对象为,NotSpeakDTO:{}", JSON.toJSONString(notSpeakDTO));
Example example = new Example(ShyNotspeak.class);
Example.Criteria criteria = example.createCriteria();
if (CommonUtils.isNotEmpty(notSpeakDTO.getOrderByClause())) {
example.setOrderByClause(notSpeakDTO.getOrderByClause());
} else {
example.setOrderByClause("state desc , updated_at desc");
}
if (CommonUtils.isNotEmpty(notSpeakDTO.getUser_name())) {
criteria.andLike("user_name", "%" + notSpeakDTO.getUser_name() + "%");
}
if (CommonUtils.isNotNull(notSpeakDTO.getUser_id())) {
criteria.andEqualTo("user_id", notSpeakDTO.getUser_id());
}
if (CommonUtils.isNotNull(notSpeakDTO.getState())) {
criteria.andEqualTo("state", notSpeakDTO.getState());
}
PageHelper.startPage(notSpeakDTO.getPage(), notSpeakDTO.getPageSize(), true);
List<ShyNotspeak> shyNotspeakList = shyNotspeakMapper.selectByExample(example);
PageInfo<ShyNotspeak> pageInfo = new PageInfo<>(shyNotspeakList);
return pageInfo;
}
/**
* 根据主键id查询禁言对象
*
* @param id
* @return
*/
@Override
public ShyNotspeak selectByPrimaryKey(Integer id) {
return shyNotspeakMapper.selectByPrimaryKey(id);
}
/**
* 根据主键修改禁言对象
*
* @param shyNotspeak
* @return
*/
@Override
public int updateByPrimaryKeySelective(ShyNotspeak shyNotspeak) {
return shyNotspeakMapper.updateByPrimaryKeySelective(shyNotspeak);
}
/**
* 获取禁言时间
*
* @return
*/
@Override
public List<ShyNotspeak> getNotSpeakByTime() {
Example example = new Example(ShyNotspeak.class);
Example.Criteria criteria = example.createCriteria();
criteria.andEqualTo("state", CommonConst.SPEAK_NOT);
criteria.andLessThan("end_time", CommonUtils.getCurrentTime());
return shyNotspeakMapper.selectByExample(example);
}
}