ContentServiceImpl.java
18.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
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
package com.cnlive.shenhe.service.serviceImpl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.cnlive.shenhe.dto.ContentDTO;
import com.cnlive.shenhe.entity.*;
import com.cnlive.shenhe.mapper.ShyContentMapper;
import com.cnlive.shenhe.mapper.ShyUsersMapper;
import com.cnlive.shenhe.service.ContentService;
import com.cnlive.shenhe.service.SitesService;
import com.cnlive.shenhe.service.VideosService;
import com.cnlive.shenhe.service.YiDunService;
import com.cnlive.shenhe.utils.*;
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.ArrayList;
import java.util.Date;
import java.util.List;
/**
* @Auther: liwei
* @Date: 2019/5/20 17:30
* @Description:
*/
@Service
public class ContentServiceImpl implements ContentService {
private static Logger logger = LoggerFactory.getLogger(ContentServiceImpl.class);
@Autowired
ShyContentMapper shyContentMapper;
@Autowired
ShyUsersMapper shyUsersMapper;
@Autowired
AuditPass pass;
@Autowired
SitesService sitesService;
@Autowired
VideosService videosService;
@Autowired
YiDunService yiDunService;
/**
* 获取图文对象
*
* @param shyContent
* @return
*/
@Override
public ShyContent getShyContent(ShyContent shyContent) {
List<ShyContent> shyContentList = shyContentMapper.select(shyContent);
if (CommonUtils.isNotNull(shyContentList) && shyContentList.size() > 0) {
return shyContentList.get(0);
}
return new ShyContent();
}
/**
* 获取图文集合
*
* @param shyContent
* @return
*/
@Override
public List<ShyContent> findShyContent(ShyContent shyContent) {
return shyContentMapper.selectByRowBounds(shyContent, new RowBounds(0, 100));
}
/**
* 根据条件 查询图文集合
*
* @return
*/
@Override
public List<ShyContent> findShyContentWithWebPage() {
List checkParamList = new ArrayList();
checkParamList.add("content");
//checkParamList.add("moment");
Example example = new Example(ShyContent.class);
Example.Criteria criteria = example.createCriteria();
//criteria.andNotIn("content_tag", checkParamList);
criteria.andEqualTo("content_tag", checkParamList);
criteria.andEqualTo("shenhe_type", CommonConst.AUDIT_TYPE_MACHANE);
criteria.andEqualTo("receive_status", CommonConst.RECEIVE_BEFORE);
return shyContentMapper.selectByExampleAndRowBounds(example, new RowBounds(0, 100));
}
/**
* 修改图文 返回布尔类型
*
* @param shyContent
* @return
*/
@Override
public boolean updateShyContent(ShyContent shyContent) {
int result = shyContentMapper.updateByPrimaryKeySelective(shyContent);
return result != 0;
}
/**
* 导入图文 返回布尔类型
*
* @param shyContent
* @return
*/
@Override
public boolean impotContent(ShyContent shyContent) {
int result = shyContentMapper.insertSelective(shyContent);
return result != 0;
}
/**
* 分页、条件查询 返回集合
*
* @param contentDTO
* @return
*/
@Override
public PageInfo<ShyContent> getPage(ContentDTO contentDTO) {
Example example = new Example(ShyContent.class);
Example.Criteria criteria = example.createCriteria();
if (CommonUtils.isNotEmpty(contentDTO.getOrderByClause())) {
example.setOrderByClause(contentDTO.getOrderByClause());
} else {
example.setOrderByClause("create_date desc");
}
if (CommonUtils.isNotEmpty(contentDTO.getStart_date())) {
criteria.andGreaterThanOrEqualTo("create_date", contentDTO.getStart_date());
}
if (CommonUtils.isNotEmpty(contentDTO.getEnd_date())) {
criteria.andLessThanOrEqualTo("create_date", contentDTO.getEnd_date());
}
if (CommonUtils.isNotEmpty(contentDTO.getTitle())) {
criteria.andLike("title", "%" + contentDTO.getTitle() + "%");
}
if (CommonUtils.isNotEmpty(contentDTO.getSource())) {
criteria.andLike("source", "%" + contentDTO.getSource() + "%");
}
if (CommonUtils.isNotEmpty(contentDTO.getAuthor())) {
criteria.andEqualTo("author", contentDTO.getAuthor());
}
if (CommonUtils.isNotEmpty(contentDTO.getUpdater())) {
criteria.andEqualTo("updater", contentDTO.getUpdater());
}
if (CommonUtils.isNotEmpty(contentDTO.getContent_tag())) {
criteria.andEqualTo("content_tag", contentDTO.getContent_tag());
}
if (CommonUtils.isNotNull(contentDTO.getSpid())) {
criteria.andEqualTo("sp_id", contentDTO.getSpid());
}
if (CommonUtils.isNotEmpty(contentDTO.getContentId())) {
criteria.andEqualTo("content_id", contentDTO.getContentId());
}
if (CommonUtils.isNotNull(contentDTO.getReceive_status())) {
criteria.andEqualTo("receive_status", contentDTO.getReceive_status());
if (!contentDTO.getReceive_status().equals(CommonConst.RECEIVE_BEFORE)) {
criteria.andEqualTo("auditor_id", contentDTO.getUserId());
}
}
PageHelper.startPage(contentDTO.getPage(), contentDTO.getPageSize(), true);
List<ShyContent> contentList = shyContentMapper.selectByExample(example);
PageInfo<ShyContent> pageInfo = new PageInfo<>(contentList);
return pageInfo;
}
/**
* 根据条件导出数据excel
*
* @return
*/
@Override
public List<ShyContent> findByCondition(ContentDTO contentDTO) {
Example example = new Example(ShyContent.class);
Example.Criteria criteria = example.createCriteria();
if (CommonUtils.isNotEmpty(contentDTO.getOrderByClause())) {
example.setOrderByClause(contentDTO.getOrderByClause());
} else {
example.setOrderByClause("create_date desc");
}
if (CommonUtils.isNotNull(contentDTO.getStart_date())) {
criteria.andGreaterThanOrEqualTo("create_date", contentDTO.getStart_date());
}
if (CommonUtils.isNotNull(contentDTO.getEnd_date())) {
criteria.andLessThanOrEqualTo("create_date", contentDTO.getEnd_date());
}
if (CommonUtils.isNotEmpty(contentDTO.getTitle())) {
criteria.andLike("title", "%" + contentDTO.getTitle() + "%");
}
if (CommonUtils.isNotNull(contentDTO.getSpid())) {
criteria.andEqualTo("sp_id", contentDTO.getSpid());
}
if (CommonUtils.isNotEmpty(contentDTO.getContentId())) {
criteria.andEqualTo("content_id", contentDTO.getContentId());
}
if (CommonUtils.isNotEmpty(contentDTO.getContent_tag())) {
criteria.andEqualTo("content_tag", contentDTO.getContent_tag());
}
if (CommonUtils.isNotNull(contentDTO.getReceive_status())) {
criteria.andEqualTo("receive_status", contentDTO.getReceive_status());
}
return shyContentMapper.selectByExample(example);
}
/**
* 根据id获取图文详情
*
* @param id
* @return
*/
@Override
public ShyContent getDetailsContent(Integer id) {
ShyContent content = shyContentMapper.selectByPrimaryKey(id);
if (content.getReceive_status().equals(CommonConst.RECEIVE_AUDIT)) {
String updater = CommonUtils.isEmpty(content.getUpdater()) || "null".equals(content.getUpdater()) ? "白名单" : content.getUpdater();
String auditorId = content.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();
}
content.setUpdater(updater);
}
ShySites shySite = sitesService.findspidDescByspid(content.getSp_id());
if (CommonUtils.isNotNull(shySite)) {
content.setSp_desc(shySite.getName());
}
return content;
}
/**
* 回调
*
* @param contentId
* @param msg
* @param state
* @param userId
* @param updater
* @return
*/
@Override
public boolean callback(String contentId, String msg, Integer state, String userId, String updater) {
boolean success = true;
ShyContent content = shyContentMapper.selectByPrimaryKey(Integer.parseInt(contentId));
logger.info("contentId:{},content:{}", contentId, content);
JSONObject result = new JSONObject();
try {
if (CommonUtils.isNotEmpty(content.getContent_tag()) && "content".equals(content.getContent_tag())) {
result = pass.contentPass(content.getContent_id(), state + "", msg, content.getCallback());
} else if (CommonUtils.isNotEmpty(content.getContent_tag()) && "moment".equals(content.getContent_tag())) {
result = pass.momentPass(content.getContent_id(), state, msg, content.getCallback(), content.getAuthor());
} else if (CommonUtils.isNotEmpty(content.getContent_tag()) && "cms_photoalbum".equals(content.getContent_tag())) {
result = pass.cmsCommonContentPass(content.getContent_id(), state, msg, content.getCallback(), content.getAuthor());
} else if (CommonUtils.isNotEmpty(content.getContent_tag()) && "edu_works".equals(content.getContent_tag())) {
result = pass.cmsCommonContentPass(content.getContent_id(), state, msg, content.getCallback(), content.getAuthor());
}
} catch (Exception e) {
logger.error("图文审核回调失败,图文id:{}", content.getId());
success = false;
return success;
}
if (result == null) {
logger.error("图文回调错误,且无返回信息。图文id:{}", content.getId());
success = false;
return success;
} else {
Integer code = result.getInteger("errorCode");
if (code != 0) {
logger.error("图文回调错误,图文id:{},errorCode:{},errorMessage:{}", content.getId(), code,
result.getString("errorMessage"));
success = false;
return success;
}
//如果当前图文是朋友圈的视频,通知点播云
if (CommonUtils.isNotEmpty(content.getContent_tag())
&& "moment".equals(content.getContent_tag())
&& CommonUtils.isNotEmpty(content.getVideo_id())
&& state.equals(CommonConst.AUDIT_REFUSE)) {
ShyVideos shyVideos1 = new ShyVideos();
shyVideos1.setVideo_id(content.getVideo_id());
List<ShyVideos> listShyVideos = videosService.findShyVideo(shyVideos1);
if (listShyVideos.size() > 0) {
ShyVideos shyVideos = listShyVideos.get(0);
String showMsg = videosService.repulse(shyVideos.getId().toString(), msg, userId);
if (CommonUtils.isNotEmpty(showMsg)) {
success = false;
return success;
}
}
}
// 设置图文状态为审核后的状态
content.setContent_status(state);
// 领取状态为已审核
content.setReceive_status(CommonConst.RECEIVE_AUDIT);
// 设置审核消息
content.setShenhe_msg(msg);
if (CommonUtils.isNotEmpty(userId)) {
content.setAuditor_id(userId);
// 设置审核类型为人工
content.setShenhe_type(CommonConst.AUDIT_TYPE_USER);
} else {
//设置更新人
content.setUpdater(updater);
}
content.setLast_update(CommonUtils.getCurrentTime());
int i = shyContentMapper.updateByPrimaryKeySelective(content);
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) {
ShyContent shyContent = shyContentMapper.selectByPrimaryKey(Integer.parseInt(cid));
if (CommonUtils.isNotNull(shyContent) && shyContent.getReceive_status().equals(CommonConst.RECEIVE_BEFORE)) {
shyContent.setAuditor_id(userId);
shyContent.setReceive_status(CommonConst.RECEIVE_AFTER);
shyContent.setLast_update(CommonUtils.getCurrentTime());
shyContentMapper.updateByPrimaryKeySelective(shyContent);
n++;
}
}
} else if (CommonUtils.isNotNull(num) && num > 0) {
Example example = new Example(ShyContent.class);
example.setOrderByClause("create_date desc");
example.and().andEqualTo("receive_status", CommonConst.RECEIVE_BEFORE);
// example.and().andEqualTo("receive", CommonConst.RECEIVE_AFTER);
if (CommonUtils.isNotNull(spid) && spid != 0) {
example.and().andEqualTo("spid", spid);
}
List<ShyContent> shyContentList = shyContentMapper.selectByExampleAndRowBounds(example, new RowBounds(0, num));
if (!shyContentList.isEmpty()) {
for (ShyContent shyContent : shyContentList) {
shyContent.setAuditor_id(userId);
shyContent.setReceive_status(CommonConst.RECEIVE_AFTER);
shyContent.setLast_update(CommonUtils.getCurrentTime());
shyContentMapper.updateByPrimaryKeySelective(shyContent);
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) {
ShyContent shyContent = shyContentMapper.selectByPrimaryKey(Integer.parseInt(cid));
if (shyContent.getReceive_status().equals(CommonConst.RECEIVE_AFTER) && userId.equals(shyContent.getAuditor_id())) {
shyContent.setReceive_status(CommonConst.RECEIVE_BEFORE);
shyContent.setAuditor_id(null);
shyContent.setLast_update(CommonUtils.getCurrentTime());
int i = shyContentMapper.updateByPrimaryKeySelective(shyContent);
if (i == 1) {
n++;
}
}
}
return n;
}
/**
* 根据主键查询图文对象
*
* @param id
* @return
*/
@Override
public ShyContent selectByPrimaryKey(Integer id) {
return shyContentMapper.selectByPrimaryKey(id);
}
/**
* 根据主键修改图文
*
* @param content
* @return
*/
@Override
public int updateByPrimaryKeySelective(ShyContent content) {
return shyContentMapper.updateByPrimaryKeySelective(content);
}
/**
* 获得审核类型
*
* @param spId
*/
@Override
public Integer getShenheType(Integer spId, String contentTag) {
//获取图文免审sp
List<Integer> sites = sitesService.getBusinessList(CommonConst.BUSINESS_CONTENT);
//初始化一个审核状态
//审核类型,1:免审,2:机审,3:人工审 默认人工审
Integer shenheType = CommonConst.AUDIT_TYPE_USER;
//如果当前sp是免审sp
if (sites.contains(spId) || contentTag.startsWith("cms_") || contentTag.startsWith("edu_")) {
//免审
shenheType = CommonConst.AUDIT_TYPE_FREE;
} else {
if ("content".equals(contentTag)) {
//机审
shenheType = CommonConst.AUDIT_TYPE_MACHANE;
}
}
return shenheType;
}
/**
* 易盾网站过滤
* 送审类型:1:文本 2:图片 3.网页 4:点播音频
*
* @param shyContent
* @return
*/
@Override
public void contentFilter(ShyContent shyContent) {
logger.info("contentFilter接收的ShyContent对象:{}", shyContent.toString());
try {
String contentUrl = shyContent.getContent_url();
logger.info("审核云向易盾网站检测接口提交的url:{}", contentUrl);
//调用易盾网站检测接口
JSONObject jsonObject = YiDunAntiFraudUtil.submitYiDunUrl(contentUrl);
if (jsonObject != null) {
JSONObject result = jsonObject.getJSONObject("result");
String dataId = result.getString("dataId");
String taskId = result.getString("taskId");
ShyYidun shyYidun = new ShyYidun();
shyYidun.setId(dataId);
shyYidun.setUrl(contentUrl);
shyYidun.setTask_id(taskId);
shyYidun.setData_id(dataId);
shyYidun.setCheck_type(CommonConstStates.WANGYE);
shyYidun.setContent_id(shyContent.getId().toString());
shyYidun.setCreate_time(new Date());
logger.info("审核云保存到ShyYidun表里数据:{}", JSON.toJSONString(shyYidun));
yiDunService.addYiDunMsg(shyYidun);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}