RoleController.java
5.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
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
package com.tianbo.warehouse.controller;
import com.github.pagehelper.PageInfo;
import com.tianbo.warehouse.annotation.LogAnnotation;
import com.tianbo.warehouse.controller.response.ResultJson;
import com.tianbo.warehouse.model.ROLE;
import com.tianbo.warehouse.model.RoleDataPermission;
import com.tianbo.warehouse.model.RolePermission;
import com.tianbo.warehouse.service.RoleService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
@RestController()
@RequestMapping("/role")
public class RoleController {
@Autowired
RoleService roleService;
@GetMapping("/list")
public PageInfo<ROLE> list(@RequestParam(value = "pageNum",required = false,defaultValue = "1")
int pageNum,
@RequestParam(value = "pageSize",required = false,defaultValue = "10")
int pageSize,
@RequestParam(value = "roleName",required = false)
String roleName,
@RequestParam(value = "type", required = false)
String type){
return roleService.findAll(pageNum,pageSize, roleName, type);
}
@LogAnnotation(moduleName = "岗位/角色管理",operate = "岗位/角色添加")
@PostMapping("/add")
public ResultJson add(@RequestBody ROLE role){
int i =roleService.insertSelective(role);
return i==1 ? new ResultJson("200","添加权限成功") :new ResultJson("500","insert faild");
}
/**
* 设置角色的权限
* @return
*/
@LogAnnotation(moduleName = "岗位/角色管理",operate = "权限设置")
@PutMapping("/permSet")
public ResultJson permissionSet(@RequestBody RolePermission rolePermission){
int i = roleService.setRolePermissoin(rolePermission);
return i==1 ? new ResultJson("200","设置权限成功") :new ResultJson("500","设置权限失败");
}
/**
* 设置角色的的数据权限
* @return
*/
@LogAnnotation(moduleName = "数据权限设置",operate = "数据权限设置接口")
@PostMapping("/dataPermSet")
public ResultJson dataPermissionSet(@RequestBody RoleDataPermission roleDataPermission){
int i = roleService.setRoleDataPermissoin(roleDataPermission);
return i>0 ? new ResultJson("200","设置权限成功") :new ResultJson("500","设置权限失败");
}
/**
* 获取角色的的数据权限
* @return
*/
// @LogAnnotation(moduleName = "获取角色的的数据权限",operate = "获取角色的的数据权限")
@PostMapping("/roleDataPermGet")
public ResultJson roleDataPermGet(@RequestBody RoleDataPermission roleDataPermission){
RoleDataPermission permissions = roleService.getRoleDataPermissoin(roleDataPermission);
return new ResultJson("200","获取权限列表成功",permissions);
}
@LogAnnotation(moduleName = "岗位/角色管理",operate = "岗位/角色修改")
@PutMapping("/edit")
@ResponseBody
public ResultJson edit(@RequestBody @Valid ROLE role){
int i =roleService.updateByPrimaryKeySelective(role);
ResultJson resultJson = new ResultJson();
if (1==i){
resultJson = new ResultJson("200","修改成功");
}else {
resultJson = new ResultJson("500","insert faild");
}
return resultJson;
}
@LogAnnotation(moduleName = "岗位/角色管理",operate = "岗位/角色删除")
@DeleteMapping("/del")
public ResultJson reomve(@RequestBody ROLE role, HttpServletRequest request, HttpServletResponse response){
int i =roleService.deleteByPrimaryKey(role.getRoleId());
ResultJson resultJson = new ResultJson();
if (1==i){
resultJson = new ResultJson("200","删除成功");
}else {
resultJson = new ResultJson("500","insert faild");
}
return resultJson;
}
@LogAnnotation(moduleName = "岗位/角色管理",operate = "岗位/角色批量删除")
@GetMapping("/batchremove")
public ResultJson reomve(String ids, HttpServletRequest request, HttpServletResponse response){
ResultJson resultJson = new ResultJson();
if (roleService.deleteByPrimaryKey(Integer.valueOf(ids))>0){
resultJson = new ResultJson("200","删除成功");
}else {
resultJson = new ResultJson("500","insert faild");
}
return resultJson;
}
// @LogAnnotation(moduleName = "岗位/角色管理", operate = "添加组织机构token")
@PostMapping("/createRoleToken")
public ResultJson createRoleToken(@RequestParam(value = "roleId") Integer roleId){
String roleToken = roleService.createRoleToken(roleId);
if (StringUtils.isNotBlank(roleToken)){
return new ResultJson("200", "success", roleToken);
}
return new ResultJson("201","error");
}
@PostMapping("/permRoleToken")
public ResultJson permRoleToken(@RequestBody RolePermission rolePermission){
return roleService.permRoleToken(rolePermission);
}
}