PermissionJsonContorller.java
3.3 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
package com.tianbo.controller.json;
import com.tianbo.common.ModelAndPage;
import com.tianbo.model.*;
import com.tianbo.service.PermissionService;
import com.tianbo.service.RolePermissionService;
import com.tianbo.util.dao.Page;
import com.tianbo.util.json.ResponseModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.List;
@Controller
@RequestMapping("/permission")
public class PermissionJsonContorller {
//service类
@Autowired
private PermissionService permissionService;
@Autowired
private RolePermissionService rolePermissionService;
@RequestMapping("list.json")
@ResponseBody
public ModelAndPage Permissionlist(){ //所有权限列表
PermissionExample example = new PermissionExample();
//调用service方法得到用户列表
List<Permission> pms = permissionService.selectByExample(example);
ModelAndPage modelAndPage = new ModelAndPage(pms,new Page());
return modelAndPage;
}
@RequestMapping(value = "listByRole.json",method = RequestMethod.POST)
@ResponseBody
public ModelAndPage listByRole(@RequestBody RolePermission rolePermission){ //角色权限列表
BigDecimal testID = new BigDecimal(1);
RolePermissionExample example = new RolePermissionExample();
example.createCriteria().andRoleIdEqualTo(testID);
//调用service方法得到用户列表
List<RolePermission> rp = rolePermissionService.selectByExample(example);
ModelAndPage modelAndPage = new ModelAndPage(rp,new Page());
return modelAndPage;
}
@RequestMapping("update.json")
@ResponseBody
public ResponseModel insertByroleID(@RequestBody RolePermission rolePermission){
BigDecimal roleId = rolePermission.getRoleId();
//先删除以前的权限绑定。
//再插入新的权限绑定.
RolePermissionExample delExample = new RolePermissionExample();
delExample.createCriteria().andRoleIdEqualTo(roleId);
int delSuccess = rolePermissionService.deleteByExample(delExample);
if (delSuccess>0){
//循环取出提交的已选择的Permission id列表,再插入
for(Integer PmsId:rolePermission.getPmList()){
RolePermission rolePermission1 = new RolePermission();
rolePermission1.setRoleId(roleId);
rolePermission1.setPermissionId(new BigDecimal(PmsId));
int i = rolePermissionService.insert(rolePermission1);
if (i<=0){
return new ResponseModel(500,"权限更新失败");
}
}
}else {
return new ResponseModel(500,"权限更新失败");
}
return new ResponseModel(200,"权限更新成功");
}
@RequestMapping("edit.json")
@ResponseBody
public ModelAndPage edit(){
PermissionExample example = new PermissionExample();
//调用service方法得到用户列表
List<Permission> pms = permissionService.selectByExample(example);
ModelAndPage modelAndPage = new ModelAndPage(pms,new Page());
return modelAndPage;
}
}