UsersController.java
8.69 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
package com.cnlive.shenhe.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.cnlive.shenhe.bean.SessionUser;
import com.cnlive.shenhe.dto.UsersDTO;
import com.cnlive.shenhe.entity.ShyLog;
import com.cnlive.shenhe.entity.ShySites;
import com.cnlive.shenhe.entity.ShyUsers;
import com.cnlive.shenhe.service.ShyLogService;
import com.cnlive.shenhe.service.SitesService;
import com.cnlive.shenhe.service.UsersService;
import com.cnlive.shenhe.utils.CommonConst;
import com.cnlive.shenhe.utils.CommonUtils;
import com.github.pagehelper.PageInfo;
import org.jasig.cas.client.authentication.AttributePrincipal;
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.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @Auther: liwei
* @Date: 2019/08/20 14:22
* @Description:
*/
@Controller
public class UsersController extends BaseController {
private static Logger logger = LoggerFactory.getLogger(UsersController.class);
@Autowired
private UsersService usersService;
@Autowired
private SitesService sitesService;
@Autowired
private ShyLogService shyLogService;
/**
* 登录入口
*/
@Value("${SERVICE_LOGIN}")
private String SERVICE_LOGIN;
/**
* 注销
*/
@Value("${SERVICE_LOGINOUT}")
private String SERVICE_LOGINOUT;
/**
* 本机的名称
*/
@Value("${spring.localhost.url}")
private String redirect_url;
@Value("${CAS_SERVER_LOGIN_URL}")
private String CAS_SERVER_LOGIN_URL;
@Value("${CAS_SERVER_URL_PREFIX}")
private String CAS_SERVER_URL_PREFIX;
@GetMapping(value = "/users/{id}")
@ResponseBody
public Object getTest(@PathVariable Integer id) {
return usersService.get(id);
}
/**
* 登录
*
* @param request
* @return
*/
@RequestMapping({"/users/login", "/"})
public String index(HttpServletRequest request) {
AttributePrincipal principal = (AttributePrincipal) request.getUserPrincipal();
if (CommonUtils.isNull(principal)) {
return "redirect:" + CAS_SERVER_LOGIN_URL + "?service=" + SERVICE_LOGIN;
}
//用户ID
String id = principal.getName();
if (CommonUtils.isNotEmpty(id)) {
ShyUsers user = usersService.get(Integer.parseInt(id));
if (CommonUtils.isNotNull(user) && user.getState()) {
SessionUser sessionUser = new SessionUser();
sessionUser.setId(id);
sessionUser.setUserId(user.getUser_id());
sessionUser.setSpid(Integer.parseInt(principal.getAttributes().get("new_sp_id").toString()));
sessionUser.setUserName(user.getUsername());
sessionUser.setCompany(user.getCompany_brief());
sessionUser.setEmail(user.getEmail());
sessionUser.setLogo(user.getUser_logo());
sessionUser.setMaster(user.getMaster());
request.getSession().setAttribute(SessionUser.SESSION_KEY, sessionUser);
ShyLog shyLog = new ShyLog();
shyLog.setVideoId("-");
shyLog.setVideoName("-");
shyLog.setOperator(user.getUsername() + "(" + user.getId() + ")");
shyLog.setOperationTime(new Date());
shyLog.setOperationType("登录");
shyLog.setRemark(user.getUsername() + "--" + "登录");
shyLogService.addShyLog(shyLog);
return "redirect:" + redirect_url + "/videos/page?state=0&receive=0&page=1&pageSize=10";
}
}
return "page/error.html";
}
/**
* 注销
*
* @param session
* @return
*/
@RequestMapping("/users/logout")
public String logout(HttpSession session) {
SessionUser sessionUser = (SessionUser) session.getAttribute(SessionUser.SESSION_KEY);
if (sessionUser != null) {
ShyLog shyLog = new ShyLog();
shyLog.setVideoId("-");
shyLog.setVideoName("-");
shyLog.setOperator(sessionUser.getUserName() + "(" + sessionUser.getId() + ")");
shyLog.setOperationTime(new Date());
shyLog.setOperationType("注销");
shyLog.setRemark(sessionUser.getUserName() + "--" + "注销");
shyLogService.addShyLog(shyLog);
}
session.invalidate();
return "redirect:" + CAS_SERVER_URL_PREFIX + "/logout?service=" + SERVICE_LOGIN;
}
/**
* 用户列表
*
* @param model
* @param usersDTO
* @param session
* @return
*/
@GetMapping(value = "/users/page")
public String page(Model model, UsersDTO usersDTO, HttpSession session) {
logger.info("列表请求参数:{}", JSON.toJSONString(usersDTO));
SessionUser sessionUser = (SessionUser) session.getAttribute(SessionUser.getSessionKey());
if (CommonUtils.isNull(sessionUser)) {
return "redirect:/users/login";
}
Integer spid = sessionUser.getSpid();
//usersDTO.setSp_id(usersDTO.getSp_id());
//if (spid == 0) {
// usersDTO.setSp_id(null);
//}
PageInfo<ShyUsers> usersPage = usersService.getPage(usersDTO);
List<ShyUsers> list = usersPage.getList();
JSONObject notice = CommonConst.NOTICE;
if (!list.isEmpty()) {
for (ShyUsers users : list) {
//显示spid简称
ShySites shySites = sitesService.findspidDescByspid(users.getSp_id());
if (CommonUtils.isNotNull(shySites)) {
users.setSp_desc(shySites.getName());
}
}
}
model.addAttribute("usersPage", usersPage);
model.addAttribute("pageSize", usersDTO.getPageSize());
model.addAttribute("notice", notice);
model.addAttribute("Sp_id", usersDTO.getSp_id());
model.addAttribute("Username", usersDTO.getUsername());
model.addAttribute("Mobile", usersDTO.getMobile());
return "page/users.html";
}
/**
* 获取通知是否显示
*
* @param
* @param session
* @return
*/
@PostMapping(value = "/users/getNoticeShow")
@ResponseBody
public Map<String, Object> getNoticeShow(HttpSession session) {
SessionUser sessionUser = (SessionUser) session.getAttribute(SessionUser.getSessionKey());
ShyUsers shyUser = new ShyUsers();
shyUser.setUser_id(sessionUser.getUserId());
shyUser = usersService.select(shyUser);
//是否显示频道消息框
boolean isShowChinnal = false;
//是否显示直播申请消息框
boolean isShowLiveApply = false;
//是否显示话题审核消息框
boolean isShowTopic = false;
if (CommonUtils.isNotEmpty(shyUser.getNotice_show()) && shyUser.getNotice_show().contains(CommonConst.NOTICE_CHANNAL.toString())) {
isShowChinnal = true;
}
if (CommonUtils.isNotEmpty(shyUser.getNotice_show()) && shyUser.getNotice_show().contains(CommonConst.NOTICE_LIVEAPPLY.toString())) {
isShowLiveApply = true;
}
if (CommonUtils.isNotEmpty(shyUser.getNotice_show()) && shyUser.getNotice_show().contains(CommonConst.NOTICE_TOPIC.toString())) {
isShowTopic = true;
}
Map<String, Object> map = new HashMap<>(16);
map.put("isShowChinnal", isShowChinnal);
map.put("isShowLiveApply", isShowLiveApply);
map.put("isShowTopic", isShowTopic);
return map;
}
@PostMapping(value = "/users/write")
public String write(Model model, Integer userId, String[] write_notice, HttpSession session, String redirect_url) {
SessionUser sessionUser = (SessionUser) session.getAttribute(SessionUser.getSessionKey());
ShyUsers user = usersService.get(userId);
StringBuilder write = new StringBuilder();
if (CommonUtils.isNotNull(write_notice) && write_notice.length > 0) {
for (String w : write_notice) {
write.append(",").append(w);
}
write = new StringBuilder(write.substring(1));
}
user.setNotice_show(write.toString());
boolean success = usersService.update(user);
if (success) {
return "redirect:" + redirect_url;
} else {
setmodelResult(model);
return "error.html";
}
}
}