LiveController.java
11.6 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
package com.cnlive.shenhe.controller;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.cnlive.shenhe.bean.ErrorEnum;
import com.cnlive.shenhe.bean.ResponseBean;
import com.cnlive.shenhe.bean.SessionUser;
import com.cnlive.shenhe.entity.ShyLive;
import com.cnlive.shenhe.entity.ShySites;
import com.cnlive.shenhe.entity.ShyUsers;
import com.cnlive.shenhe.entity.ShyVideos;
import com.cnlive.shenhe.serviceImpl.LiveServiceImpl;
import com.cnlive.shenhe.serviceImpl.SitesServiceImpl;
import com.cnlive.shenhe.serviceImpl.UsersServiceImpl;
import com.cnlive.shenhe.serviceImpl.VideosServiceImpl;
import com.cnlive.shenhe.utils.AuditPass;
import com.cnlive.shenhe.utils.CommonConst;
import com.cnlive.shenhe.utils.CommonUtils;
import com.github.pagehelper.PageInfo;
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.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.*;
import java.util.List;
@Controller
@RequestMapping("/live")
public class LiveController {
private static Logger logger = LoggerFactory.getLogger(LiveController.class);
@Autowired
AuditPass Pass;
@Autowired
VideosServiceImpl videosService;
@Autowired
UsersServiceImpl usersService;
@Autowired
SitesServiceImpl sitesService;
@Autowired
LiveServiceImpl liveService;
@Value("${qn_domain}")
String qn_domain;
@Value("${ks_domain}")
String ks_domain;
/**
* 审核信息返回接口
*
* @param activity_id 视频id
* @param state 状态码
* @param attr_tags 标签
* @param msg 备注信息
* @return
*/
@PostMapping("/shenheVideo")
@ResponseBody
public ResponseBean shenheInfo(Integer id, String activity_id, Integer state, String attr_tags, String msg, String callback, HttpSession session) {
SessionUser sessionUser = (SessionUser) session.getAttribute(SessionUser.getSessionKey());
String userId = sessionUser.getUserId();
// ShyVideos shyVideos = videosService.selectByPrimaryKey(id);
// if (shyVideos.getReceive() && CommonUtils.isNotEmpty(shyVideos.getReceive_user_id()) && userId.equals(shyVideos.getReceive_user_id())) {
JSONObject result = null;
try {
result = Pass.auditPass(activity_id, state, attr_tags, msg, callback);
} catch (Exception e) {
e.printStackTrace();
System.out.println("视频审核失败");
return new ResponseBean(ErrorEnum.ERROR);
}
if (result == null) {
System.out.println("视频审核失败且接口错误没有返回信息");
return new ResponseBean(ErrorEnum.ERROR);
}
Integer code = result.getInteger("code");
if (code != 0) {
System.out.println("审核失败,code==" + code);
return new ResponseBean(code, result.getString("msg"));
}
state = state == 4 ? 2 : 1;
int i = videosService.updateVideo(id, userId,null,attr_tags, state, msg);
if (i == 0) {
return new ResponseBean(ErrorEnum.ERROR);
}
return new ResponseBean(ErrorEnum.SUCCESS);
// }
// logger.error("领取逻辑不符,不能审核,Video_id:{}", shyVideos.getVideo_id());
// return new ResponseBean(ErrorEnum.ERROR.getErrorCode(), "领取逻辑不符,不能审核");
}
/**
* 内容分页列表接口
*
* @param video_title
* @param start_date
* @param end_date
* @param state
* @param page
* @param pageSize
* @param orderByClause
* @return
*/
@GetMapping("/page")
public Object getListVideos(Model model,String activity_id,String start_date,String end_date,
String activity_name, Integer activity_status, Integer page,Integer pageSize,
Integer shenhe_state, String orderByClause, String sp_desc, HttpSession session) {
SessionUser sessionUser = (SessionUser) session.getAttribute(SessionUser.getSessionKey());
if(CommonUtils.isNull(sessionUser)){
return "redirect:/users/login";
}
Integer spid = sessionUser.getSpid();
String userId = sessionUser.getUserId();
if (CommonUtils.isNull(page)) page = 1;
if (CommonUtils.isNull(pageSize)) pageSize = 60;
if (CommonUtils.isNotEmpty(sp_desc) && spid == 0) {
ShySites shySite=sitesService.findspidBySpdesc(sp_desc);
if(CommonUtils.isNotNull(shySite)){
spid = shySite.getSpid();
}else{
return "page/sitesError.html";
}
} else if (CommonUtils.isEmpty(sp_desc) && spid == 0) {
spid = null;
}
PageInfo<ShyLive> livePage = liveService.getListContent(activity_name, start_date,end_date,
activity_id, activity_status, page, pageSize, shenhe_state, orderByClause, spid, userId);
List<ShyLive> list = livePage.getList();
if (!list.isEmpty()) {
for (ShyLive live : list) {
//显示spid简称
ShySites shySites = sitesService.findspidDescByspid(live.getSp_id());
if (CommonUtils.isNotNull(shySites)) {
live.setSpid_desc(shySites.getName());
}
}
}
model.addAttribute("livePage", livePage);
return "page/live.html";
}
/**
* 内容详情页接口(查看)
*
* @param id
* @return
*/
@GetMapping("/details")
public Object getDetailsVideo(Model model, Integer id) {
ShyVideos detailsContent = videosService.getDetailsContent(id);
Object images = JSON.parse(detailsContent.getVideo_imgs());
Object avsampleImgs = JSON.parse(detailsContent.getAvsample_imgs());
String yuming = "";
Integer plat = detailsContent.getPlat();
if (plat == CommonConst.QINIU_PLAT) {
yuming = qn_domain + "/";
} else if (plat == CommonConst.KS_PLAT) {
yuming = ks_domain + "/";
}
detailsContent.setAttr_tags(CommonUtils.isEmpty(detailsContent.getAttr_tags())?"":detailsContent.getAttr_tags());
model.addAttribute("images", images);
model.addAttribute("avsampleImgs", avsampleImgs);
model.addAttribute("video", detailsContent);
model.addAttribute("yuming", yuming);
return "page/videoDetail.html";
}
/**
* 认领
*
* @param ids 根据id认领
* @param num 认领条数
* @param session
* @return
*/
@PostMapping("/receive")
@ResponseBody
public ResponseBean receive(String ids, Integer num, HttpSession session) {
SessionUser sessionUser = (SessionUser) session.getAttribute(SessionUser.getSessionKey());
String userId = sessionUser.getUserId();
Integer spid = sessionUser.getSpid();
//领取时要检查领取的数据是否可以领
if (CommonUtils.isNotEmpty(ids)) {
String[] cids = ids.split(",");
for (String cid : cids) {
ShyLive shyLive = liveService.selectByPrimaryKey(Integer.parseInt(cid));
if (CommonUtils.isNotNull(shyLive)) {
if (shyLive.getShenhe_state() != CommonConst.RECEIVE_BEFORE ) {
return new ResponseBean(ErrorEnum.ERROR.getErrorCode(), "您领取的内容中有已被领取或者已经被审核,请检查并重试");
}
} else {
return new ResponseBean(ErrorEnum.ERROR.getErrorCode(), "您领取的内容不存在,请检查并重试");
}
}
}
Integer n = liveService.receive(ids, num, userId, spid);
return new ResponseBean(ErrorEnum.SUCCESS.getErrorCode(), "认领到" + n + "条内容");
}
/**
* 退领
* @param ids
* @param session
* @return
*/
@PostMapping("/retReceive")
@ResponseBody
public ResponseBean retReceive(String ids, HttpSession session) {
SessionUser sessionUser = (SessionUser) session.getAttribute(SessionUser.getSessionKey());
String userId = sessionUser.getUserId();
//在退领操作前先判断是否包含已退领或者已经审核的数据,有则退回检查并重新退领
String[] cids = ids.split(",");
for (String cid : cids) {
ShyLive shyLive = liveService.selectByPrimaryKey(Integer.parseInt(cid));
if (shyLive.getShenhe_state() != CommonConst.RECEIVE_AFTER || !shyLive.getAuditor().equals(userId)) {
return new ResponseBean(ErrorEnum.ERROR.getErrorCode(), "退领失败,您选中的内容包含已退领的或已经审核的");
}
}
return liveService.retReceive(ids, userId);
}
/**
* 打回(审核拒绝)
*
* @param ids
* @param msg
* @param session
* @return
*/
@PostMapping("/repulse")
@ResponseBody
public ResponseBean repulse(String ids, String msg, HttpSession session) {
SessionUser sessionUser = (SessionUser) session.getAttribute(SessionUser.getSessionKey());
String userId = sessionUser.getUserId();
ResponseBean responseBean = new ResponseBean();
String[] shyLiveIds = ids.split(",");
String showMsg = "";
for (String shyLiveId : shyLiveIds) {
ShyLive shyLive = liveService.selectByPrimaryKey(Integer.parseInt(shyLiveId));
// JSONObject result = null;
// try {
// result = Pass.auditPass(shyLive.getActivity_id(), 6, msg, msg, shyLive.getCallback());
// } catch (Exception e) {
// logger.error("直播视频审核失败,id==" + shyLiveId, e);
// showMsg = showMsg + "," + shyLive.getActivity_id() + " 拒绝请求失败";
// break;
// }
// if (result == null) {
// logger.error("直播视频审核失败且接口错误没有返回信息,id==" + shyLiveId);
// showMsg = showMsg + "," + shyLive.getActivity_id() + " 拒绝请求失败";
// break;
// }
// Integer code = result.getInteger("code");
// if (code != 0) {
// logger.error("直播视频审核失败,id:{},code:{}", shyLiveId, code);
// showMsg = showMsg + "," + shyLive.getActivity_id() + " " + result.getString("msg");
// break;
// }
int i = liveService.updateLive(Integer.parseInt(shyLiveId), userId,"", 4, msg);
if (i == 0) {
showMsg = showMsg + "," + shyLive.getActivity_id() + " 更新失败";
break;
}
}
if (CommonUtils.isNotEmpty(showMsg)) {
responseBean.setErrorCode(ErrorEnum.ERROR.getErrorCode());
responseBean.setErrorMessage(showMsg);
}
return responseBean;
}
@PostMapping("/ceshi")
@ResponseBody
public static String ceshi(String name) {
return name;
}
}