"package com.ruoyi.web.controller.system;\n\nimport com.ruoyi.common.annotation.Log;\nimport com.ruoyi.common.core.controller.BaseController;\nimport com.ruoyi.common.core.domain.AjaxResult;\nimport com.ruoyi.common.core.domain.Ztree;\nimport com.ruoyi.common.core.domain.entity.SysRole;\nimport com.ruoyi.common.core.domain.entity.SysUser;\nimport com.ruoyi.common.core.page.TableDataInfo;\nimport com.ruoyi.common.enums.BusinessType;\nimport com.ruoyi.common.utils.poi.ExcelUtil;\nimport com.ruoyi.framework.shiro.util.AuthorizationUtils;\nimport com.ruoyi.system.domain.SysUserRole;\nimport com.ruoyi.system.service.ISysDeptService;\nimport com.ruoyi.system.service.ISysRoleService;\nimport com.ruoyi.system.service.ISysUserService;\nimport java.util.List;\nimport org.apache.shiro.authz.annotation.RequiresPermissions;\nimport org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.stereotype.Controller;\nimport org.springframework.ui.ModelMap;\nimport org.springframework.validation.annotation.Validated;\nimport org.springframework.web.bind.annotation.GetMapping;\nimport org.springframework.web.bind.annotation.PathVariable;\nimport org.springframework.web.bind.annotation.PostMapping;\nimport org.springframework.web.bind.annotation.RequestMapping;\nimport org.springframework.web.bind.annotation.ResponseBody;\n\n@Controller\n@RequestMapping({"/system/role"})\npublic class SysRoleController extends BaseController {\n private String prefix = "system/role";\n @Autowired\n private ISysRoleService roleService;\n @Autowired\n private ISysUserService userService;\n @Autowired\n private ISysDeptService deptService;\n\n public SysRoleController() {\n }\n\n @RequiresPermissions({"system:role:view"})\n @GetMapping\n public String role() {\n return this.prefix + "/role";\n }\n\n @RequiresPermissions({"system:role:list"})\n @PostMapping({"/list"})\n @ResponseBody\n public TableDataInfo list(SysRole role) {\n this.startPage();\n List list = this.roleService.selectRoleList(role);\n return this.getDataTable(list);\n }\n\n @Log(\n title = "角色管理",\n businessType = BusinessType.EXPORT\n )\n @RequiresPermissions({"system:role:export"})\n @PostMapping({"/export"})\n @ResponseBody\n public AjaxResult export(SysRole role) {\n List list = this.roleService.selectRoleList(role);\n ExcelUtil util = new ExcelUtil(SysRole.class);\n return util.exportExcel(list, "角色数据");\n }\n\n @GetMapping({"/add"})\n public String add() {\n return this.prefix + "/add";\n }\n\n @RequiresPermissions({"system:role:add"})\n @Log(\n title = "角色管理",\n businessType = BusinessType.INSERT\n )\n @PostMapping({"/add"})\n @ResponseBody\n public AjaxResult addSave(@Validated SysRole role) {\n if (!this.roleService.checkRoleNameUnique(role)) {\n return this.error("新增角色'" + role.getRoleName() + "'失败,角色名称已存在");\n } else if (!this.roleService.checkRoleKeyUnique(role)) {\n return this.error("新增角色'" + role.getRoleName() + "'失败,角色权限已存在");\n } else {\n role.setCreateBy(this.getLoginName());\n AuthorizationUtils.clearAllCachedAuthorizationInfo();\n return this.toAjax(this.roleService.insertRole(role));\n }\n }\n\n @RequiresPermissions({"system:role:edit"})\n @GetMapping({"/edit/{roleId}"})\n public String edit(@PathVariable("roleId") Long roleId, ModelMap mmap) {\n this.roleService.checkRoleDataScope(roleId);\n mmap.put("role", this.roleService.selectRoleById(roleId));\n return this.prefix + "/edit";\n }\n\n @RequiresPermissions({"system:role:edit"})\n @Log(\n title = "角色管理",\n businessType = BusinessType.UPDATE\n )\n @PostMapping({"/edit"})\n @ResponseBody\n public AjaxResult editSave(@Validated SysRole role) {\n this.roleService.checkRoleAllowed(role);\n this.roleService.checkRoleDataScope(role.getRoleId());\n if (!this.roleService.checkRoleNameUnique(role)) {\n return this.error("修改角色'" + role.getRoleName() + "'失败,角色名称已存在");\n } else if (!this.roleService.checkRoleKeyUnique(role)) {\n return this.error("修改角色'" + role.getRoleName() + "'失败,角色权限已存在");\n } else {\n role.setUpdateBy(this.getLoginName());\n AuthorizationUtils.clearAllCachedAuthorizationInfo();\n return this.toAjax(this.roleService.updateRole(role));\n }\n }\n\n @GetMapping({"/authDataScope/{roleId}"})\n public String authDataScope(@PathVariable("roleId") Long roleId, ModelMap mmap) {\n mmap.put("role", this.roleService.selectRoleById(roleId));\n return this.prefix + "/dataScope";\n }\n\n @RequiresPermissions({"system:role:edit"})\n @Log(\n title = "角色管理",\n businessType = BusinessType.UPDATE\n )\n @PostMapping({"/authDataScope"})\n @ResponseBody\n public AjaxResult authDataScopeSave(SysRole role) {\n this.roleService.checkRoleAllowed(role);\n this.roleService.checkRoleDataScope(role.getRoleId());\n role.setUpdateBy(this.getLoginName());\n if (this.roleService.authDataScope(role) > 0) {\n this.setSysUser(this.userService.selectUserById(this.getUserId()));\n return this.success();\n } else {\n return this.error();\n }\n }\n\n @RequiresPermissions({"system:role:remove"})\n @Log(\n title = "角色管理",\n businessType = BusinessType.DELETE\n )\n @PostMapping({"/remove"})\n @ResponseBody\n public AjaxResult remove(String ids) {\n return this.toAjax(this.roleService.deleteRoleByIds(ids));\n }\n\n @PostMapping({"/checkRoleNameUnique"})\n @ResponseBody\n public boolean checkRoleNameUnique(SysRole role) {\n return this.roleService.checkRoleNameUnique(role);\n }\n\n @PostMapping({"/checkRoleKeyUnique"})\n @ResponseBody\n public boolean checkRoleKeyUnique(SysRole role) {\n return this.roleService.checkRoleKeyUnique(role);\n }\n\n @GetMapping({"/selectMenuTree"})\n public String selectMenuTree() {\n return this.prefix + "/tree";\n }\n\n @Log(\n title = "角色管理",\n businessType = BusinessType.UPDATE\n )\n @RequiresPermissions({"system:role:edit"})\n @PostMapping({"/changeStatus"})\n @ResponseBody\n public AjaxResult changeStatus(SysRole role) {\n this.roleService.checkRoleAllowed(role);\n this.roleService.checkRoleDataScope(role.getRoleId());\n return this.toAjax(this.roleService.changeStatus(role));\n }\n\n @RequiresPermissions({"system:role:edit"})\n @GetMapping({"/authUser/{roleId}"})\n public String authUser(@PathVariable("roleId") Long roleId, ModelMap mmap) {\n mmap.put("role", this.roleService.selectRoleById(roleId));\n return this.prefix + "/authUser";\n }\n\n @RequiresPermissions({"system:role:list"})\n @PostMapping({"/authUser/allocatedList"})\n @ResponseBody\n public TableDataInfo allocatedList(SysUser user) {\n this.startPage();\n List list = this.userService.selectAllocatedList(user);\n return this.getDataTable(list);\n }\n\n @RequiresPermissions({"system:role:edit"})\n @Log(\n title = "角色管理",\n businessType = BusinessType.GRANT\n )\n @PostMapping({"/authUser/cancel"})\n @ResponseBody\n public AjaxResult cancelAuthUser(SysUserRole userRole) {\n return this.toAjax(this.roleService.deleteAuthUser(userRole));\n }\n\n @RequiresPermissions({"system:role:edit"})\n @Log(\n title = "角色管理",\n businessType = BusinessType.GRANT\n )\n @PostMapping({"/authUser/cancelAll"})\n @ResponseBody\n public AjaxResult cancelAuthUserAll(Long roleId, String userIds) {\n return this.toAjax(this.roleService.deleteAuthUsers(roleId, userIds));\n }\n\n @GetMapping({"/authUser/selectUser/{roleId}"})\n public String selectUser(@PathVariable("roleId") Long roleId, ModelMap mmap) {\n mmap.put("role", this.roleService.selectRoleById(roleId));\n return this.prefix + "/selectUser";\n }\n\n @RequiresPermissions({"system:role:list"})\n @PostMapping({"/authUser/unallocatedList"})\n @ResponseBody\n public TableDataInfo unallocatedList(SysUser user) {\n this.startPage();\n List list = this.userService.selectUnallocatedList(user);\n return this.getDataTable(list);\n }\n\n @RequiresPermissions({"system:role:edit"})\n @Log(\n title = "角色管理",\n businessType = BusinessType.GRANT\n )\n @PostMapping({"/authUser/selectAll"})\n @ResponseBody\n public AjaxResult selectAuthUserAll(Long roleId, String userIds) {\n this.roleService.checkRoleDataScope(roleId);\n return this.toAjax(this.roleService.insertAuthUsers(roleId, userIds));\n }\n\n @RequiresPermissions({"system:role:edit"})\n @GetMapping({"/deptTreeData"})\n @ResponseBody\n public List deptTreeData(SysRole role) {\n List ztrees = this.deptService.roleDeptTreeData(role);\n return ztrees;\n }\n}\n

RuoYi系统角色管理控制器 - 系统管理 - RuoYi框架

原文地址: https://www.cveoy.top/t/topic/pAzi 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录