ManagerCtrl.java
5.83 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
package com.ui.ctrl;
import com.ui.User.UserAuthLocal;
import com.ui.contants.HttpUriContants;
import com.ui.http.HttpRestClient;
import com.ui.model.BaseResponse;
import com.ui.model.req.AuthModule;
import com.ui.model.req.PageRequest;
import com.ui.model.req.User;
import org.apache.commons.lang.RandomStringUtils;
import org.apache.commons.lang.StringUtils;
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.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;
@Controller
@RequestMapping("manage")
public class ManagerCtrl {
Logger log = LoggerFactory.getLogger(ManagerCtrl.class);
@Autowired
HttpRestClient httpRestClient;
@Autowired
UserAuthLocal userAuthLocal;
@RequestMapping("/toUser")
public ModelAndView toAddUser() {
return new ModelAndView("manager/user");
}
@RequestMapping("/toModule")
public ModelAndView toAddModule(Model model) {
BaseResponse baseResponse = httpRestClient.defaultPost(HttpUriContants.GET_All_MODULEGROUP, null, BaseResponse.class);
if (baseResponse != null) {
model.addAttribute("modulegroups", baseResponse.getData());
}
return new ModelAndView("manager/module");
}
@RequestMapping("/saveUser")
@ResponseBody
public BaseResponse saveUser(@RequestBody User user, HttpSession session) {
BaseResponse baseResponse = null;
if (StringUtils.isNotBlank(user.getModules()) && StringUtils.endsWith(user.getModules(), ",")) {
user.setModules(user.getModules().substring(0, user.getModules().length() - 1));
}
if (StringUtils.isNotBlank(user.getModuleGroups()) && StringUtils.endsWith(user.getModuleGroups(), ",")) {
user.setModuleGroups(user.getModuleGroups().substring(0, user.getModuleGroups().length() - 1));
}
if(StringUtils.isBlank(user.getEmail())||StringUtils.isBlank(user.getMobile())){
return new BaseResponse(201, "邮箱、手机号不能为空");
}
if(StringUtils.isBlank(user.getLadpName())){
user.setLadpName(user.getEmail().substring(0,user.getEmail().indexOf("@")));
}
if (user.getId() < 1) {//add
if (userAuthLocal.getUserByname(user.getName()) != null) {
return new BaseResponse(201, "用户已经存在");
}
user.setPwd(RandomStringUtils.random(8, true, true));
baseResponse = httpRestClient.defaultPost(HttpUriContants.USER_INSERT, user, BaseResponse.class);
} else {
User u = (User) session.getAttribute("user");
String username = u.getName();
if ("admin".equals(user.getName()) && !"admin".equals(username)) {
return new BaseResponse(201, "此用户无法修改");
}
baseResponse = httpRestClient.defaultPost(HttpUriContants.USER_UPDATE, user, BaseResponse.class);
}
userAuthLocal.flushUser(user.getName());
return baseResponse;
}
@RequestMapping("/getUsers")
@ResponseBody
public BaseResponse getUsers(PageRequest req, String keys) {
BaseResponse response = httpRestClient.defaultPost(HttpUriContants.GET_USERS + "?keys="+keys, req, BaseResponse.class);
return response;
}
@RequestMapping("/getAllUser")
@ResponseBody
public BaseResponse getAllUser(PageRequest req) {
BaseResponse response = httpRestClient.defaultPost(HttpUriContants.GET_USERS_ALL, req, BaseResponse.class);
return response;
}
@RequestMapping("/deleteUser")
@ResponseBody
public BaseResponse deleteUser(String name) {
if ("admin".equals(name)) {
return new BaseResponse(201, "此用户无法删除");
}
Map map = new HashMap<>();
map.put("name", name);
BaseResponse response = httpRestClient.defaultGet(HttpUriContants.USER_DELETE_NAME, BaseResponse.class, map);
userAuthLocal.flushUser(name);
return response;
}
@RequestMapping("/saveAuthModule")
@ResponseBody
public BaseResponse saveAuthModule(@RequestBody AuthModule authModule) {
BaseResponse baseResponse = null;
if (authModule.getId() < 1) {//add
if (userAuthLocal.getAuthModuleByname(authModule.getModuleName()) != null) {
return new BaseResponse(201, "模块已经存在");
}
baseResponse = httpRestClient.defaultPost(HttpUriContants.MODULE_INSERT, authModule, BaseResponse.class);
} else {
baseResponse = httpRestClient.defaultPost(HttpUriContants.MODULE_UPDATE, authModule, BaseResponse.class);
}
userAuthLocal.flushModule(authModule.getModuleName());
return baseResponse;
}
@RequestMapping("/getAuthModules")
@ResponseBody
public BaseResponse getAuthModules(PageRequest req,String keys) {
BaseResponse response = httpRestClient.defaultPost(HttpUriContants.GET_MODULES+"?keys="+keys, req, BaseResponse.class);
return response;
}
@RequestMapping("/deleteAuthModule")
@ResponseBody
public BaseResponse deleteAuthModule(String name) {
if ("manage".equals(name)) {
return new BaseResponse(201, "此模块无法delete");
}
Map map = new HashMap<>();
map.put("name", name);
BaseResponse response = httpRestClient.defaultGet(HttpUriContants.MODULE_DELETE_NAME, BaseResponse.class, map);
userAuthLocal.flushModule(name);
return response;
}
}