CommentsServiceImpl.java
15.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
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
package com.cnlive.shenhe.service.serviceImpl;
import com.alibaba.fastjson.JSONObject;
import com.cnlive.shenhe.dto.CommentsDTO;
import com.cnlive.shenhe.entity.ShyComments;
import com.cnlive.shenhe.entity.ShyUsers;
import com.cnlive.shenhe.mapper.ShyCommentsMapper;
import com.cnlive.shenhe.mapper.ShyUsersMapper;
import com.cnlive.shenhe.service.CommentsService;
import com.cnlive.shenhe.service.SitesService;
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 CommentsServiceImpl implements CommentsService {
private static Logger logger = LoggerFactory.getLogger(CommentsServiceImpl.class);
@Autowired
ShyCommentsMapper shyCommentsMapper;
@Autowired
ShyUsersMapper shyUsersMapper;
@Autowired
AuditPass pass;
@Autowired
SitesService sitesService;
/**
* 根据评论对象获取评论集合
*
* @param shyComments
* @return
*/
@Override
public List<ShyComments> findShyComments(ShyComments shyComments) {
return shyCommentsMapper.selectByRowBounds(shyComments, new RowBounds(0, 100));
}
/**
* 修改评论 返回布尔类型
*
* @param shyComments
* @return
*/
@Override
public boolean updateShyComments1(ShyComments shyComments) {
int result = shyCommentsMapper.updateByPrimaryKey(shyComments);
return result != 0;
}
/**
* 导入评论 返回布尔类型
*
* @param shyComments
* @return
*/
@Override
public boolean impotComments(ShyComments shyComments) {
int result = shyCommentsMapper.insertSelective(shyComments);
return result != 0;
}
/**
* 评论分页、条件查询
*
* @param commentsDTO
* @return
*/
@Override
public PageInfo<ShyComments> getPage(CommentsDTO commentsDTO) {
logger.info("接受参数对象为,CommentsDTO:{}", JSONObject.toJSON(commentsDTO));
Example example = new Example(ShyComments.class);
Example.Criteria criteria = example.createCriteria();
if (CommonUtils.isNotEmpty(commentsDTO.getOrderByClause())) {
example.setOrderByClause(commentsDTO.getOrderByClause());
} else {
example.setOrderByClause("comment_time desc");
}
if (CommonUtils.isNotEmpty(commentsDTO.getStart_date()) && CommonUtils.isNotEmpty(commentsDTO.getEnd_date())) {
criteria.andGreaterThanOrEqualTo("comment_time", commentsDTO.getStart_date());
criteria.andLessThanOrEqualTo("comment_time", commentsDTO.getEnd_date());
}
if (CommonUtils.isNotEmpty(commentsDTO.getContent())) {
criteria.andLike("comment_content", "%" + commentsDTO.getContent() + "%");
}
if (CommonUtils.isNotEmpty(commentsDTO.getUpdater())) {
criteria.andEqualTo("updater", commentsDTO.getUpdater());
}
if (CommonUtils.isNotNull(commentsDTO.getSpid())) {
criteria.andEqualTo("spid", commentsDTO.getSpid());
}
if (CommonUtils.isNotNull(commentsDTO.getIs_hot())) {
criteria.andEqualTo("is_hot", commentsDTO.getIs_hot());
}
if (CommonUtils.isNotNull(commentsDTO.getComment_user_id())) {
criteria.andEqualTo("comment_user_id", commentsDTO.getComment_user_id());
}
if (CommonUtils.isNotEmpty(commentsDTO.getType()) && Integer.parseInt(commentsDTO.getType()) == 0) {
criteria.andEqualTo("type", CommonConst.CATEGORY_TOPIC);
} else if (CommonUtils.isNotEmpty(commentsDTO.getType()) && Integer.parseInt(commentsDTO.getType()) == 1) {
criteria.andEqualTo("type", CommonConst.CATEGORY_ELSE);
}
if (CommonUtils.isNotEmpty(commentsDTO.getActivity_id())) {
criteria.andLike("activity_id", "%" + commentsDTO.getActivity_id() + "%");
}
if (CommonUtils.isNotNull(commentsDTO.getReceive())) {
criteria.andEqualTo("receive", commentsDTO.getReceive());
if (commentsDTO.getReceive().equals(CommonConst.RECEIVE_AFTER)) {
criteria.andEqualTo("receive_user_id", commentsDTO.getUserId());
}
}
if (CommonUtils.isNotNull(commentsDTO.getState()) && commentsDTO.getState() != 3) {
criteria.andEqualTo("state", commentsDTO.getState());
} else if (CommonUtils.isNotNull(commentsDTO.getState()) && commentsDTO.getState() == 3) {
criteria.andBetween("state", CommonConst.AUDIT_SUCCESS, CommonConst.AUDIT_REFUSE);
}
PageHelper.startPage(commentsDTO.getPage(), commentsDTO.getPageSize(), true);
List<ShyComments> commentsList = shyCommentsMapper.selectByExample(example);
PageInfo<ShyComments> pageInfo = new PageInfo<>(commentsList);
return pageInfo;
}
/**
* 导出Excel表格
*
* @param commentsDTO
* @return
*/
@Override
public PageInfo<ShyComments> getPageExcel(CommentsDTO commentsDTO) {
Example example = new Example(ShyComments.class);
Example.Criteria criteria = example.createCriteria();
if (CommonUtils.isNotEmpty(commentsDTO.getOrderByClause())) {
example.setOrderByClause(commentsDTO.getOrderByClause());
} else {
example.setOrderByClause("comment_time desc");
}
if (CommonUtils.isNotEmpty(commentsDTO.getStart_date()) && CommonUtils.isNotEmpty(commentsDTO.getEnd_date())) {
criteria.andGreaterThanOrEqualTo("comment_time", commentsDTO.getStart_date());
criteria.andLessThanOrEqualTo("comment_time", commentsDTO.getEnd_date());
}
if (CommonUtils.isNotEmpty(commentsDTO.getContent())) {
criteria.andLike("comment_content", "%" + commentsDTO.getContent() + "%");
}
if (CommonUtils.isNotEmpty(commentsDTO.getUpdater())) {
criteria.andEqualTo("updater", commentsDTO.getUpdater());
}
if (CommonUtils.isNotNull(commentsDTO.getSpid())) {
criteria.andEqualTo("spid", commentsDTO.getSpid());
}
if (CommonUtils.isNotNull(commentsDTO.getIs_hot())) {
criteria.andEqualTo("is_hot", commentsDTO.getIs_hot());
}
if (CommonUtils.isNotEmpty(commentsDTO.getType()) && Integer.parseInt(commentsDTO.getType()) == 0) {
criteria.andEqualTo("type", CommonConst.CATEGORY_TOPIC);
} else if (CommonUtils.isNotEmpty(commentsDTO.getType()) && Integer.parseInt(commentsDTO.getType()) == 1) {
criteria.andIsNull("type");
}
if (CommonUtils.isNotEmpty(commentsDTO.getActivity_id())) {
criteria.andLike("activity_id", "%" + commentsDTO.getActivity_id() + "%");
}
if (CommonUtils.isNotNull(commentsDTO.getReceive())) {
criteria.andEqualTo("receive", commentsDTO.getReceive());
if (commentsDTO.getReceive().equals(CommonConst.RECEIVE_AFTER)) {
criteria.andEqualTo("receive_user_id", commentsDTO.getUserId());
}
}
//不是 我的已审 进来的,只查一种状态
if (CommonUtils.isNotNull(commentsDTO.getState()) && commentsDTO.getState() != 3) {
criteria.andEqualTo("state", commentsDTO.getState());
//是 我的已审,查通过和拒绝的两种状态
} else if (CommonUtils.isNotNull(commentsDTO.getState()) && commentsDTO.getState() == 3) {
criteria.andBetween("state", CommonConst.AUDIT_SUCCESS, CommonConst.AUDIT_REFUSE);
}
List<ShyComments> commentsList = shyCommentsMapper.selectByExample(example);
PageInfo<ShyComments> pageInfo = new PageInfo<>(commentsList);
return pageInfo;
}
/**
* 获取评论详情
*
* @param id
* @return
*/
@Override
public ShyComments getDetailsComment(Integer id) {
ShyComments comment = shyCommentsMapper.selectByPrimaryKey(id);
if (!comment.getState().equals(CommonConst.AUDIT_INTT)) {
String updater = CommonUtils.isEmpty(comment.getUpdater()) || "null".equals(comment.getUpdater()) ? "白名单" : comment.getUpdater();
String auditorId = comment.getAuditor_id();
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();
updater = CommonUtils.isEmpty(user.getUsername()) ? email : user.getUsername();
}
comment.setUpdater(updater);
}
return comment;
}
/**
* 修改状态 回调 返回布尔类型
*
* @param ids
* @param state
* @param userId
* @param updater
* @param msg
* @return
*/
@Override
public boolean updateState(String ids, Integer state, String userId, String updater, String msg) {
boolean success = true;
String[] commentIds = ids.split(",");
for (String commentId : commentIds) {
ShyComments comment = shyCommentsMapper.selectByPrimaryKey(Integer.parseInt(commentId));
JSONObject json = new JSONObject();
json.put("activity_id", comment.getActivity_id());
json.put("state", state + 2);
json.put("attr_tags", "");
json.put("msg", msg);
JSONObject result = new JSONObject();
try {
result = pass.commentPass(json, comment.getCallback());
} catch (Exception e) {
logger.error("评论回调失败,activity_id:{}", comment.getActivity_id());
success = false;
break;
}
if (result == null) {
logger.error("评论回调错误,且无返回信息。activity_id:{}", comment.getActivity_id());
success = false;
break;
} else {
Integer code = result.getInteger("errorCode");
if (code != 0) {
logger.error("评论回调错误,activity_id:{},errorCode:{},errorMessage:{}", comment.getActivity_id(), code, result.getString("errorMessage"));
success = false;
break;
}
comment.setState(state);
comment.setMsg(msg);
if (CommonUtils.isEmpty(userId)) {
comment.setUpdater(updater);
} else {
comment.setAuditor_id(userId);
//已领取
comment.setReceive(1);
comment.setReceive_user_id(userId);
}
int i = shyCommentsMapper.updateByPrimaryKeySelective(comment);
if (i != 1) {
success = false;
}
}
}
return success;
}
/**
* 认领
*
* @param ids
* @param num
* @param userId
* @param spid
* @return
*/
@Override
public Integer receive(String ids, Integer num, String userId, Integer spid) {
Integer n = 0;
if (CommonUtils.isNotEmpty(ids)) {
String[] cids = ids.split(",");
for (String cid : cids) {
ShyComments shyComments = shyCommentsMapper.selectByPrimaryKey(Integer.parseInt(cid));
if (CommonUtils.isNotNull(shyComments) && shyComments.getState().equals(CommonConst.AUDIT_INTT) && shyComments.getReceive().equals(CommonConst.RECEIVE_BEFORE)) {
shyComments.setReceive_user_id(userId);
shyComments.setReceive(CommonConst.RECEIVE_AFTER);
shyCommentsMapper.updateByPrimaryKeySelective(shyComments);
n++;
}
}
} else if (CommonUtils.isNotNull(num) && num > 0) {
Example example = new Example(ShyComments.class);
example.setOrderByClause("created_at desc");
example.and().andEqualTo("state", CommonConst.AUDIT_INTT);
example.and().andEqualTo("receive", CommonConst.RECEIVE_AFTER);
if (CommonUtils.isNotNull(spid) && spid != 0) {
example.and().andEqualTo("spid", spid);
}
List<ShyComments> shyCommentsList = shyCommentsMapper.selectByExampleAndRowBounds(example, new RowBounds(0, num));
if (!shyCommentsList.isEmpty()) {
for (ShyComments shyComments : shyCommentsList) {
shyComments.setReceive_user_id(userId);
shyComments.setReceive(CommonConst.RECEIVE_AFTER);
shyCommentsMapper.updateByPrimaryKeySelective(shyComments);
n++;
}
}
}
return n;
}
/**
* 退领
*
* @param ids
* @param userId
* @return
*/
@Override
public Integer retReceive(String ids, String userId) {
Integer n = 0;
String[] cids = ids.split(",");
for (String cid : cids) {
ShyComments shyComments = shyCommentsMapper.selectByPrimaryKey(Integer.parseInt(cid));
if (shyComments.getState().equals(CommonConst.AUDIT_INTT) && shyComments.getReceive().equals(CommonConst.RECEIVE_AFTER) && userId.equals(shyComments.getReceive_user_id())) {
shyComments.setReceive(CommonConst.RECEIVE_BEFORE);
shyComments.setReceive_user_id(null);
int i = shyCommentsMapper.updateByPrimaryKeySelective(shyComments);
if (i == 1) {
n++;
}
}
}
return n;
}
/**
* 根据主键id查询评论对象
*
* @param id
* @return
*/
@Override
public ShyComments selectByPrimaryKey(Integer id) {
return shyCommentsMapper.selectByPrimaryKey(id);
}
/**
* 根据主键id修改对象
*
* @param comments
* @return
*/
@Override
public int updateByPrimaryKeySelective(ShyComments comments) {
return shyCommentsMapper.updateByPrimaryKeySelective(comments);
}
/**
* 获得审核类型
*
* @param shyComments
*/
@Override
public void getShenheType(ShyComments shyComments) {
//获取评论免审sp
List<Integer> sites = sitesService.getBusinessList(CommonConst.BUSINESS_COMMENT);
//初始化一个审核状态
//审核类型,1:免审,2:机审,3:人工审
Integer shenheType = CommonConst.AUDIT_TYPE_USER;
//如果当前sp是免审sp
if (sites.contains(shyComments.getSpid())) {
//免审
shenheType = CommonConst.AUDIT_TYPE_FREE;
}
shyComments.setShenhe_type(shenheType);
}
}