VideosServiceImpl.java
7.61 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
package com.cnlive.shenhe.serviceImpl;
import com.cnlive.shenhe.entity.ShySites;
import com.cnlive.shenhe.entity.ShyUsers;
import com.cnlive.shenhe.entity.ShyVideos;
import com.cnlive.shenhe.mapper.ShySitesMapper;
import com.cnlive.shenhe.mapper.ShyUsersMapper;
import com.cnlive.shenhe.mapper.ShyVideosMapper;
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.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import java.sql.Timestamp;
import java.text.ParseException;
import java.util.List;
/**
* @Auther: chenhao
* @Date: 2018/11/30 14:23
* @Description:
*/
@Service
public class VideosServiceImpl {
@Autowired
ShyVideosMapper shyVideosMapper;
@Autowired
ShySitesMapper shySitesMapper;
@Autowired
ShyUsersMapper shyUsersMapper;
public boolean impotVideo(ShyVideos shyVideos) {
int result = shyVideosMapper.insertSelective(shyVideos);
if (result == 0) {
return false;
}
return true;
}
public ShyVideos selectByPrimaryKey(Integer id) {
ShyVideos shyVideos = shyVideosMapper.selectByPrimaryKey(id);
return shyVideos;
}
public List<ShyVideos> findshyVideo(ShyVideos shyVideos) {
List<ShyVideos> shyVideoslist = shyVideosMapper.selectByRowBounds(shyVideos, new RowBounds(0, 100));
return shyVideoslist;
}
public boolean updateshyVideos(ShyVideos shyVideos) {
int i = shyVideosMapper.updateByPrimaryKeySelective(shyVideos);
if (i == 0) {
return false;
}
return true;
}
public int updateVideo(Integer id, String auditor_id, Integer state, String msg) {
ShyVideos shyVideos = shyVideosMapper.selectByPrimaryKey(id);
shyVideos.setAuditor_id(auditor_id);
shyVideos.setState(state);
shyVideos.setMsg(msg);
return shyVideosMapper.updateByPrimaryKeySelective(shyVideos);
}
public PageInfo<ShyVideos> getListContent(String video_title, String start_date, String end_date, Integer state, Boolean receive, Integer page, Integer pageSize, String video_priority, String orderByClause, Integer spid, String userId) {
Example example = new Example(ShyVideos.class);
Example.Criteria criteria = example.createCriteria();
Example.Criteria criteria2 = example.createCriteria();
if (CommonUtils.isNotEmpty(orderByClause)) {
example.setOrderByClause(orderByClause);
}
if (CommonUtils.isNotEmpty(start_date) && CommonUtils.isNotEmpty(end_date)) {
Timestamp startdate = null;
Timestamp enddate = null;
try {
startdate = CommonUtils.parseDate(start_date, "yyyy-MM-dd HH:mm:ss");
enddate = CommonUtils.parseDate(end_date, "yyyy-MM-dd HH:mm:ss");
} catch (ParseException e) {
e.printStackTrace();
}
criteria.andGreaterThanOrEqualTo("video_upload_time", startdate);
criteria.andLessThanOrEqualTo("video_upload_time", enddate);
}
if (CommonUtils.isNotEmpty(video_title)) {
criteria.andLike("video_title", "%" + video_title + "%");
}
if (CommonUtils.isNotNull(state) && state == 0) {
criteria.andEqualTo("state", state);
} else if (CommonUtils.isNotNull(state) && state == 1) {
criteria.andEqualTo("state", state);
criteria2.andEqualTo("state", 2);
example.or(criteria2);
}
if (CommonUtils.isNotEmpty(video_priority)) {
criteria.andEqualTo("video_priority", video_priority);
}
if (CommonUtils.isNotNull(spid)) {
criteria.andEqualTo("spid", spid);
}
if (CommonUtils.isNotNull(receive)) {
criteria.andEqualTo("receive", receive);
if (receive == true) {
criteria.andEqualTo("receive_user_id", userId);
}
}
//默认按上传时间倒序排序
example.setOrderByClause("video_upload_time desc");
PageHelper.startPage(page, pageSize, true);
List<ShyVideos> shyVideosList = shyVideosMapper.selectByExample(example);
PageInfo<ShyVideos> pageInfo = new PageInfo<>(shyVideosList);
return pageInfo;
}
public ShyVideos getDetailsContent(Integer id) {
ShyVideos shyVideos = shyVideosMapper.selectByPrimaryKey(id);
if (shyVideos.getState() != CommonConst.AUDIT_INTT) {
String auditorName = "白名单";
String auditor_id = shyVideos.getAuditor_id();
if (CommonUtils.isNotEmpty(auditor_id)) {
ShyUsers user = new ShyUsers();
user.setUser_id(auditor_id);
user = shyUsersMapper.selectOne(user);
String userName = CommonUtils.isEmpty(user.getUsername()) ? "" : user.getUsername();
String email = CommonUtils.isEmpty(user.getEmail()) ? "" : user.getEmail();
auditorName = userName + email;
}
shyVideos.setAuditor(auditorName);
}
return shyVideos;
}
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) {
ShyVideos shyVideos = shyVideosMapper.selectByPrimaryKey(Integer.parseInt(cid));
if (CommonUtils.isNotNull(shyVideos) && shyVideos.getState() == CommonConst.AUDIT_INTT && !shyVideos.getReceive()) {
shyVideos.setReceive_user_id(userId);
shyVideos.setReceive(true);
shyVideosMapper.updateByPrimaryKeySelective(shyVideos);
n++;
}
}
} else if (CommonUtils.isNotNull(num) && num > 0) {
Example example = new Example(ShyVideos.class);
example.setOrderByClause("created_at desc");
example.and().andEqualTo("state", CommonConst.AUDIT_INTT);
example.and().andEqualTo("receive", CommonConst.RECEIVE_BEFORE);
if (CommonUtils.isNotNull(spid) && spid != 0) example.and().andEqualTo("spid", spid);
List<ShyVideos> shyCommentsList = shyVideosMapper.selectByExampleAndRowBounds(example, new RowBounds(0, num));
if (!shyCommentsList.isEmpty()) {
for (ShyVideos shyComments : shyCommentsList) {
shyComments.setReceive_user_id(userId);
shyComments.setReceive(true);
shyVideosMapper.updateByPrimaryKeySelective(shyComments);
n++;
}
}
}
return n;
}
public boolean retReceive(String ids, String userId) {
boolean result = true;
String[] cids = ids.split(",");
for (String cid : cids) {
ShyVideos shyVideos = shyVideosMapper.selectByPrimaryKey(Integer.parseInt(cid));
if (shyVideos.getState() == CommonConst.AUDIT_INTT && shyVideos.getReceive() && shyVideos.getReceive_user_id() == userId) {
shyVideos.setReceive(CommonConst.RECEIVE_BEFORE);
shyVideos.setReceive_user_id(null);
int i = shyVideosMapper.updateByPrimaryKeySelective(shyVideos);
if (i != 1) {
return false;
}
} else {
return false;
}
}
return result;
}
}