CommentsServiceImpl.java
10.8 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
package com.cnlive.shenhe.serviceImpl;
import com.alibaba.fastjson.JSONObject;
import com.cnlive.shenhe.entity.ShyComments;
import com.cnlive.shenhe.entity.ShySites;
import com.cnlive.shenhe.entity.ShyUsers;
import com.cnlive.shenhe.entity.ShyUsersfree;
import com.cnlive.shenhe.entity.ShyVideos;
import com.cnlive.shenhe.mapper.ShyCommentsMapper;
import com.cnlive.shenhe.mapper.ShySitesMapper;
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.Date;
import java.util.List;
/**
* @Auther: chenhao
* @Date: 2018/12/4 17:30
* @Description:
*/
@Service
public class CommentsServiceImpl {
private static Logger logger = LoggerFactory.getLogger(CommentsServiceImpl.class);
@Autowired
ShyCommentsMapper shyCommentsMapper;
@Autowired
ShySitesMapper shySitesMapper;
@Autowired
ShyUsersMapper shyUsersMapper;
@Autowired
AuditPass Pass;
@Autowired
SitesServiceImpl sitesService;
public List<ShySites> getBusiness(ShySites shySites) {
List<ShySites> sitesList = shySitesMapper.select(shySites);
return sitesList;
}
//**************************************
public List<ShyComments> findshyComments(ShyComments shyComments) {
List<ShyComments> commentsList = shyCommentsMapper.selectByRowBounds(shyComments, new RowBounds(0, 100));
return commentsList;
}
public boolean updateshyComments1(ShyComments shyComments) {
int result = shyCommentsMapper.updateByPrimaryKey(shyComments);
if (result == 0) {
return false;
}
return true;
}
public boolean impotComments(ShyComments shyComments) {
int result = shyCommentsMapper.insertSelective(shyComments);
if (result == 0) {
return false;
}
return true;
}
public int updateComment(Integer id, Integer state, String msg) {
ShyComments shyComments = shyCommentsMapper.selectByPrimaryKey(id);
shyComments.setState(state);
shyComments.setMsg(msg);
return shyCommentsMapper.updateByPrimaryKeySelective(shyComments);
}
public PageInfo<ShyComments> getPage(String activity_id, String content, Integer is_hot, Date start_date, Date end_date, String states, Integer receive, String updater, Integer page, Integer pageSize, String orderByClause, Integer spid, String userId) {
Example example = new Example(ShyComments.class);
Example.Criteria criteria = example.createCriteria();
if (CommonUtils.isNotEmpty(orderByClause)) {
example.setOrderByClause(orderByClause);
} else {
example.setOrderByClause("comment_time desc");
}
if (CommonUtils.isNotNull(start_date) && CommonUtils.isNotNull(end_date)) {
criteria.andGreaterThanOrEqualTo("comment_time", start_date);
criteria.andLessThanOrEqualTo("comment_time", end_date);
}
if (CommonUtils.isNotEmpty(content)) {
criteria.andLike("comment_content", "%" + content + "%");
}
if (CommonUtils.isNotEmpty(updater)) {
criteria.andEqualTo("updater", updater);
}
if (CommonUtils.isNotNull(spid)) {
criteria.andEqualTo("spid", spid);
}
if (CommonUtils.isNotNull(is_hot)) {
criteria.andEqualTo("is_hot", is_hot);
}
if (CommonUtils.isNotEmpty(activity_id)) {
criteria.andLike("activity_id", "%" + activity_id + "%");
}
if (CommonUtils.isNotNull(receive)) {
criteria.andEqualTo("receive", receive);
if (receive==CommonConst.RECEIVE_AFTER) {
criteria.andEqualTo("receive_user_id", userId);
}
}
if (CommonUtils.isNotEmpty(states)) {
Example.Criteria criteria1 = example.createCriteria();
String[] stas = states.split(",");
for (String s : stas) {
criteria1.orEqualTo("state", Integer.parseInt(s));
}
example.and(criteria1);
}
PageHelper.startPage(page, pageSize, true);
List<ShyComments> commentsList = shyCommentsMapper.selectByExample(example);
PageInfo<ShyComments> pageInfo = new PageInfo<>(commentsList);
return pageInfo;
}
public ShyComments getDetailsComment(Integer id) {
ShyComments comment = shyCommentsMapper.selectByPrimaryKey(id);
if (comment.getState() != CommonConst.AUDIT_INTT) {
String updater = CommonUtils.isEmpty(comment.getUpdater()) || "null".equals(comment.getUpdater())? "白名单":comment.getUpdater();
String auditor_id = comment.getAuditor_id();
if (CommonUtils.isNotEmpty(auditor_id)) {
ShyUsers user = new ShyUsers();
user.setUser_id(auditor_id);
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;
}
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;
}
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() == CommonConst.AUDIT_INTT && shyComments.getReceive()==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;
}
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() == CommonConst.AUDIT_INTT && shyComments.getReceive()==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;
}
public ShyComments selectByPrimaryKey(Integer id) {
ShyComments shyComments = shyCommentsMapper.selectByPrimaryKey(id);
return shyComments;
}
public int updateByPrimaryKeySelective(ShyComments comments) {
return shyCommentsMapper.updateByPrimaryKeySelective(comments);
}
/**
* 获得审核类型
* @param shyComments
*/
public void getShenheType(ShyComments shyComments){
//获取评论免审sp
List<Integer> sites = sitesService.getBusinessList(CommonConst.BUSINESS_COMMENT);
//初始化一个审核状态
Integer shenheType=3;//审核类型,1:免审,2:机审,3:人工审
//如果当前sp是免审sp
if(sites.contains(shyComments.getSpid())){
shenheType=1;//免审
}
shyComments.setShenhe_type(shenheType);
}
}