PermssionController.java
5.5 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.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.PERMISSION;
import com.tianbo.warehouse.model.USERS;
import com.tianbo.warehouse.service.PermissionService;
import com.tianbo.warehouse.service.UserService;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
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;
import java.util.List;
@RestController()
@RequestMapping("/perm")
public class PermssionController {
@Autowired
PermissionService permissionService;
@Autowired
UserService userService;
@GetMapping("/list")
public PageInfo<PERMISSION> list(@RequestParam(value = "pageNum",required = false,defaultValue = "1")
int pageNum,
@RequestParam(value = "pageSize",required = false,defaultValue = "5")
int pageSize,
@RequestParam(value = "name", required = false) String name){
return permissionService.findAll(pageNum,pageSize, name);
}
@LogAnnotation(moduleName = "权限管理",operate = "权限添加")
@PostMapping("/add")
public ResultJson add(@RequestBody PERMISSION permission){
int i =permissionService.insertSelective(permission);
ResultJson resultJson = new ResultJson();
if (1==i){
resultJson = new ResultJson("200","添加成功");
}else {
resultJson = new ResultJson("500","insert faild");
}
return resultJson;
}
@LogAnnotation(moduleName = "权限管理",operate = "权限修改")
@PutMapping("/edit")
@ResponseBody
public ResultJson edit(@RequestBody @Valid PERMISSION permission){
int i =permissionService.updateByPrimaryKeySelective(permission);
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 PERMISSION permission, HttpServletRequest request, HttpServletResponse response){
Integer permissionId = permission.getPermissionId();
int i =permissionService.deleteByPrimaryKey(permission.getPermissionId());
ResultJson resultJson = new ResultJson();
if (1==i){
resultJson = new ResultJson("200","删除成功");
}else {
resultJson = new ResultJson("500","insert faild");
}
return resultJson;
}
@LogAnnotation(moduleName = "权限管理",operate = "权限批量删除")
@PostMapping("/batchremove")
public ResultJson reomve(@RequestBody List<Integer> ids, HttpServletRequest request, HttpServletResponse response){
ResultJson resultJson = new ResultJson();
if (permissionService.deleteByPrimaryKeys(ids)>0){
resultJson = new ResultJson("200","删除成功");
}else {
resultJson = new ResultJson("400","删除失败");
}
return resultJson;
}
// @LogAnnotation(moduleName = "权限管理",operate = "查找权限")
@GetMapping("/findByRoleId")
public ResultJson findByRoleId(@RequestParam Integer roleId){
ResultJson resultJson = new ResultJson();
List<PERMISSION> list = permissionService.findByRoleId(roleId);
resultJson.setData(list);
resultJson.setCode("1");
resultJson.setMsg("SUCCESS");
return resultJson;
}
@GetMapping("/flushPermCache")
public ResultJson flushPermCache(){
permissionService.flushCache();
return new ResultJson("200","清理缓存成功");
}
@GetMapping("/userMenu")
public ResultJson<List<PERMISSION>> userMenu(
@RequestParam(value = "userId") Integer userId){
return new ResultJson<List<PERMISSION>>("200","success",permissionService.getUserMenuTreeByUserId(userId));
}
@ApiOperation(value = "所有目录列表", notes = "查询所有目录菜单的树形结构信息")
@GetMapping("/menu")
public ResultJson<List<PERMISSION>> menu(){
return new ResultJson<List<PERMISSION>>("200","success",permissionService.getUserMenuTreeByUserId(0));
}
@ApiOperation(value = "根据用户ID查询用户权限", notes = "根据用户ID查询用户权限")
@GetMapping("/getPermission")
public ResultJson getPermission(
@RequestHeader("Authorization") String token,
@RequestParam(value = "url",required = false)String url,
@RequestParam(value = "name",required = false)String name){
Boolean result = permissionService.getPermission(token, url, name);
return new ResultJson("200","success",result);
}
@GetMapping("/getUserPermByToken")
public ResultJson get(
@RequestHeader("Authorization") String token,
@RequestParam(value = "path") String path
){
System.out.println("im in");
USERS userInfo = userService.getUserDataPermissionsByPath(token, path);
return new ResultJson("200","get user data permissions success",userInfo);
}
}