zhuguifei
2026-03-10 58402bd5e762361363a0f7d7907153c77dbb819f
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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
package com.shlanbao.tzsc.pms.sys.role.controller;
 
import java.util.List;
 
import javax.servlet.http.HttpServletRequest;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
 
import com.shlanbao.tzsc.base.controller.BaseController;
import com.shlanbao.tzsc.base.model.Json;
import com.shlanbao.tzsc.base.model.PageParams;
import com.shlanbao.tzsc.pms.sys.resource.beans.ResourceBean;
import com.shlanbao.tzsc.pms.sys.role.beans.RoleBean;
import com.shlanbao.tzsc.pms.sys.role.service.RoleServiceI;
import com.shlanbao.tzsc.pms.sys.user.beans.UserBean;
/**
 * 角色管理控制器
 * <li>@author Leejean
 * <li>@create 2014-7-12上午10:03:27
 */
@Controller
@RequestMapping("/pms/sysRole")
public class RoleController extends BaseController {
    @Autowired
    private RoleServiceI roleService;
    /**
     * 查询所有角色
     * @author Leejean
     * @create 2014-7-12上午10:03:08
     */
    @ResponseBody
    @RequestMapping("/getAllRoles")
    public List<RoleBean> getAllRoles(RoleBean roleBean){
        try {
            return roleService.getAllRoles(roleBean);
        } catch (Exception e) {
            log.error("查询角色异常", e);
        }
        return null;
    }
    /**
     * 调转到角色新增页面
     * @author Leejean
     * @create 2014-8-21上午10:40:00
     * @return
     */
    @RequestMapping("/goToRoleAddJsp")
    public String goToRoleAddJsp(){
        try {
            return "/pms/sys/role/roleAdd";
        } catch (Exception e) {
            log.error("调转到角色新增页面", e);
            e.printStackTrace();
        }
        return "/error/500";
    }
    /**
     * 新增角色
     * @author Leejean
     * @create 2014-8-21上午08:44:45
     * @param roleBean
     * @return
     */
    @ResponseBody
    @RequestMapping("/addRole")
    public Json addRole(RoleBean roleBean){
        Json json = new Json();
        try {
            roleService.addRole(roleBean);
            json.setSuccess(true);
            json.setMsg("新增角色成功!");
        } catch (Exception e) {
            log.error("新增角色异常", e);
            json.setSuccess(false);
            json.setMsg("新增角色失败!");
        }
        return json;
    }
    /**
     * 调转到角色编辑页面
     * @author Leejean
     * @create 2014-8-21上午10:38:51
     * @param id
     * @param request
     * @return
     */
    @RequestMapping("/goToRoleEditJsp")
    public String goToRoleEditJsp(String id,HttpServletRequest request){
        try {
            request.setAttribute("checkedRole", roleService.getSysRoleById(id));
            return "/pms/sys/role/roleEdit";
        } catch (Exception e) {
            log.error("调转到角色编辑页面失败", e);
            e.printStackTrace();
        }
        return "/error/500";
    }
    /**
     * 编辑角色
     * @author Leejean
     * @create 2014-8-21上午08:44:45
     * @param roleBean
     * @return
     */
    @ResponseBody
    @RequestMapping("/editRole")
    public Json editRole(RoleBean roleBean){
        Json json = new Json();
        try {
            roleService.editRole(roleBean);
            json.setSuccess(true);
            json.setMsg("编辑角色成功!");
        } catch (Exception e) {
            log.error("编辑角色异常", e);
            json.setSuccess(false);
            json.setMsg("编辑角色失败!");
        }
        return json;
    }
    /**
     * 删除角色
     * @author Leejean
     * @create 2014-8-21上午08:44:45
     * @param roleBean
     * @return
     */
    @ResponseBody
    @RequestMapping("/deleteRole")
    public Json deleteRole(String id){
        Json json = new Json();
        try {
            roleService.deleteRole(id);
            json.setSuccess(true);
            json.setMsg("删除角色成功!");
        } catch (Exception e) {
            log.error("删除角色异常", e);
            json.setSuccess(false);
            json.setMsg("删除角色失败!");
        }
        return json;
    }
    /**
     * 批量删除角色
     * @author Leejean
     * @create 2014-8-21上午08:44:45
     * @param ids ids串
     * @return
     */
    @ResponseBody
    @RequestMapping("/batchDeleteRoles")
    public Json batchDeleteRoles(String ids){
        Json json = new Json();
        try {
            roleService.batchDeleteRoles(ids);
            json.setSuccess(true);
            json.setMsg("批量删除角色成功!");
        } catch (Exception e) {
            log.error("批量删除角色异常", e);
            json.setSuccess(false);
            json.setMsg("批量删除角色失败!");
        }
        return json;
    }
    /**
     * 跳转到分配权限页面
     * @author Leejean
     * @create 2014年8月25日下午9:41:58
     * @param id 角色id
     * @return
     */
    @RequestMapping("/goToAssignResourceJsp")
    public String goToAssignResourceJsp(HttpServletRequest request,String id){
        request.setAttribute("checkedRoleId",id);
        return "/pms/sys/role/assignResource";
    }
    /**
     * 根据当前角色加载该角色拥有的资源列表
     * @author Leejean
     * @create 2014年8月25日下午9:40:23
     * @param id 角色id
     * @return 资源列表
     */
    @RequestMapping("/getResourcesByRole")
    @ResponseBody
    public List<ResourceBean> getResourcesByRole(String id){
        try {
            return roleService.getResourcesByRole(id);
        } catch (Exception e) {
            log.error("根据当前角色加载该角色拥有的资源列表失败", e);
        }
        return null;
    }
    @RequestMapping("/goToBatchAssignResourceJsp")
    public String goToBatchAssignResourceJsp(){
        return "/pms/sys/role/batchAssignResource";
    }
    /**
     * 给角色分配权限
     * @author Leejean
     * @create 2014-8-21上午09:04:05
     * @param id 角色id
     * @param ids 资源id串
     * @return
     */
    @ResponseBody
    @RequestMapping("/assignResourceToRole")
    public Json assignResourceToRole(String id,String ids){
        Json json = new Json();
        try {
            roleService.assignResourceToRole(id,ids);
            json.setSuccess(true);
            json.setMsg("给角色分配权限成功!");
        } catch (Exception e) {
            log.error("给角色分配权限异常", e);
            json.setSuccess(false);
            json.setMsg("给角色分配权限失败!");
        }
        return json;
    }
    /**
     * 批量给角色分配权限
     * @author Leejean
     * @create 2014-8-21上午09:04:05
     * @param id 角色id串
     * @param rids 资源id串
     * @return
     */
    @ResponseBody
    @RequestMapping("/batchAssignResourceToRoles")
    public Json batchAssignResourceToRoles(String rids,String resids){
        Json json = new Json();
        try {
            roleService.batchAssignResourceToRoles(rids,resids);
            json.setSuccess(true);
            json.setMsg("批量给角色分配权限成功!");
        } catch (Exception e) {
            log.error("批量给角色分配权限异常", e);
            json.setSuccess(false);
            json.setMsg("批量给角色分配权限失败!");
        }
        return json;
    }
    /**
     * 跳转到给角色分配用户界面
     * @author Leejean
     * @create 2014年8月25日下午9:41:58
     * @param id 角色id
     * @return
     */
    @RequestMapping("/goToAssignUserJsp")
    public String goToAssignUserJsp(HttpServletRequest request,String id){
        request.setAttribute("checkedRoleId",id);
        return "/pms/sys/role/assignUser";
    }
    /**
     * 给角色分配用户
     * @author Leejean
     * @create 2014年8月29日上午11:38:43
     * @param id 角色id
     * @param ids 用户ids
     * @return
     */
    @ResponseBody
    @RequestMapping("/assignUsersToRole")
    public Json assignUsersToRole(String id,String ids){
        Json json = new Json();
        try {
            roleService.assignUsersToRole(id,ids);
            json.setSuccess(true);
            json.setMsg("给角色分配用户成功!");
        } catch (Exception e) {
            log.error("给角色分配用户异常", e);
            json.setMsg("给角色分配用户失败!");
        }
        return json;
    }
    /**
     * 查询待分配的角色用户
     * @author Leejean
     * @create 2014年8月25日下午9:41:58
     * @param id 角色id
     * @return
     */
    @ResponseBody
    @RequestMapping("/getRoleUnAssignedUsers")
    public List<UserBean> getRoleUnAssignedUsers(String oid,String name,PageParams pageParams){
        try {
            return roleService.getRoleUnAssignedUsers(oid,name);
        } catch (Exception e) {
            log.error("获得该角色用户分配情况异常", e);
        }
        return null;
    }
    /**
     * 查询已分配的角色用户
     * @author Leejean
     * @create 2014年8月25日下午9:41:58
     * @param id 角色id
     * @return
     */
    @ResponseBody
    @RequestMapping("/getRoleAssignedUsers")
    public List<UserBean> getRoleAssignedUsers(String oid,UserBean userBean){
        try {
            return roleService.getRoleAssignedUsers(oid);
        } catch (Exception e) {
            log.error("获得该角色用户分配情况异常", e);
        }
        return null;
    }
}