TopicController.java
7.17 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
package com.cnlive.shenhe.controller;
import com.alibaba.fastjson.JSON;
import com.cnlive.shenhe.bean.ErrorEnum;
import com.cnlive.shenhe.bean.ResponseBean;
import com.cnlive.shenhe.bean.SessionUser;
import com.cnlive.shenhe.dto.TopicDTO;
import com.cnlive.shenhe.entity.ShySites;
import com.cnlive.shenhe.entity.ShyTopic;
import com.cnlive.shenhe.service.SitesService;
import com.cnlive.shenhe.service.TopicService;
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.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author Administrator
*/
@Controller
@RequestMapping("/topic")
public class TopicController extends BaseController {
private static Logger logger = LoggerFactory.getLogger(TopicController.class);
@Autowired
TopicService topicService;
@Autowired
SitesService sitesService;
@Value("${spring.localhost.url}")
private String localhost_url;
/**
* 图文列表
*
* @param model
* @param topicDTO
* @param session
* @return
*/
@GetMapping("/page")
public String getPage(Model model, TopicDTO topicDTO, HttpSession session) {
logger.info("列表请求参数:{}", JSON.toJSONString(topicDTO));
SessionUser sessionUser = (SessionUser) session.getAttribute(SessionUser.getSessionKey());
if (CommonUtils.isNull(sessionUser)) {
return "redirect:/users/login";
}
Integer spid = sessionUser.getSpid();
String userId = sessionUser.getUserId();
topicDTO.setSpid(spid);
topicDTO.setUserId(userId);
if (CommonUtils.isNotEmpty(topicDTO.getSp_desc()) && topicDTO.getSpid() == 0) {
ShySites shySite = sitesService.findspidBySpdesc(topicDTO.getSp_desc());
if (CommonUtils.isNotNull(shySite)) {
topicDTO.setSpid(shySite.getSpid());
} else {
setmodelSite(model);
return "error.html";
}
} else if (CommonUtils.isEmpty(topicDTO.getSp_desc()) && topicDTO.getSpid() == 0) {
topicDTO.setSpid(null);
}
if (CommonUtils.isNotEmpty(topicDTO.getStart_date())) {
try {
topicDTO.setStart_date(String.valueOf(CommonUtils.parseDate(topicDTO.getStart_date(), "yyyy-MM-dd")));
} catch (Exception e) {
}
}
if (CommonUtils.isNotEmpty(topicDTO.getEnd_date())) {
try {
topicDTO.setEnd_date(String.valueOf(CommonUtils.parseDate(topicDTO.getEnd_date(), "yyyy-MM-dd")));
} catch (Exception e) {
}
}
PageInfo<ShyTopic> topicPage = topicService.getPage(topicDTO);
List<ShyTopic> list = topicPage.getList();
if (!list.isEmpty()) {
for (ShyTopic topic : list) {
if (!topic.getShenhe_status().equals(CommonConst.AUDIT_INTT)) {
String auditorId = topic.getAuditor_id();
String updater = CommonUtils.isEmpty(topic.getUpdater()) || "null".equals(topic.getUpdater()) ? "白名单" : topic.getUpdater();
updater = sitesService.getUpdater(updater, auditorId);
topic.setUpdater(updater);
}
//显示spid简称
if (CommonUtils.isNotNull(topic.getSp_id())) {
ShySites shySites = sitesService.findspidDescByspid(topic.getSp_id());
if (CommonUtils.isNotNull(shySites)) {
topic.setSp_desc(shySites.getName());
}
} else {
topic.setSp_desc("sp无法显示");
}
}
}
model.addAttribute("topicPage", topicPage);
model.addAttribute("pageSize", topicDTO.getPageSize());
model.addAttribute("Topic_id", topicDTO.getTopic_id());
model.addAttribute("Topic_name", topicDTO.getTopic_name());
model.addAttribute("Sp_desc", topicDTO.getSp_desc());
model.addAttribute("Start_date", topicDTO.getStart_date());
model.addAttribute("End_date", topicDTO.getEnd_date());
model.addAttribute("TopicStatus",topicDTO.getShenhe_status());
return "page/topic.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;
String[] topicIds = ids.split(",");
for (String id : topicIds) {
success = topicService.callback(id, "审核通过", CommonConst.AUDIT_SUCCESS, userId, "");
if (!success) {
return new ResponseBean(ErrorEnum.ERROR);
}
}
return new ResponseBean(ErrorEnum.SUCCESS);
}
/**
* 审核拒绝
*
* @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;
String[] contentIds = ids.split(",");
for (String id : contentIds) {
success = topicService.callback(id, msg, CommonConst.AUDIT_REFUSE, userId, "");
if (!success) {
return new ResponseBean(ErrorEnum.ERROR);
}
}
return new ResponseBean(ErrorEnum.SUCCESS);
}
/**
* 话题审核前台通知接口
*
* @return
*/
@GetMapping("/topicNotice")
@ResponseBody
public Map<String, Object> topicNotice() {
Map<String, Object> map = new HashMap<>(16);
ShyTopic shyTopic = new ShyTopic();
shyTopic.setShenhe_status(CommonConst.AUDIT_INTT);
shyTopic.setShenhe_type(CommonConst.AUDIT_TYPE_USER);
List<ShyTopic> shyTopicList = topicService.findShyTopic(shyTopic);
if (shyTopicList != null && shyTopicList.size() > 0) {
logger.info("您有" + shyTopicList.size() + "条新的话题审核,请注意查看!");
// 第三个提示框,避免冲突
map.put("id", "3");
map.put("title", "新话题审核通知");
map.put("content", "您有" + shyTopicList.size() + "条新的话题审核,请注意查看!");
map.put("url", localhost_url + "/topic/page?shenhe_status=0&receive=0");
return map;
}
return null;
}
}