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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
package cn.wisenergy.chnmuseum.party.web.controller;
import cn.wisenergy.chnmuseum.party.core.annotations.OperationLog;
import cn.wisenergy.chnmuseum.party.model.*;
import cn.wisenergy.chnmuseum.party.service.PermissionService;
import cn.wisenergy.chnmuseum.party.service.RolePermissionService;
import cn.wisenergy.chnmuseum.party.service.RoleService;
import cn.wisenergy.chnmuseum.party.service.impl.EmployeeRoleServiceImpl;
import cn.wisenergy.chnmuseum.party.service.impl.RoleMenuServiceImpl;
import cn.wisenergy.chnmuseum.party.web.controller.base.BaseController;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.stuxuhai.jpinyin.PinyinHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.*;
/**
* 角色管理Controller
*/
@Api(tags = "角色管理")
@RequestMapping("/role")
@RestController
public class RoleController extends BaseController {
private static final Logger LOGGER = LoggerFactory.getLogger(RoleController.class);
@Autowired
private RoleService roleService;
@Autowired
private PermissionService permissionService;
@Autowired
private RolePermissionService rolePermissionService;
@Resource
private EmployeeRoleServiceImpl employeeRoleService;
@Resource
private RoleMenuServiceImpl roleMenuService;
/**
* 获取单个角色
*
* @param Id
* @return
*/
@ApiOperation(value = "获取单个角色")
@RequestMapping(value = "/getById", method = RequestMethod.GET)
@RequiresPermissions("/role/getById")
public ResponseEntity<Role> getById(String Id) {
try {
Role role = roleService.getById(Id);
if (null == role) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
}
return ResponseEntity.ok(role);
} catch (Exception e) {
logger.error("查询错误!", e);
}
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
}
// 获取角色分页对象
@ApiOperation(value = "获取角色分页对象")
@RequestMapping(value = "/getRoleList", method = RequestMethod.GET)
@RequiresPermissions("/role/getRoleList")
public ResponseEntity<Page<Role>> getRoleList(String name) {
try {
name = StringUtils.trimToNull(name);
QueryWrapper<Role> ew = new QueryWrapper<>();
if (StringUtils.isNotBlank(name)) {
ew.like("name", name);
}
ew.eq("is_deleted", 0);
ew.orderByAsc("sortorder");
Page<Role> page = this.getPage();
return ResponseEntity.ok(this.roleService.page(page, ew));
} catch (Exception e) {
LOGGER.error("查询角色列表出错!", e);
}
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
}
/**
* 添加
*/
@OperationLog("添加角色")
@ApiOperation("添加角色")
@PostMapping(value = "/add")
@RequiresPermissions("/role/add")
@ApiImplicitParams(value = {
@ApiImplicitParam(name = "permissionIds", value = "权限id", paramType = "query", dataType = "String"),
@ApiImplicitParam(name = "menuIds", value = "菜单id", paramType = "query", dataType = "String")})
public ResponseEntity<Map<String, Object>> add(Role role, String permissionIds) {
Map<String, Object> resultMap = new LinkedHashMap<String, Object>();
try {
QueryWrapper<Role> ew = new QueryWrapper<>();
ew.select("max(sortorder) as sort");
Role r = this.roleService.getOne(ew);
if (r != null) {
role.setSortorder(r.getSortorder() + 1);
} else {
role.setSortorder(1);
}
if (StringUtils.isNoneBlank(role.getName())) {
ew.eq("name", role.getName());
role.setName(StringUtils.trimToNull(role.getName()));
role.setAlias(PinyinHelper.getShortPinyin(role.getName()));
}
ew.or();
if (StringUtils.isNoneBlank(role.getAlias())) {
ew.eq("alias", role.getAlias());
role.setAlias(StringUtils.trimToNull(role.getAlias()));
}
Role one = this.roleService.getOne(ew);
if (one != null) {
resultMap.put("status", 400);
resultMap.put("message", "该角色已存在");
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(resultMap);
}
boolean ret = false;
role.setCreateTime(new Date(System.currentTimeMillis()));
role.setUpdateTime(role.getCreateTime());
ret = this.roleService.save(role);
if (permissionIds != null) {
String[] permissionIdsSplit = permissionIds.split(",");
// 添加新分配的权限
List<RolePermission> permissions = new ArrayList<RolePermission>();
RolePermission e = null;
for (String pid : permissionIdsSplit) {
e = new RolePermission();
e.setPid(pid);
e.setRid(role.getId());
e.setCreateTime(new Date(System.currentTimeMillis()));
e.setUpdateTime(e.getCreateTime());
permissions.add(e);
}
ret = rolePermissionService.saveBatch(permissions);
}
if (!ret) {
resultMap.put("status", 400);
resultMap.put("message", "添加失败");
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(resultMap);
}
// 204
resultMap.put("status", 200);
resultMap.put("message", "添加成功");
return ResponseEntity.status(HttpStatus.OK).body(resultMap);
} catch (Exception e) {
logger.error("添加角色错误!", e);
}
resultMap.put("status", 500);
resultMap.put("message", "操作失败");
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(resultMap);
}
@OperationLog("编辑角色")
@ApiOperation(value = "编辑")
@RequestMapping(value = "/edit", method = RequestMethod.PUT)
@RequiresPermissions("/role/edit")
public ResponseEntity<Map<String, Object>> edit(Role role) {
Map<String, Object> resultMap = new LinkedHashMap<String, Object>();
try {
QueryWrapper<Role> ew = new QueryWrapper<>();
ew.ne("id", role.getId());
if (StringUtils.isNoneBlank(role.getName())) {
ew.eq("name", role.getName().trim());
role.setAlias(PinyinHelper.getShortPinyin(role.getName().trim()));
}
ew.or();
if (StringUtils.isNoneBlank(role.getAlias())) {
ew.eq("alias", role.getAlias().trim());
}
Role role1 = this.roleService.getOne(ew);
if (role1 != null) {
resultMap.put("status", 400);
resultMap.put("message", "角色已存在");
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(resultMap);
}
role.setUpdateTime(new Date(System.currentTimeMillis()));
boolean ret = this.roleService.updateById(role);
if (!ret) {
resultMap.put("status", 500);
resultMap.put("message", "修改失败");
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(resultMap);
} else {
return ResponseEntity.ok().body(null);
}
} catch (Exception e) {
logger.error("修改角色错误!", e);
}
resultMap.put("status", 500);
resultMap.put("message", "修改失败");
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(resultMap);
}
// 刪除
@OperationLog("删除角色")
@ApiOperation(value = "刪除")
@RequestMapping(value = "/delete", method = RequestMethod.DELETE)
@RequiresPermissions("/role/delete")
public ResponseEntity<Map<String, Object>> delete(String roleId) {
Map<String, Object> resultMap = new LinkedHashMap<String, Object>();
try {
if ("1".equals(roleId) || "2".equals(roleId) || "3".equals(roleId) || "4".equals(roleId)) {
resultMap.put("status", 400);
resultMap.put("message", "该角色为默认角色不能被删除");
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(resultMap);
}
QueryWrapper<EmployeeRole> ew = new QueryWrapper<EmployeeRole>();
ew.eq("role_id", roleId);
int count = this.employeeRoleService.count(ew);
boolean ret1;
boolean ret2;
if (count > 0) {
resultMap.put("status", 400);
resultMap.put("message", "该角色下存在未删除的用户,请您删除用户后再删除角色!");
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(resultMap);
} else {
Role role = new Role();
role.setId(roleId);
role.setIsDeleted(1);
ret1 = this.roleService.removeById(role);
RolePermission rp = new RolePermission();
rp.setRid(roleId);
ret2 = rolePermissionService.remove(new QueryWrapper<>(rp));
}
if (!ret1 && !ret2) {
// 删除失败, 500
resultMap.put("status", 500);
resultMap.put("message", "删除失败!");
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(resultMap);
}
// 204
resultMap.put("status", 200);
resultMap.put("message", "删除成功!");
return ResponseEntity.status(HttpStatus.OK).body(resultMap);
} catch (Exception e) {
LOGGER.error("删除角色错误!", e);
}
// 500
resultMap.put("status", 500);
resultMap.put("message", "删除错误!");
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(resultMap);
}
@RequestMapping(value = "/rights", method = RequestMethod.GET)
@RequiresPermissions("/role/rights")
public ResponseEntity<List<Map<String, String>>> rights(String roleId) {
try {
List<Permission> list = this.permissionService.list(null);
QueryWrapper<RolePermission> wrapper = new QueryWrapper<>();
List<Object> roleRightsList = null;
if (roleId != null) {
wrapper.eq("rid", roleId).select("pid");
roleRightsList = this.rolePermissionService.listObjs(wrapper);
}
List<Map<String, String>> rightsList = new ArrayList<>();
for (Permission p : list) {
Map<String, String> map = new HashMap<>();
map.put("id", p.getId());
map.put("pId", p.getPid());
map.put("name", p.getName());
// 默认展开树
map.put("open", "true");
if (roleId != null && !p.getPid().equals("0")) {
// 如果角色已有该权限,则默认选中
if (roleRightsList.contains(p.getId())) {
map.put("checked", "true");
} else {
map.put("checked", "false");
}
}
rightsList.add(map);
}
return ResponseEntity.ok(rightsList);
} catch (Exception e) {
logger.error("获取角色权限失败", e.getMessage());
e.printStackTrace();
}
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
}
/**
* 更新角色接口权限列表
*
* @return
* @Params roleId
*/
@OperationLog("更新角色操作权限")
@ApiOperation(value = "更新权限列表")
@RequestMapping(value = "/updateRoleRights", method = RequestMethod.POST)
@RequiresPermissions("/role/updateRoleRights")
public ResponseEntity<Map<String, Object>> updateRoleRights(String roleId, String permissionIds) {
Map<String, Object> resultMap = new LinkedHashMap<String, Object>();
try {
if (roleId != null) {
// 查询出本角色已经分配了的权限
RolePermission rolePermission = new RolePermission();
rolePermission.setRid(roleId);
QueryWrapper<RolePermission> ew = new QueryWrapper<>();
ew.setEntity(rolePermission);
List<RolePermission> roleRightList = this.rolePermissionService.list(ew);
boolean ret = false;
// 如果存在权限,先进行删除
if (roleRightList.size() > 0) {
this.rolePermissionService.remove(ew);
}
String[] rightIds = StringUtils.split(permissionIds, ",");
if (StringUtils.isNotBlank(permissionIds) && rightIds != null) {
// 添加新分配的权限
List<RolePermission> permissions = new ArrayList<RolePermission>();
RolePermission e;
for (String pid : rightIds) {
e = new RolePermission();
e.setPid(pid);
e.setRid(roleId);
e.setCreateTime(new Date(System.currentTimeMillis()));
e.setUpdateTime(e.getCreateTime());
permissions.add(e);
}
ret = rolePermissionService.saveBatch(permissions);
} else {
resultMap.put("status", 400);
resultMap.put("message", "错误请求!");
return ResponseEntity.status(HttpStatus.OK).body(resultMap);
}
if (!ret) {
// 更新失败, 500
resultMap.put("status", 500);
resultMap.put("message", "更新失败!");
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(resultMap);
}
// 204
resultMap.put("status", 200);
resultMap.put("message", "更新成功!");
return ResponseEntity.status(HttpStatus.OK).body(resultMap);
} else {
resultMap.put("status", 400);
resultMap.put("message", "请选择角色!");
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(resultMap);
}
} catch (Exception e) {
logger.error("更新角色权限错误!", e);
}
// 500
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
}
/**
* 更新角色菜单列表
*
* @return
*/
@OperationLog("更新角色菜单权限")
@ApiOperation(value = "更新菜单列表")
@RequestMapping(value = "/updateRoleMenu", method = RequestMethod.POST)
@RequiresPermissions("/role/updateRoleMenu")
public ResponseEntity<Map<String, Object>> updateRoleMenu(String roleId, String menuIds) {
Map<String, Object> resultMap = new LinkedHashMap<String, Object>();
try {
if (roleId != null) {
// 查询出本角色已经分配了的菜单
RoleMenu roleMenu = new RoleMenu();
roleMenu.setRoleId(roleId);
QueryWrapper<RoleMenu> ew = new QueryWrapper<>();
ew.setEntity(roleMenu);
List<RoleMenu> roleMenuList = this.roleMenuService.list(ew);
boolean ret = false;
// 如果存在菜单,先进行删除
if (roleMenuList.size() > 0) {
this.roleMenuService.remove(ew);
}
String[] mIds = StringUtils.split(menuIds, ",");
if (StringUtils.isNotBlank(menuIds) && mIds != null) {
// 添加新分配的菜单
List<RoleMenu> menus = new ArrayList<RoleMenu>();
RoleMenu e = null;
for (String mid : mIds) {
e = new RoleMenu();
e.setMenuId(mid);
e.setRoleId(roleId);
e.setCreateTime(new Date(System.currentTimeMillis()));
e.setUpdateTime(e.getCreateTime());
menus.add(e);
}
ret = roleMenuService.saveBatch(menus);
if (!ret) {
// 更新失败, 500
resultMap.put("status", 500);
resultMap.put("message", "更新失败!");
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(resultMap);
}
}
// 204
resultMap.put("status", 200);
resultMap.put("message", "更新成功!");
return ResponseEntity.status(HttpStatus.OK).body(resultMap);
} else {
resultMap.put("status", 400);
resultMap.put("message", "请选择角色!");
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(resultMap);
}
} catch (Exception e) {
logger.error("更新角色菜单错误!", e);
}
// 500
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
}
@OperationLog("启用角色")
@ApiOperation(value = "启动")
@RequestMapping(value = "/enableRole", method = RequestMethod.PUT)
@RequiresPermissions("/role/enableRole")
public ResponseEntity<Map<String, Object>> enableRole(String roleId) {
try {
Map<String, Object> map = new HashMap<>();
Role entity = new Role();
entity.setId(roleId);
entity.setStatus(true);
entity.setUpdateTime(new Date(System.currentTimeMillis()));
boolean ret = this.roleService.updateById(entity);
if (!ret) {
map.put("status", "500");
map.put("message", "服务器错误");
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(map);
}
map.put("status", "201");
map.put("message", "启用成功");
return ResponseEntity.status(HttpStatus.OK).body(map);
} catch (Exception e) {
logger.error("用户启动出错!", e);
}
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(
null);
}
// 批量启动
@OperationLog("批量启用角色")
@ApiOperation(value = "批量启动")
@RequestMapping(value = "/batchEnable", method = RequestMethod.PUT)
@RequiresPermissions("/role/batchEnable")
public ResponseEntity<Map<String, Object>> batchEnable(String roleIds) {
try {
Map<String, Object> map = new HashMap<>();
boolean flag = false;
if (StringUtils.isNotBlank(roleIds)) {
String[] roleIdArr = roleIds.split(",");
Role entity = new Role();
entity.setStatus(true);
entity.setUpdateTime(new Date(System.currentTimeMillis()));
for (String roleId : roleIdArr) {
entity.setId(roleId);
flag = this.roleService.updateById(entity);
if (!flag) {
break;
}
}
} else {
map.put("status", "400");
map.put("message", "请选择要启动的用户");
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(map);
}
if (!flag) {
map.put("status", "400");
map.put("message", "批量启动失败");
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(map);
} else {
map.put("status", "201");
map.put("message", "批量启动成功");
return ResponseEntity.status(HttpStatus.OK).body(map);
}
} catch (Exception e) {
logger.error("批量启动失败!", e);
}
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
}
/**
* 禁用
*
* @param roleId
* @return
*/
@OperationLog("禁用角色")
@ApiOperation(value = "禁用")
@RequestMapping(value = "/disable", method = RequestMethod.PUT)
@RequiresPermissions("/role/disable")
public ResponseEntity<Map<String, Object>> disableRole(String roleId) {
try {
Map<String, Object> map = new HashMap<>();
Role entity = new Role();
entity.setId(roleId);
entity.setStatus(false);
entity.setUpdateTime(new Date(System.currentTimeMillis()));
boolean ret = this.roleService.updateById(entity);
if (!ret) {
map.put("status", "400");
map.put("message", "禁用错误");
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(map);
}
map.put("status", "201");
map.put("message", "禁用成功");
return ResponseEntity.status(HttpStatus.OK).body(map);
} catch (Exception e) {
logger.error("禁用用户出错!", e);
}
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(
null);
}
// 批量禁用
@OperationLog("批量禁用角色")
@ApiOperation(value = "批量禁用")
@RequestMapping(value = "/batchDis", method = RequestMethod.PUT)
@RequiresPermissions("/role/batchDis")
public ResponseEntity<Map<String, Object>> batchDis(String roleIds) {
try {
Map<String, Object> map = new HashMap<>();
boolean flag = false;
if (StringUtils.isNotBlank(roleIds)) {
String[] roleIdArr = roleIds.split(",");
Role entity = new Role();
entity.setStatus(false);
entity.setUpdateTime(new Date(System.currentTimeMillis()));
for (String roleId : roleIdArr) {
entity.setId(roleId);
flag = this.roleService.updateById(entity);
if (!flag) {
break;
}
}
} else {
map.put("status", "400");
map.put("message", "请选择要禁用的用户");
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(map);
}
if (!flag) {
map.put("status", "400");
map.put("message", "禁用失败");
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(map);
} else {
map.put("status", "201");
map.put("message", "禁用成功");
return ResponseEntity.status(HttpStatus.OK).body(map);
}
} catch (Exception e) {
logger.error("用户禁用失败!", e);
}
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
}
// 批量删除
@OperationLog("批量删除角色")
@ApiOperation(value = "批量删除")
@RequestMapping(value = "/batchDel", method = RequestMethod.DELETE)
@RequiresPermissions("/role/batchDel")
public ResponseEntity<Map<String, Object>> batchDel(String roleIds) {
try {
Map<String, Object> map = new HashMap<>();
boolean flag = false;
boolean batchDelflag = false;
String selectRoleIds = "";
if (StringUtils.isNotBlank(roleIds)) {
String[] roleIdArr = roleIds.split(",");
Role entity = new Role();
entity.setIsDeleted(1);
for (String roleId : roleIdArr) {
if ("1".equals(roleId) || "2".equals(roleId) || "3".equals(roleId) || "4".equals(roleId)) {
if ("".equals(selectRoleIds)) {
selectRoleIds = roleId;
} else {
selectRoleIds += "," + roleId;
}
continue;
}
entity.setId(roleId);
this.roleService.updateById(entity);
//同时删除角色的权限
RolePermission rp = new RolePermission();
rp.setRid(roleId);
flag = rolePermissionService.remove(new QueryWrapper<>(rp));
if (!flag) {
batchDelflag = true;
break;
}
}
} else {
map.put("status", "400");
map.put("message", "请选择要删除的角色");
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(map);
}
if (batchDelflag) {
map.put("status", 400);
map.put("message", "删除失败");
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(map);
}
if (!"".equals(selectRoleIds) && !flag) {
map.put("status", 400);
map.put("message", "系统默认角色不能被删除");
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(map);
}
map.put("status", 200);
String message = "删除成功";
if (!"".equals(selectRoleIds) && flag) {
message = "系统默认角色不能被删除,其他选中角色删除成功";
}
map.put("message", message);
return ResponseEntity.status(HttpStatus.OK).body(map);
} catch (Exception e) {
logger.error("角色删除失败!", e);
}
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
}
// 获取角色下拉框数据
@ApiOperation(value = "获取角色下拉框数据")
@RequestMapping(value = "/getRoleBox", method = RequestMethod.GET)
@RequiresPermissions("/role/getRoleBox")
public Map<String,Object> getRoleBox() {
try {
QueryWrapper<Role> ew = new QueryWrapper<>();
ew.select("id", "name");
ew.eq("is_deleted", 0);
ew.eq("status", 1);
ew.orderByAsc("sortorder");
ew.orderByDesc("create_time");
List<Role> list = roleService.list(ew);
return getResult(list);
} catch (Exception e) {
LOGGER.error("查询角色列表出错!", e);
}
return getFailResult();
}
}