UsersController.java
6.89 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
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.ShySites;
import com.cnlive.shenhe.entity.ShyUsers;
import com.cnlive.shenhe.entity.ShyUsersfree;
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.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.print.attribute.HashAttributeSet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
/**
* @Auther: liwei
* @Date: 2019/08/20 14:22
* @Description:
*/
@Controller
@RequestMapping("/users")
public class UsersController extends BaseController {
@Autowired
UsersServiceImpl usersService;
@Autowired
SitesServiceImpl sitesService;
@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=http://test.shen.cnlive.com:82/users/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:http://test.shen.cnlive.com:82/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=http://test.shen.cnlive.com:82/users/login";
}
@GetMapping(value = "/page")
public String page(Model model, Integer page, Integer pageSize, String orderByClause,
String username, String mobile, Integer sp_id, String company_brief, HttpSession session) {
SessionUser sessionUser = (SessionUser) session.getAttribute(SessionUser.getSessionKey());
if(CommonUtils.isNull(sessionUser)){
return "redirect:/users/login";
}
Integer spid = sessionUser.getSpid();
if (spid == 0) spid = null;
if (CommonUtils.isNull(page)) page = 1;
if (CommonUtils.isNull(pageSize)) pageSize = 10;
PageInfo<ShyUsers> usersPage = usersService.getPage(page, pageSize, orderByClause, username,mobile,sp_id,company_brief);
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", pageSize);
model.addAttribute("notice", notice);
return "page/users.html";
}
/**
* 获取通知是否显示
* @param showType
* @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())&­User.getNotice_show().contains(CommonConst.NOTICE_CHANNAL.toString())){
isShow_chinnal=true;
}
if(CommonUtils.isNotEmpty(shyUser.getNotice_show())&­User.getNotice_show().contains(CommonConst.NOTICE_LIVEAPPLY.toString())){
isShow_liveApply=true;
}
if(CommonUtils.isNotEmpty(shyUser.getNotice_show())&­User.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 {
setmodel_result(model);
return "error.html";
}
}
}