| | |
| | | package com.ruoyi.web.controller.system; |
| | | |
| | | import cn.dev33.satoken.annotation.SaCheckPermission; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import com.ruoyi.common.annotation.Log; |
| | | import com.ruoyi.common.constant.UserConstants; |
| | | import com.ruoyi.common.core.controller.BaseController; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.common.core.domain.PageQuery; |
| | | import com.ruoyi.common.core.domain.entity.SysRole; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.core.domain.model.LoginUser; |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | import com.ruoyi.common.enums.BusinessType; |
| | | import com.ruoyi.common.helper.LoginHelper; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | | import com.ruoyi.system.domain.SysUserRole; |
| | | import com.ruoyi.system.service.ISysRoleService; |
| | | import com.ruoyi.system.service.ISysUserService; |
| | | import com.ruoyi.system.service.SysPermissionService; |
| | | import io.swagger.annotations.*; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | |
| | | */ |
| | | @Validated |
| | | @Api(value = "角色信息控制器", tags = {"角色信息管理"}) |
| | | @RequiredArgsConstructor(onConstructor_ = @Autowired) |
| | | @RequiredArgsConstructor |
| | | @RestController |
| | | @RequestMapping("/system/role") |
| | | public class SysRoleController extends BaseController { |
| | | |
| | | private final ISysRoleService roleService; |
| | | private final ISysUserService userService; |
| | | private final SysPermissionService permissionService; |
| | | |
| | | @ApiOperation("查询角色信息列表") |
| | | @SaCheckPermission("system:role:list") |
| | | @GetMapping("/list") |
| | | public TableDataInfo<SysRole> list(SysRole role) { |
| | | return roleService.selectPageRoleList(role); |
| | | public TableDataInfo<SysRole> list(SysRole role, PageQuery pageQuery) { |
| | | return roleService.selectPageRoleList(role, pageQuery); |
| | | } |
| | | |
| | | @ApiOperation("导出角色信息列表") |
| | |
| | | @PutMapping |
| | | public AjaxResult<Void> edit(@Validated @RequestBody SysRole role) { |
| | | roleService.checkRoleAllowed(role); |
| | | roleService.checkRoleDataScope(role.getRoleId()); |
| | | if (UserConstants.NOT_UNIQUE.equals(roleService.checkRoleNameUnique(role))) { |
| | | return AjaxResult.error("修改角色'" + role.getRoleName() + "'失败,角色名称已存在"); |
| | | } else if (UserConstants.NOT_UNIQUE.equals(roleService.checkRoleKeyUnique(role))) { |
| | |
| | | } |
| | | |
| | | if (roleService.updateRole(role) > 0) { |
| | | // 更新缓存用户权限 |
| | | LoginUser loginUser = getLoginUser(); |
| | | SysUser sysUser = userService.selectUserById(loginUser.getUserId()); |
| | | if (ObjectUtil.isNotNull(sysUser) && !sysUser.isAdmin()) { |
| | | loginUser.setMenuPermission(permissionService.getMenuPermission(sysUser)); |
| | | LoginHelper.setLoginUser(loginUser); |
| | | } |
| | | return AjaxResult.success(); |
| | | } |
| | | return AjaxResult.error("修改角色'" + role.getRoleName() + "'失败,请联系管理员"); |
| | |
| | | @PutMapping("/dataScope") |
| | | public AjaxResult<Void> dataScope(@RequestBody SysRole role) { |
| | | roleService.checkRoleAllowed(role); |
| | | roleService.checkRoleDataScope(role.getRoleId()); |
| | | return toAjax(roleService.authDataScope(role)); |
| | | } |
| | | |
| | |
| | | @PutMapping("/changeStatus") |
| | | public AjaxResult<Void> changeStatus(@RequestBody SysRole role) { |
| | | roleService.checkRoleAllowed(role); |
| | | roleService.checkRoleDataScope(role.getRoleId()); |
| | | return toAjax(roleService.updateRoleStatus(role)); |
| | | } |
| | | |
| | |
| | | @ApiOperation("查询已分配用户角色列表") |
| | | @SaCheckPermission("system:role:list") |
| | | @GetMapping("/authUser/allocatedList") |
| | | public TableDataInfo<SysUser> allocatedList(SysUser user) { |
| | | return userService.selectAllocatedList(user); |
| | | public TableDataInfo<SysUser> allocatedList(SysUser user, PageQuery pageQuery) { |
| | | return userService.selectAllocatedList(user, pageQuery); |
| | | } |
| | | |
| | | /** |
| | |
| | | @ApiOperation("查询未分配用户角色列表") |
| | | @SaCheckPermission("system:role:list") |
| | | @GetMapping("/authUser/unallocatedList") |
| | | public TableDataInfo<SysUser> unallocatedList(SysUser user) { |
| | | return userService.selectUnallocatedList(user); |
| | | public TableDataInfo<SysUser> unallocatedList(SysUser user, PageQuery pageQuery) { |
| | | return userService.selectUnallocatedList(user, pageQuery); |
| | | } |
| | | |
| | | /** |
| | |
| | | @Log(title = "角色管理", businessType = BusinessType.GRANT) |
| | | @PutMapping("/authUser/selectAll") |
| | | public AjaxResult<Void> selectAuthUserAll(Long roleId, Long[] userIds) { |
| | | roleService.checkRoleDataScope(roleId); |
| | | return toAjax(roleService.insertAuthUsers(roleId, userIds)); |
| | | } |
| | | } |