LiveServiceImpl.java
11.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
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
package com.cnlive.shenhe.serviceImpl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.cnlive.shenhe.bean.ErrorEnum;
import com.cnlive.shenhe.bean.ResponseBean;
import com.cnlive.shenhe.entity.ShyLive;
import com.cnlive.shenhe.entity.ShySites;
import com.cnlive.shenhe.entity.ShyUsers;
import com.cnlive.shenhe.entity.ShyUsersfree;
import com.cnlive.shenhe.entity.ShyVideofilter;
import com.cnlive.shenhe.entity.ShyVideos;
import com.cnlive.shenhe.job.VideosJob;
import com.cnlive.shenhe.mapper.ShyLiveMapper;
import com.cnlive.shenhe.mapper.ShySitesMapper;
import com.cnlive.shenhe.mapper.ShyUsersMapper;
import com.cnlive.shenhe.mapper.ShyVideosMapper;
import com.cnlive.shenhe.utils.AntiFraudUtil;
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.sql.Timestamp;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @Auther: chenhao
* @Date: 2018/11/30 14:23
* @Description:
*/
@Service
public class LiveServiceImpl {
private static Logger logger = LoggerFactory.getLogger(LiveServiceImpl.class);
@Autowired
ShyVideosMapper shyVideosMapper;
@Autowired
ShyLiveMapper shyLiveMapper;
@Autowired
ShySitesMapper shySitesMapper;
@Autowired
ShyUsersMapper shyUsersMapper;
@Autowired
LiveServiceImpl videosService;
@Autowired
SitesServiceImpl sitesService;
@Autowired
UsersfreeServiceImpl usersfreeServiceImpl;
@Autowired
VideofilterServiceImpl videofilterServiceImpl;
@Value("${qn_domain}")
String qn_domain;
@Value("${ks_domain}")
String ks_domain;
@Autowired
AuditPass Pass;
//==============
public boolean impotVideo(ShyLive shyLive) {
int result = shyLiveMapper.insertSelective(shyLive);
if (result == 0) {
return false;
}
return true;
}
//==============
public ShyLive selectByPrimaryKey(Integer id) {
ShyLive shyLive = shyLiveMapper.selectByPrimaryKey(id);
return shyLive;
}
//=============
public List<ShyLive> findshyLive(ShyLive shyLive) {
List<ShyLive> shyLivelist = shyLiveMapper.selectByRowBounds(shyLive, new RowBounds(0, 100));
return shyLivelist;
}
//==============
public boolean updateshyLive(ShyLive shyLive) {
int i = shyLiveMapper.updateByPrimaryKey(shyLive);
if (i == 0) {
return false;
}
return true;
}
//==============
public int updateLive(Integer id, String auditor_id,String updater, Integer activity_status, String msg) {
ShyLive shyLive = shyLiveMapper.selectByPrimaryKey(id);
shyLive.setAuditor(auditor_id);
shyLive.setShenhe_state(CommonConst.RECEIVE_AUDIT);
shyLive.setActivity_status(activity_status);
shyLive.setShenhe_msg(msg);
shyLive.setUpdater(updater);
shyLive.setIs_hot(1);
return shyLiveMapper.updateByPrimaryKey(shyLive);
}
//===============
public PageInfo<ShyLive> getListContent(String activity_name, String start_date, String end_date,
String activity_id, Integer activity_status, Integer page, Integer pageSize,
Integer shenhe_state, String orderByClause, Integer spid, String userId) {
Example example = new Example(ShyLive.class);
Example.Criteria criteria = example.createCriteria();
// Example.Criteria criteria2 = example.createCriteria();
if (CommonUtils.isNotEmpty(orderByClause)) {
example.setOrderByClause(orderByClause);
}
if (CommonUtils.isNotEmpty(start_date)) {
Timestamp startdate = null;
try {
startdate = CommonUtils.parseDate(start_date, "yyyy-MM-dd");
} catch (ParseException e) {
e.printStackTrace();
}
criteria.andGreaterThanOrEqualTo("activity_start_time", startdate);
// criteria2.andGreaterThanOrEqualTo("activity_start_time", startdate);
}
if ( CommonUtils.isNotEmpty(end_date)) {
Timestamp enddate = null;
try {
enddate = CommonUtils.parseDate(end_date, "yyyy-MM-dd");
} catch (ParseException e) {
e.printStackTrace();
}
criteria.andLessThanOrEqualTo("activity_end_time", enddate);
// criteria2.andLessThanOrEqualTo("activity_end_time", enddate);
}
if (CommonUtils.isNotEmpty(activity_name)) {
criteria.andLike("activity_name", "%" + activity_name + "%");
// criteria2.andLike("activity_name", "%" + activity_name + "%");
}
if (CommonUtils.isNotEmpty(activity_id)) {
criteria.andEqualTo("activity_id", activity_id);
// criteria2.andEqualTo("activity_id", activity_id);
}
if (CommonUtils.isNotNull(spid)) {
criteria.andEqualTo("sp_id", spid);
// criteria2.andEqualTo("spid", spid);
}
if (CommonUtils.isNotNull(shenhe_state)) {
criteria.andEqualTo("shenhe_state", shenhe_state);
// criteria2.andEqualTo("shenhe_state", shenhe_state);
if (shenhe_state != CommonConst.RECEIVE_BEFORE) {
criteria.andEqualTo("auditor", userId);
// criteria2.andEqualTo("auditor", userId);
}
}
if (CommonUtils.isNotNull(activity_status) ) {
criteria.andEqualTo("activity_status", activity_status);
}
criteria.andEqualTo("is_show", 1);
//排序
// example.setOrderByClause("is_hot desc, activity_start_time desc");
PageHelper.startPage(page, pageSize, true);
List<ShyLive> shyLiveList = shyLiveMapper.selectByExample(example);
PageInfo<ShyLive> pageInfo = new PageInfo<>(shyLiveList);
return pageInfo;
}
//======================
public ShyLive getDetailsLive(Integer id) {
ShyLive shyLive = shyLiveMapper.selectByPrimaryKey(id);
if (shyLive.getShenhe_state() != CommonConst.RECEIVE_BEFORE) {
String updater = CommonUtils.isEmpty(shyLive.getUpdater()) || "null".equals(shyLive.getUpdater())? "自动通过":shyLive.getUpdater();
String auditor_id = shyLive.getAuditor();
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;
}
shyLive.setUpdater(updater);
}
return shyLive;
}
//====================
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) {
ShyLive shyLive = shyLiveMapper.selectByPrimaryKey(Integer.parseInt(cid));
if (CommonUtils.isNotNull(shyLive) && shyLive.getShenhe_state() == CommonConst.RECEIVE_BEFORE ) {
shyLive.setAuditor(userId);;
shyLive.setShenhe_state(CommonConst.RECEIVE_AFTER);
shyLiveMapper.updateByPrimaryKeySelective(shyLive);
n++;
}
}
} else if (CommonUtils.isNotNull(num) && num > 0) {
Example example = new Example(ShyLive.class);
example.setOrderByClause("is_hot desc, activity_start_time asc");
example.and().andEqualTo("shenhe_state", CommonConst.RECEIVE_BEFORE);
if (CommonUtils.isNotNull(spid) && spid != 0) example.and().andEqualTo("spid", spid);
List<ShyLive> shyLiveList = shyLiveMapper.selectByExampleAndRowBounds(example, new RowBounds(0, num));
if (!shyLiveList.isEmpty()) {
for (ShyLive shyLive : shyLiveList) {
shyLive.setAuditor(userId);
shyLive.setShenhe_state(CommonConst.RECEIVE_AFTER);
shyLiveMapper.updateByPrimaryKeySelective(shyLive);
n++;
}
}
}
return n;
}
//================
public ResponseBean retReceive(String ids, String userId) {
String[] cids = ids.split(",");
for (String cid : cids) {
ShyLive shyLive = shyLiveMapper.selectByPrimaryKey(Integer.parseInt(cid));
if (shyLive.getShenhe_state() == CommonConst.RECEIVE_AFTER && shyLive.getAuditor().equals(userId)) {
shyLive.setShenhe_state(CommonConst.RECEIVE_BEFORE);
shyLive.setAuditor(null);
int i = shyLiveMapper.updateByPrimaryKey(shyLive);
if (i != 1) {
return new ResponseBean(ErrorEnum.ERROR.getErrorCode(), "退领失败,请重试");
}
} else {
return new ResponseBean(ErrorEnum.ERROR.getErrorCode(), "退领失败,您选中的内容包含已退领的或已经审核的");
}
}
return new ResponseBean(ErrorEnum.SUCCESS.getErrorCode(), "已退领");
}
/**
* 根据条件导出数据excel
* @return
*/
public List<ShyLive> findByCondition(String activity_id,String start_date,String end_date,
String activity_name, Integer activity_status, Integer page,Integer pageSize,
Integer shenhe_state, String orderByClause, Integer spid) {
Example example = new Example(ShyLive.class);
Example.Criteria criteria = example.createCriteria();
if (CommonUtils.isNotEmpty(orderByClause)) {
example.setOrderByClause(orderByClause);
}else{
//默认排序
example.setOrderByClause("activity_start_time asc");
}
if (CommonUtils.isNotEmpty(start_date)) {
Timestamp startdate = null;
try {
startdate = CommonUtils.parseDate(start_date, "yyyy-MM-dd HH:mm");
} catch (ParseException e) {
e.printStackTrace();
}
criteria.andGreaterThanOrEqualTo("activity_start_time", startdate);
}
if ( CommonUtils.isNotEmpty(end_date)) {
Timestamp enddate = null;
try {
enddate = CommonUtils.parseDate(end_date, "yyyy-MM-dd HH:mm");
} catch (ParseException e) {
e.printStackTrace();
}
criteria.andLessThanOrEqualTo("activity_end_time", enddate);
}
if (CommonUtils.isNotEmpty(activity_name)) {
criteria.andLike("activity_name", "%" + activity_name + "%");
}
if (CommonUtils.isNotNull(activity_status) ) {
criteria.andEqualTo("activity_status", activity_status);
}
if (CommonUtils.isNotEmpty(activity_id)) {
criteria.andEqualTo("activity_id", activity_id);
}
if (CommonUtils.isNotNull(spid)) {
criteria.andEqualTo("spid", spid);
}
if (CommonUtils.isNotNull(shenhe_state)) {
criteria.andEqualTo("shenhe_state", shenhe_state);
}
List<ShyLive> shyLiveList = shyLiveMapper.selectByExample(example);
return shyLiveList;
}
}