| | |
| | | package com.ruoyi.project.system.controller; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import jakarta.servlet.http.HttpServletResponse; |
| | | |
| | | import com.ruoyi.framework.web.domain.R; |
| | | import com.ruoyi.project.system.domain.vo.SysUserDeptVo; |
| | | import com.ruoyi.project.system.mapper.SysUserMapper; |
| | | import com.ruoyi.project.system.service.*; |
| | | import lombok.AllArgsConstructor; |
| | | import org.apache.commons.lang3.ArrayUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.DeleteMapping; |
| | |
| | | import com.ruoyi.framework.security.service.SysPermissionService; |
| | | import com.ruoyi.framework.security.service.TokenService; |
| | | import com.ruoyi.framework.web.controller.BaseController; |
| | | import com.ruoyi.framework.web.domain.AjaxResult; |
| | | import com.ruoyi.framework.web.page.TableDataInfo; |
| | | import com.ruoyi.project.system.domain.SysDept; |
| | | import com.ruoyi.project.system.domain.SysRole; |
| | | import com.ruoyi.project.system.domain.SysUser; |
| | | import com.ruoyi.project.system.domain.SysUserRole; |
| | | import com.ruoyi.project.system.service.ISysDeptService; |
| | | import com.ruoyi.project.system.service.ISysRoleService; |
| | | import com.ruoyi.project.system.service.ISysUserService; |
| | | |
| | | /** |
| | | * 角色信息 |
| | |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('system:role:query')") |
| | | @GetMapping(value = "/{roleId}") |
| | | public R<?> getInfo(@PathVariable Long roleId) |
| | | public AjaxResult getInfo(@PathVariable Long roleId) |
| | | { |
| | | roleService.checkRoleDataScope(roleId); |
| | | return R.ok(roleService.selectRoleById(roleId)); |
| | | return success(roleService.selectRoleById(roleId)); |
| | | } |
| | | |
| | | /** |
| | |
| | | @PreAuthorize("@ss.hasPermi('system:role:add')") |
| | | @Log(title = "角色管理", businessType = BusinessType.INSERT) |
| | | @PostMapping |
| | | public R<?> add(@Validated @RequestBody SysRole role) |
| | | public AjaxResult add(@Validated @RequestBody SysRole role) |
| | | { |
| | | if (!roleService.checkRoleNameUnique(role)) |
| | | { |
| | | return R.fail("新增角色'" + role.getRoleName() + "'失败,角色名称已存在"); |
| | | return error("新增角色'" + role.getRoleName() + "'失败,角色名称已存在"); |
| | | } |
| | | else if (!roleService.checkRoleKeyUnique(role)) |
| | | { |
| | | return R.fail("新增角色'" + role.getRoleName() + "'失败,角色权限已存在"); |
| | | return error("新增角色'" + role.getRoleName() + "'失败,角色权限已存在"); |
| | | } |
| | | role.setCreateBy(getUsername()); |
| | | roleService.insertRole(role); |
| | | return R.ok(); |
| | | return toAjax(roleService.insertRole(role)); |
| | | |
| | | } |
| | | |
| | |
| | | @PreAuthorize("@ss.hasPermi('system:role:edit')") |
| | | @Log(title = "角色管理", businessType = BusinessType.UPDATE) |
| | | @PutMapping |
| | | public R<?> edit(@Validated @RequestBody SysRole role) |
| | | public AjaxResult edit(@Validated @RequestBody SysRole role) |
| | | { |
| | | roleService.checkRoleAllowed(role); |
| | | roleService.checkRoleDataScope(role.getRoleId()); |
| | | if (!roleService.checkRoleNameUnique(role)) |
| | | { |
| | | return R.fail("修改角色'" + role.getRoleName() + "'失败,角色名称已存在"); |
| | | return error("修改角色'" + role.getRoleName() + "'失败,角色名称已存在"); |
| | | } |
| | | else if (!roleService.checkRoleKeyUnique(role)) |
| | | { |
| | | return R.fail("修改角色'" + role.getRoleName() + "'失败,角色权限已存在"); |
| | | return error("修改角色'" + role.getRoleName() + "'失败,角色权限已存在"); |
| | | } |
| | | role.setUpdateBy(getUsername()); |
| | | |
| | |
| | | loginUser.setPermissions(permissionService.getMenuPermission(loginUser.getUser())); |
| | | tokenService.setLoginUser(loginUser); |
| | | } |
| | | return R.ok(); |
| | | return success(); |
| | | } |
| | | return R.fail("修改角色'" + role.getRoleName() + "'失败,请联系管理员"); |
| | | return error("修改角色'" + role.getRoleName() + "'失败,请联系管理员"); |
| | | } |
| | | |
| | | /** |
| | |
| | | @PreAuthorize("@ss.hasPermi('system:role:edit')") |
| | | @Log(title = "角色管理", businessType = BusinessType.UPDATE) |
| | | @PutMapping("/dataScope") |
| | | public R<?> dataScope(@RequestBody SysRole role) |
| | | public AjaxResult dataScope(@RequestBody SysRole role) |
| | | { |
| | | roleService.checkRoleAllowed(role); |
| | | roleService.checkRoleDataScope(role.getRoleId()); |
| | | roleService.authDataScope(role); |
| | | return R.ok(); |
| | | return toAjax(roleService.authDataScope(role)); |
| | | } |
| | | |
| | | /** |
| | |
| | | @PreAuthorize("@ss.hasPermi('system:role:edit')") |
| | | @Log(title = "角色管理", businessType = BusinessType.UPDATE) |
| | | @PutMapping("/changeStatus") |
| | | public R<?> changeStatus(@RequestBody SysRole role) |
| | | public AjaxResult changeStatus(@RequestBody SysRole role) |
| | | { |
| | | roleService.checkRoleAllowed(role); |
| | | roleService.checkRoleDataScope(role.getRoleId()); |
| | | role.setUpdateBy(getUsername()); |
| | | roleService.updateRoleStatus(role); |
| | | return R.ok(); |
| | | return toAjax(roleService.updateRoleStatus(role)); |
| | | } |
| | | |
| | | /** |
| | |
| | | @PreAuthorize("@ss.hasPermi('system:role:remove')") |
| | | @Log(title = "角色管理", businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/{roleIds}") |
| | | public R<?> remove(@PathVariable Long[] roleIds) |
| | | public AjaxResult remove(@PathVariable Long[] roleIds) |
| | | { |
| | | roleService.deleteRoleByIds(roleIds); |
| | | return R.ok(); |
| | | return toAjax(roleService.deleteRoleByIds(roleIds)); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('system:role:query')") |
| | | @GetMapping("/optionselect") |
| | | public R<?> optionselect() |
| | | public AjaxResult optionselect() |
| | | { |
| | | return R.ok(roleService.selectRoleAll()); |
| | | return success(roleService.selectRoleAll()); |
| | | } |
| | | |
| | | /** |
| | |
| | | @PreAuthorize("@ss.hasPermi('system:role:edit')") |
| | | @Log(title = "角色管理", businessType = BusinessType.GRANT) |
| | | @PutMapping("/authUser/cancel") |
| | | public R<?> cancelAuthUser(@RequestBody SysUserRole userRole) |
| | | public AjaxResult cancelAuthUser(@RequestBody SysUserRole userRole) |
| | | { |
| | | roleService.deleteAuthUser(userRole); |
| | | return R.ok(); |
| | | return toAjax(roleService.deleteAuthUser(userRole)); |
| | | } |
| | | |
| | | /** |
| | |
| | | @PreAuthorize("@ss.hasPermi('system:role:edit')") |
| | | @Log(title = "角色管理", businessType = BusinessType.GRANT) |
| | | @PutMapping("/authUser/cancelAll") |
| | | public R<?> cancelAuthUserAll(Long roleId, Long[] userIds) |
| | | public AjaxResult cancelAuthUserAll(Long roleId, Long[] userIds) |
| | | { |
| | | roleService.deleteAuthUsers(roleId, userIds); |
| | | return R.ok(); |
| | | return toAjax(roleService.deleteAuthUsers(roleId, userIds)); |
| | | } |
| | | |
| | | /** |
| | |
| | | @PreAuthorize("@ss.hasPermi('system:role:edit')") |
| | | @Log(title = "角色管理", businessType = BusinessType.GRANT) |
| | | @PutMapping("/authUser/selectAll") |
| | | public R<?> selectAuthUserAll(Long roleId, Long[] userIds) |
| | | public AjaxResult selectAuthUserAll(Long roleId, Long[] userIds) |
| | | { |
| | | roleService.checkRoleDataScope(roleId); |
| | | roleService.insertAuthUsers(roleId, userIds); |
| | | return R.ok(); |
| | | return toAjax(roleService.insertAuthUsers(roleId, userIds)); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('system:role:query')") |
| | | @GetMapping(value = "/deptTree/{roleId}") |
| | | public R<?> deptTree(@PathVariable("roleId") Long roleId) |
| | | public AjaxResult deptTree(@PathVariable("roleId") Long roleId) |
| | | { |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("checkedKeys", deptService.selectDeptListByRoleId(roleId)); |
| | | map.put("depts", deptService.selectDeptTreeList(new SysDept())); |
| | | return R.ok(map); |
| | | AjaxResult ajax = AjaxResult.success(); |
| | | ajax.put("checkedKeys", deptService.selectDeptListByRoleId(roleId)); |
| | | ajax.put("depts", deptService.selectDeptTreeList(new SysDept())); |
| | | return ajax; |
| | | } |
| | | } |