2022-04-22 15:26:39 +08:00
|
|
|
package net.maku.system.controller;
|
|
|
|
|
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
2023-01-18 00:04:56 +08:00
|
|
|
import jakarta.validation.Valid;
|
2022-04-22 15:26:39 +08:00
|
|
|
import lombok.AllArgsConstructor;
|
2023-01-20 13:47:45 +08:00
|
|
|
import net.maku.framework.common.utils.PageResult;
|
2022-04-22 15:26:39 +08:00
|
|
|
import net.maku.framework.common.utils.Result;
|
2023-05-22 15:59:15 +08:00
|
|
|
import net.maku.framework.operatelog.annotations.OperateLog;
|
|
|
|
import net.maku.framework.operatelog.enums.OperateTypeEnum;
|
2022-04-22 15:26:39 +08:00
|
|
|
import net.maku.framework.security.user.SecurityUser;
|
|
|
|
import net.maku.framework.security.user.UserDetail;
|
|
|
|
import net.maku.system.convert.SysRoleConvert;
|
|
|
|
import net.maku.system.entity.SysRoleEntity;
|
2022-11-16 15:02:32 +08:00
|
|
|
import net.maku.system.query.SysRoleQuery;
|
2022-07-25 16:06:39 +08:00
|
|
|
import net.maku.system.query.SysRoleUserQuery;
|
|
|
|
import net.maku.system.service.*;
|
2022-05-05 13:58:45 +08:00
|
|
|
import net.maku.system.vo.SysMenuVO;
|
2022-07-23 17:12:00 +08:00
|
|
|
import net.maku.system.vo.SysRoleDataScopeVO;
|
2022-05-05 13:58:45 +08:00
|
|
|
import net.maku.system.vo.SysRoleVO;
|
2022-07-25 16:06:39 +08:00
|
|
|
import net.maku.system.vo.SysUserVO;
|
2023-01-18 00:04:56 +08:00
|
|
|
import org.springdoc.core.annotations.ParameterObject;
|
2022-04-23 23:01:54 +08:00
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
2022-04-22 15:26:39 +08:00
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 角色管理
|
2022-11-16 15:02:32 +08:00
|
|
|
*
|
2022-04-22 15:26:39 +08:00
|
|
|
* @author 阿沐 babamu@126.com
|
2023-02-21 16:44:04 +08:00
|
|
|
* <a href="https://maku.net">MAKU</a>
|
2022-04-22 15:26:39 +08:00
|
|
|
*/
|
|
|
|
@RestController
|
|
|
|
@RequestMapping("sys/role")
|
2022-11-16 15:02:32 +08:00
|
|
|
@Tag(name = "角色管理")
|
2022-04-22 15:26:39 +08:00
|
|
|
@AllArgsConstructor
|
|
|
|
public class SysRoleController {
|
2022-11-16 15:02:32 +08:00
|
|
|
private final SysRoleService sysRoleService;
|
|
|
|
private final SysUserService sysUserService;
|
|
|
|
private final SysRoleMenuService sysRoleMenuService;
|
|
|
|
private final SysRoleDataScopeService sysRoleDataScopeService;
|
|
|
|
private final SysMenuService sysMenuService;
|
|
|
|
private final SysUserRoleService sysUserRoleService;
|
|
|
|
|
|
|
|
@GetMapping("page")
|
|
|
|
@Operation(summary = "分页")
|
|
|
|
@PreAuthorize("hasAuthority('sys:role:page')")
|
2023-01-15 20:08:11 +08:00
|
|
|
public Result<PageResult<SysRoleVO>> page(@ParameterObject @Valid SysRoleQuery query) {
|
2022-11-16 15:02:32 +08:00
|
|
|
PageResult<SysRoleVO> page = sysRoleService.page(query);
|
|
|
|
|
|
|
|
return Result.ok(page);
|
|
|
|
}
|
|
|
|
|
|
|
|
@GetMapping("list")
|
|
|
|
@Operation(summary = "列表")
|
|
|
|
@PreAuthorize("hasAuthority('sys:role:list')")
|
|
|
|
public Result<List<SysRoleVO>> list() {
|
|
|
|
List<SysRoleVO> list = sysRoleService.getList(new SysRoleQuery());
|
|
|
|
|
|
|
|
return Result.ok(list);
|
|
|
|
}
|
|
|
|
|
|
|
|
@GetMapping("{id}")
|
|
|
|
@Operation(summary = "信息")
|
|
|
|
@PreAuthorize("hasAuthority('sys:role:info')")
|
|
|
|
public Result<SysRoleVO> get(@PathVariable("id") Long id) {
|
|
|
|
SysRoleEntity entity = sysRoleService.getById(id);
|
|
|
|
|
|
|
|
// 转换对象
|
|
|
|
SysRoleVO role = SysRoleConvert.INSTANCE.convert(entity);
|
|
|
|
|
|
|
|
// 查询角色对应的菜单
|
|
|
|
List<Long> menuIdList = sysRoleMenuService.getMenuIdList(id);
|
|
|
|
role.setMenuIdList(menuIdList);
|
|
|
|
|
|
|
|
// 查询角色对应的数据权限
|
|
|
|
List<Long> orgIdList = sysRoleDataScopeService.getOrgIdList(id);
|
|
|
|
role.setOrgIdList(orgIdList);
|
|
|
|
|
|
|
|
return Result.ok(role);
|
|
|
|
}
|
|
|
|
|
|
|
|
@PostMapping
|
|
|
|
@Operation(summary = "保存")
|
2023-05-22 15:59:15 +08:00
|
|
|
@OperateLog(type = OperateTypeEnum.INSERT)
|
2022-11-16 15:02:32 +08:00
|
|
|
@PreAuthorize("hasAuthority('sys:role:save')")
|
|
|
|
public Result<String> save(@RequestBody @Valid SysRoleVO vo) {
|
|
|
|
sysRoleService.save(vo);
|
|
|
|
|
|
|
|
return Result.ok();
|
|
|
|
}
|
|
|
|
|
|
|
|
@PutMapping
|
|
|
|
@Operation(summary = "修改")
|
2023-05-22 15:59:15 +08:00
|
|
|
@OperateLog(type = OperateTypeEnum.UPDATE)
|
2022-11-16 15:02:32 +08:00
|
|
|
@PreAuthorize("hasAuthority('sys:role:update')")
|
|
|
|
public Result<String> update(@RequestBody @Valid SysRoleVO vo) {
|
|
|
|
sysRoleService.update(vo);
|
|
|
|
|
|
|
|
return Result.ok();
|
|
|
|
}
|
|
|
|
|
|
|
|
@PutMapping("data-scope")
|
|
|
|
@Operation(summary = "数据权限")
|
2023-05-22 15:59:15 +08:00
|
|
|
@OperateLog(type = OperateTypeEnum.UPDATE)
|
2022-11-16 15:02:32 +08:00
|
|
|
@PreAuthorize("hasAuthority('sys:role:update')")
|
|
|
|
public Result<String> dataScope(@RequestBody @Valid SysRoleDataScopeVO vo) {
|
|
|
|
sysRoleService.dataScope(vo);
|
|
|
|
|
|
|
|
return Result.ok();
|
|
|
|
}
|
|
|
|
|
|
|
|
@DeleteMapping
|
|
|
|
@Operation(summary = "删除")
|
2023-05-22 15:59:15 +08:00
|
|
|
@OperateLog(type = OperateTypeEnum.DELETE)
|
2022-11-16 15:02:32 +08:00
|
|
|
@PreAuthorize("hasAuthority('sys:role:delete')")
|
|
|
|
public Result<String> delete(@RequestBody List<Long> idList) {
|
|
|
|
sysRoleService.delete(idList);
|
|
|
|
|
|
|
|
return Result.ok();
|
|
|
|
}
|
|
|
|
|
|
|
|
@GetMapping("menu")
|
|
|
|
@Operation(summary = "角色菜单")
|
|
|
|
@PreAuthorize("hasAuthority('sys:role:menu')")
|
|
|
|
public Result<List<SysMenuVO>> menu() {
|
|
|
|
UserDetail user = SecurityUser.getUser();
|
|
|
|
List<SysMenuVO> list = sysMenuService.getUserMenuList(user, null);
|
|
|
|
|
|
|
|
return Result.ok(list);
|
|
|
|
}
|
|
|
|
|
|
|
|
@GetMapping("user/page")
|
|
|
|
@Operation(summary = "角色用户-分页")
|
|
|
|
@PreAuthorize("hasAuthority('sys:role:update')")
|
|
|
|
public Result<PageResult<SysUserVO>> userPage(@Valid SysRoleUserQuery query) {
|
|
|
|
PageResult<SysUserVO> page = sysUserService.roleUserPage(query);
|
|
|
|
|
|
|
|
return Result.ok(page);
|
|
|
|
}
|
|
|
|
|
|
|
|
@DeleteMapping("user/{roleId}")
|
|
|
|
@Operation(summary = "删除角色用户")
|
2023-05-22 15:59:15 +08:00
|
|
|
@OperateLog(type = OperateTypeEnum.DELETE)
|
2022-11-16 15:02:32 +08:00
|
|
|
@PreAuthorize("hasAuthority('sys:role:update')")
|
|
|
|
public Result<String> userDelete(@PathVariable("roleId") Long roleId, @RequestBody List<Long> userIdList) {
|
|
|
|
sysUserRoleService.deleteByUserIdList(roleId, userIdList);
|
|
|
|
|
|
|
|
return Result.ok();
|
|
|
|
}
|
|
|
|
|
|
|
|
@PostMapping("user/{roleId}")
|
|
|
|
@Operation(summary = "分配角色给用户列表")
|
2023-05-22 15:59:15 +08:00
|
|
|
@OperateLog(type = OperateTypeEnum.DELETE)
|
2022-11-16 15:02:32 +08:00
|
|
|
@PreAuthorize("hasAuthority('sys:role:update')")
|
|
|
|
public Result<String> userSave(@PathVariable("roleId") Long roleId, @RequestBody List<Long> userIdList) {
|
|
|
|
sysUserRoleService.saveUserList(roleId, userIdList);
|
|
|
|
|
|
|
|
return Result.ok();
|
|
|
|
}
|
2022-04-22 15:26:39 +08:00
|
|
|
}
|