refactor: 优化角色分配功能相关代码

This commit is contained in:
2024-11-11 20:59:16 +08:00
parent d4b02ba918
commit ad3f8329dd
14 changed files with 61 additions and 148 deletions

View File

@@ -78,12 +78,6 @@ public class CommonController {
return deptService.tree(query, sortQuery, true);
}
@Operation(summary = "查询部门用户树", description = "查询树结构的部门列表")
@GetMapping("/tree/deptWithUsers")
public List<Tree<String>> listDeptWithUsersTree(DeptQuery query, SortQuery sortQuery) {
return deptService.treeWithUsers(query, sortQuery, true);
}
@Operation(summary = "查询菜单树", description = "查询树结构的菜单列表")
@GetMapping("/tree/menu")
public List<Tree<Long>> listMenuTree(MenuQuery query, SortQuery sortQuery) {

View File

@@ -73,7 +73,7 @@ public class NoticeController extends BaseController<NoticeService, NoticeResp,
}
// 校验通知范围
if (NoticeScopeEnum.USER.equals(req.getNoticeScope())) {
ValidationUtils.throwIfEmpty(req.getNoticeUsers(), "请选择通知用户");
ValidationUtils.throwIfEmpty(req.getNoticeUsers(), "通知用户不能为空");
}
}
}

View File

@@ -18,9 +18,13 @@ package top.continew.admin.controller.system;
import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotEmpty;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import top.continew.admin.system.model.query.RoleQuery;
@@ -42,6 +46,7 @@ import java.util.List;
* @since 2023/2/8 23:11
*/
@Tag(name = "角色管理 API")
@Validated
@RestController
@RequiredArgsConstructor
@CrudRequestMapping(value = "/system/role", api = {Api.PAGE, Api.GET, Api.ADD, Api.UPDATE, Api.DELETE})
@@ -49,16 +54,18 @@ public class RoleController extends BaseController<RoleService, RoleResp, RoleDe
private final UserRoleService userRoleService;
@Operation(summary = "查询角色关联用户", description = "查询角色组绑定的关联用户")
@GetMapping("/listRoleUsers/{id}")
public List<Long> listUsers(@PathVariable("id") Long roleId) {
return userRoleService.listUserIdByRoleId(roleId);
@Operation(summary = "查询角色关联用户", description = "查询角色关联用户ID列表")
@Parameter(name = "id", description = "ID", example = "1", in = ParameterIn.PATH)
@GetMapping("/{id}/user")
public List<Long> listUser(@PathVariable("id") Long id) {
return userRoleService.listUserIdByRoleId(id);
}
@Operation(summary = "关联用户", description = "批量关联用户")
@SaCheckPermission("system:role:bindUsers")
@PostMapping("/bindUsers/{id}")
public void bindUsers(@PathVariable("id") Long roleId, @RequestBody List<Long> userIds) {
userRoleService.bindUserIds(roleId, userIds);
@Operation(summary = "分配角色给用户", description = "批量分配角色给用户")
@SaCheckPermission("system:role:assign")
@PostMapping("/{id}/user")
public void assignToUsers(@PathVariable("id") Long id,
@Validated @NotEmpty(message = "用户ID列表不能为空") @RequestBody List<Long> userIds) {
userRoleService.assignRoleToUsers(id, userIds);
}
}

View File

@@ -23,6 +23,7 @@ VALUES
(1033, '新增', 1030, 3, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'system:role:add', 3, 1, 1, NOW(), NULL, NULL),
(1034, '修改', 1030, 3, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'system:role:update', 4, 1, 1, NOW(), NULL, NULL),
(1035, '删除', 1030, 3, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'system:role:delete', 5, 1, 1, NOW(), NULL, NULL),
(1036, '分配', 1030, 3, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'system:role:assign', 6, 1, 1, NOW(), NULL, NULL),
(1050, '菜单管理', 1000, 2, '/system/menu', 'SystemMenu', 'system/menu/index', NULL, 'menu', b'0', b'0', b'0', NULL, 3, 1, 1, NOW(), NULL, NULL),
(1051, '列表', 1050, 3, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'system:menu:list', 1, 1, 1, NOW(), NULL, NULL),

View File

@@ -23,6 +23,7 @@ VALUES
(1033, '新增', 1030, 3, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'system:role:add', 3, 1, 1, NOW(), NULL, NULL),
(1034, '修改', 1030, 3, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'system:role:update', 4, 1, 1, NOW(), NULL, NULL),
(1035, '删除', 1030, 3, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'system:role:delete', 5, 1, 1, NOW(), NULL, NULL),
(1036, '分配', 1030, 3, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'system:role:assign', 6, 1, 1, NOW(), NULL, NULL),
(1050, '菜单管理', 1000, 2, '/system/menu', 'SystemMenu', 'system/menu/index', NULL, 'menu', false, false, false, NULL, 3, 1, 1, NOW(), NULL, NULL),
(1051, '列表', 1050, 3, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'system:menu:list', 1, 1, 1, NOW(), NULL, NULL),