|
@@ -6,9 +6,9 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
6
|
6
|
import com.yunzhi.demo.common.BaseController;
|
7
|
7
|
import com.yunzhi.demo.common.Constants;
|
8
|
8
|
import com.yunzhi.demo.common.ResponseBean;
|
9
|
|
-import com.yunzhi.demo.entity.SysLogin;
|
10
|
|
-import com.yunzhi.demo.entity.SysUser;
|
11
|
|
-import com.yunzhi.demo.entity.SysUserRole;
|
|
9
|
+import com.yunzhi.demo.common.StringUtils;
|
|
10
|
+import com.yunzhi.demo.entity.*;
|
|
11
|
+import com.yunzhi.demo.service.ISysMenuService;
|
12
|
12
|
import com.yunzhi.demo.service.ISysUserRoleService;
|
13
|
13
|
import io.swagger.annotations.Api;
|
14
|
14
|
import io.swagger.annotations.ApiOperation;
|
|
@@ -22,7 +22,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
22
|
22
|
import org.springframework.web.bind.annotation.RequestMethod;
|
23
|
23
|
import org.springframework.web.bind.annotation.RequestParam;
|
24
|
24
|
import com.yunzhi.demo.service.ISysRoleService;
|
25
|
|
-import com.yunzhi.demo.entity.SysRole;
|
26
|
25
|
import org.springframework.web.bind.annotation.RestController;
|
27
|
26
|
|
28
|
27
|
import java.util.ArrayList;
|
|
@@ -50,6 +49,9 @@ public class SysRoleController extends BaseController {
|
50
|
49
|
@Autowired
|
51
|
50
|
ISysUserRoleService iSysUserRoleService;
|
52
|
51
|
|
|
52
|
+ @Autowired
|
|
53
|
+ ISysMenuService iSysMenuService;
|
|
54
|
+
|
53
|
55
|
/**
|
54
|
56
|
* 分页查询列表
|
55
|
57
|
* @param pageNum
|
|
@@ -95,9 +97,12 @@ public class SysRoleController extends BaseController {
|
95
|
97
|
* @param sysRole 实体对象
|
96
|
98
|
* @return
|
97
|
99
|
*/
|
98
|
|
- @RequestMapping(value="/sysRole",method= RequestMethod.POST)
|
|
100
|
+ @RequestMapping(value="/admin/role",method= RequestMethod.POST)
|
99
|
101
|
@ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
|
100
|
102
|
public ResponseBean sysRoleAdd(@ApiParam("保存内容") @RequestBody SysRole sysRole) throws Exception{
|
|
103
|
+ if (StringUtils.isEmpty(sysRole.getName())) {
|
|
104
|
+ throw new Exception("角色名称不能为空");
|
|
105
|
+ }
|
101
|
106
|
|
102
|
107
|
if (iSysRoleService.save(sysRole)){
|
103
|
108
|
return ResponseBean.success(sysRole);
|
|
@@ -110,10 +115,17 @@ public class SysRoleController extends BaseController {
|
110
|
115
|
* 根据id删除对象
|
111
|
116
|
* @param id 实体ID
|
112
|
117
|
*/
|
113
|
|
- @RequestMapping(value="/sysRole/{id}", method= RequestMethod.DELETE)
|
|
118
|
+ @RequestMapping(value="/admin/role/{id}", method= RequestMethod.DELETE)
|
114
|
119
|
@ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
|
115
|
120
|
public ResponseBean sysRoleDelete(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
|
116
|
|
- if(iSysRoleService.removeById(id)){
|
|
121
|
+ SysRole sysRole = iSysRoleService.getById(id);
|
|
122
|
+ if (null == sysRole || Constants.STATUS_DELETED.equals(sysRole.getStatus())) {
|
|
123
|
+ return ResponseBean.success("success");
|
|
124
|
+ }
|
|
125
|
+
|
|
126
|
+ sysRole.setStatus(Constants.STATUS_DELETED);
|
|
127
|
+
|
|
128
|
+ if(iSysRoleService.updateById(sysRole)){
|
117
|
129
|
return ResponseBean.success("success");
|
118
|
130
|
}else {
|
119
|
131
|
return ResponseBean.error("删除失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
|
|
@@ -126,10 +138,17 @@ public class SysRoleController extends BaseController {
|
126
|
138
|
* @param sysRole 实体对象
|
127
|
139
|
* @return
|
128
|
140
|
*/
|
129
|
|
- @RequestMapping(value="/sysRole/{id}",method= RequestMethod.PUT)
|
|
141
|
+ @RequestMapping(value="/admin/role/{id}",method= RequestMethod.PUT)
|
130
|
142
|
@ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
|
131
|
143
|
public ResponseBean sysRoleUpdate(@ApiParam("对象ID") @PathVariable Integer id,
|
132
|
|
- @ApiParam("更新内容") @RequestBody SysRole sysRole) throws Exception{
|
|
144
|
+ @ApiParam("更新内容") @RequestBody SysRole sysRole) throws Exception{
|
|
145
|
+ if (StringUtils.isEmpty(sysRole.getName())) {
|
|
146
|
+ throw new Exception("角色名称不能为空");
|
|
147
|
+ }
|
|
148
|
+
|
|
149
|
+ if (!id.equals(sysRole.getRoleId())) {
|
|
150
|
+ throw new Exception("校验角色信息失败");
|
|
151
|
+ }
|
133
|
152
|
|
134
|
153
|
if (iSysRoleService.updateById(sysRole)){
|
135
|
154
|
return ResponseBean.success(iSysRoleService.getById(id));
|
|
@@ -142,9 +161,19 @@ public class SysRoleController extends BaseController {
|
142
|
161
|
* 根据id查询对象
|
143
|
162
|
* @param id 实体ID
|
144
|
163
|
*/
|
145
|
|
- @RequestMapping(value="/sysRole/{id}",method= RequestMethod.GET)
|
146
|
|
- @ApiOperation(value="详情", notes = "详情", httpMethod = "GET", response = ResponseBean.class)
|
|
164
|
+ @RequestMapping(value="/admin/role/{id}",method= RequestMethod.GET)
|
|
165
|
+ @ApiOperation(value="查询角色信息", notes = "详情", httpMethod = "GET", response = ResponseBean.class)
|
147
|
166
|
public ResponseBean sysRoleGet(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
|
148
|
|
- return ResponseBean.success(iSysRoleService.getById(id));
|
|
167
|
+ SysRole sysRole = iSysRoleService.getById(id);
|
|
168
|
+ if (null == sysRole || Constants.STATUS_DELETED.equals(sysRole.getStatus())) {
|
|
169
|
+ throw new Exception("未找到指定的角色信息");
|
|
170
|
+ }
|
|
171
|
+
|
|
172
|
+ List<SysMenu> menuList = iSysMenuService.getListByRole(id);
|
|
173
|
+ if (null != menuList) {
|
|
174
|
+ sysRole.setMenuList(menuList);
|
|
175
|
+ }
|
|
176
|
+
|
|
177
|
+ return ResponseBean.success(sysRole);
|
149
|
178
|
}
|
150
|
179
|
}
|