ContentController.java
7.31 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
package com.cnlive.shenhe.controller;
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.ShyComments;
import com.cnlive.shenhe.entity.ShyContent;
import com.cnlive.shenhe.entity.ShySites;
import com.cnlive.shenhe.entity.ShyUsers;
import com.cnlive.shenhe.entity.ShyVideos;
import com.cnlive.shenhe.serviceImpl.CommentsServiceImpl;
import com.cnlive.shenhe.serviceImpl.ContentServiceImpl;
import com.cnlive.shenhe.serviceImpl.SitesServiceImpl;
import com.cnlive.shenhe.serviceImpl.UsersServiceImpl;
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.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.List;
@Controller
@RequestMapping("/content")
public class ContentController {
private static Logger logger = LoggerFactory.getLogger(ContentController.class);
@Autowired
AuditPass Pass;
@Autowired
CommentsServiceImpl commentsService;
@Autowired
ContentServiceImpl contentService;
@Autowired
SitesServiceImpl sitesService;
@Autowired
UsersServiceImpl usersService;
/**
* 图文列表
*
* @param model
* @param title
* @param start_date
* @param end_date
* @param receive_status
* @param sp_desc
* @param page
* @param pageSize
* @param orderByClause
* @param session
* @return
*/
@GetMapping("/page")
public String getPage(Model model, String title,String contentId,
String start_date, String end_date, Integer receive_status, String sp_desc,
Integer page, Integer pageSize, String orderByClause, 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 = 10;
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;
}
Date sDate = null;
Date eDate = null;
if (CommonUtils.isNotEmpty(start_date)) {
try {
sDate = CommonUtils.parseDate(start_date, "yyyy-MM-dd");
} catch (Exception e) {
}
}
if (CommonUtils.isNotEmpty(end_date)) {
try {
eDate = CommonUtils.parseDate(end_date, "yyyy-MM-dd");
} catch (Exception e) {
}
}
PageInfo<ShyContent> contentPage = contentService.getPage( title,contentId, sDate, eDate, receive_status, null, page, pageSize, orderByClause, spid, userId);
List<ShyContent> list = contentPage.getList();
if (!list.isEmpty()) {
for (ShyContent content : list) {
if (content.getReceive_status() == CommonConst.RECEIVE_AUDIT) {
String auditor_id = content.getAuditor_id();
String updater = CommonUtils.isEmpty(content.getUpdater()) || "null".equals(content.getUpdater())? "白名单":content.getUpdater();
updater =sitesService.getUpdater(updater,auditor_id);
content.setUpdater(updater);
}
//显示spid简称
ShySites shySites = sitesService.findspidDescByspid(content.getSp_id());
if (CommonUtils.isNotNull(shySites)) {
content.setSp_desc(shySites.getName());
}
}
}
model.addAttribute("contentPage", contentPage);
return "page/content.html";
}
/**
* 图文详情
*
* @param id
* @return
*/
@GetMapping("/details/{id}")
public String getDetailsComments(@PathVariable Integer id, Model model) {
ShyContent content = contentService.getDetailsContent(id);
if (content.getReceive_status() != CommonConst.RECEIVE_BEFORE) {
String auditor_id = content.getAuditor_id();
String updater = CommonUtils.isEmpty(content.getUpdater()) || "null".equals(content.getUpdater())? "白名单":content.getUpdater();
updater =sitesService.getUpdater(updater,auditor_id);
content.setUpdater(updater);
}
model.addAttribute("content", content);
return "page/contentDetail.html";
}
/**
* 审核通过
*
* @param ids
* @return
*/
@PostMapping("/pass")
@ResponseBody
public ResponseBean pass(String ids, HttpSession session) {
SessionUser sessionUser = (SessionUser) session.getAttribute(SessionUser.getSessionKey());
String userId = sessionUser.getUserId();
boolean success = contentService.updateState(ids,"审核通过", CommonConst.AUDIT_SUCCESS, userId);
if (success) {
return new ResponseBean();
} else {
return new ResponseBean(ErrorEnum.ERROR);
}
}
/**
* 审核拒绝
*
* @param ids
* @return
*/
@PostMapping("/refuse")
@ResponseBody
public ResponseBean refuse(String ids,String msg, HttpSession session) {
SessionUser sessionUser = (SessionUser) session.getAttribute(SessionUser.getSessionKey());
String userId = sessionUser.getUserId();
boolean success = contentService.updateState(ids,msg, CommonConst.AUDIT_REFUSE, userId);
if (success) {
return new ResponseBean();
} else {
return new ResponseBean(ErrorEnum.ERROR);
}
}
/**
* 认领
*
* @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();
Integer n = contentService.receive(ids, num, userId, spid);
return new ResponseBean(ErrorEnum.SUCCESS.getErrorCode(), "认领到" + n + "条内容");
}
@PostMapping("/retReceive")
@ResponseBody
public ResponseBean retReceive(String ids, HttpSession session) {
SessionUser sessionUser = (SessionUser) session.getAttribute(SessionUser.getSessionKey());
String userId = sessionUser.getUserId();
Integer n = contentService.retReceive(ids, userId);
return new ResponseBean(ErrorEnum.SUCCESS.getErrorCode(), "退领了" + n + "条内容");
}
}