UsersController.java
6.86 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
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.ShySites;
import com.cnlive.shenhe.entity.ShyUsers;
import com.cnlive.shenhe.serviceImpl.SitesServiceImpl;
import com.cnlive.shenhe.serviceImpl.UsersServiceImpl;
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.HashMap;
import java.util.List;
import java.util.Map;
/**
* @Auther: liwei
* @Date: 2019/08/20 14:22
* @Description:
*/
@Controller
@RequestMapping("/users")
public class UsersController extends BaseController {
private static Logger logger = LoggerFactory.getLogger(UsersController.class);
@Autowired
UsersServiceImpl usersService;
@Autowired
SitesServiceImpl sitesService;
/**
* 登录入口
*/
@Value("${SERVICE_LOGIN}")
private String SERVICE_LOGIN;
/**
* 本机的名称
*/
@Value("${spring.localhost.url}")
private String redirectURL;
@GetMapping(value = "/{id}")
@ResponseBody
public Object getTest(@PathVariable Integer id) {
return usersService.get(id);
}
@RequestMapping("/login")
public String index(HttpServletRequest request) {
AttributePrincipal principal = (AttributePrincipal) request.getUserPrincipal();
if (CommonUtils.isNull(principal)) {
return "redirect:https://user.cnlive.com/OpenSSO2/login?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.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);
return "redirect:" + redirectURL + "/videos/page?video_title=&start_date=&end_date=&state=0&receive=0&video_priority=";
}
}
return "page/error.html";
}
@RequestMapping("/logout")
public String logout(HttpSession session) {
session.invalidate();
return "redirect:https://user.cnlive.com/OpenSSO2/logout?service=" + SERVICE_LOGIN;
}
@GetMapping(value = "/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(spid);
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);
return "page/users.html";
}
/**
* 获取通知是否显示
*
* @param
* @param session
* @return
*/
@PostMapping(value = "/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 isShow_chinnal = false;//是否显示频道消息框
boolean isShow_liveApply = false;//是否显示直播申请消息框
boolean isShow_topic = false;//是否显示话题审核消息框
if (CommonUtils.isNotEmpty(shyUser.getNotice_show()) && shyUser.getNotice_show().contains(CommonConst.NOTICE_CHANNAL.toString())) {
isShow_chinnal = true;
}
if (CommonUtils.isNotEmpty(shyUser.getNotice_show()) && shyUser.getNotice_show().contains(CommonConst.NOTICE_LIVEAPPLY.toString())) {
isShow_liveApply = true;
}
if (CommonUtils.isNotEmpty(shyUser.getNotice_show()) && shyUser.getNotice_show().contains(CommonConst.NOTICE_TOPIC.toString())) {
isShow_topic = true;
}
Map<String, Object> map = new HashMap<>();
map.put("isShow_chinnal", isShow_chinnal);
map.put("isShow_liveApply", isShow_liveApply);
map.put("isShow_topic", isShow_topic);
return map;
}
@PostMapping(value = "/write")
public String write(Model model, Integer userId, String[] write_notice, HttpSession session, String redirect_url) {
SessionUser sessionUser = (SessionUser) session.getAttribute(SessionUser.getSessionKey());
// Integer spid = sessionUser.getSpid();
// if (spid != 0) {
// return "page/error.html";
// }
ShyUsers user = usersService.get(userId);
String write = "";
if (CommonUtils.isNotNull(write_notice) && write_notice.length > 0) {
for (String w : write_notice) {
write = write + "," + w;
}
write = write.substring(1);
}
user.setNotice_show(write);
boolean success = usersService.update(user);
if (success) {
return "redirect:" + redirect_url;
} else {
setmodelResult(model);
return "error.html";
}
}
}