ManagerCtrl.java
5.65 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
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.AuthGroup;
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;
@Autowired
UserSaveComponent userSaveComponent;
@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("/toAuthority")
public ModelAndView toAuthority(Model model) {
return new ModelAndView("manager/authgroup");
}
@RequestMapping("/getAuthorityGroup")
@ResponseBody
public BaseResponse getAuthorityGroup() {
BaseResponse response = httpRestClient.defaultPost(HttpUriContants.GET_AUTHORITY_GROUP, null
, BaseResponse.class);
return response;
}
@RequestMapping("/getUsersByAuthGroup")
@ResponseBody
public BaseResponse getUsersByAuthGroup(String id) {
if(id==null){
id="";
}
BaseResponse response = httpRestClient.defaultPost(HttpUriContants.USER_BY_AUTH_GROUP+"?id="+id, null
, BaseResponse.class);
return response;
}
@RequestMapping("/saveAuthGroup")
@ResponseBody
public BaseResponse saveAuthGroup(@RequestBody AuthGroup authGroup) {
return httpRestClient.defaultPost(HttpUriContants.GET_AUTHORITY_GROUP_SAVE, authGroup, BaseResponse.class);
}
@RequestMapping("/deleteAuthGroup")
@ResponseBody
public BaseResponse deleteAuthGroup(Integer id) {
Map map = new HashMap<>();
map.put("id", id);
return httpRestClient.defaultGet(HttpUriContants.GET_AUTHORITY_GROUP_DELETE, BaseResponse.class,map);
}
@RequestMapping("/saveUser")
@ResponseBody
public BaseResponse saveUser(@RequestBody User user, HttpSession session) {
return userSaveComponent.saveUser(user,session);
}
@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;
}
}