| | |
| | | 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.springframework.beans.factory.annotation.Autowired;
|
| | | import org.apache.commons.lang3.ArrayUtils; |
| | | 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 AjaxResult getInfo(@PathVariable Long roleId)
|
| | | public R<?> getInfo(@PathVariable Long roleId) |
| | | {
|
| | | roleService.checkRoleDataScope(roleId);
|
| | | return success(roleService.selectRoleById(roleId));
|
| | | return R.ok(roleService.selectRoleById(roleId)); |
| | | }
|
| | |
|
| | | /**
|
| | |
| | | @PreAuthorize("@ss.hasPermi('system:role:add')")
|
| | | @Log(title = "角色管理", businessType = BusinessType.INSERT)
|
| | | @PostMapping
|
| | | public AjaxResult add(@Validated @RequestBody SysRole role)
|
| | | public R<?> add(@Validated @RequestBody SysRole role) |
| | | {
|
| | | if (!roleService.checkRoleNameUnique(role))
|
| | | {
|
| | | return error("新增角色'" + role.getRoleName() + "'失败,角色名称已存在");
|
| | | return R.fail("新增角色'" + role.getRoleName() + "'失败,角色名称已存在"); |
| | | }
|
| | | else if (!roleService.checkRoleKeyUnique(role))
|
| | | {
|
| | | return error("新增角色'" + role.getRoleName() + "'失败,角色权限已存在");
|
| | | return R.fail("新增角色'" + role.getRoleName() + "'失败,角色权限已存在"); |
| | | }
|
| | | role.setCreateBy(getUsername());
|
| | | return toAjax(roleService.insertRole(role));
|
| | | roleService.insertRole(role); |
| | | return R.ok(); |
| | |
|
| | | }
|
| | |
|
| | |
| | | @PreAuthorize("@ss.hasPermi('system:role:edit')")
|
| | | @Log(title = "角色管理", businessType = BusinessType.UPDATE)
|
| | | @PutMapping
|
| | | public AjaxResult edit(@Validated @RequestBody SysRole role)
|
| | | public R<?> edit(@Validated @RequestBody SysRole role) |
| | | {
|
| | | roleService.checkRoleAllowed(role);
|
| | | roleService.checkRoleDataScope(role.getRoleId());
|
| | | if (!roleService.checkRoleNameUnique(role))
|
| | | {
|
| | | return error("修改角色'" + role.getRoleName() + "'失败,角色名称已存在");
|
| | | return R.fail("修改角色'" + role.getRoleName() + "'失败,角色名称已存在"); |
| | | }
|
| | | else if (!roleService.checkRoleKeyUnique(role))
|
| | | {
|
| | | return error("修改角色'" + role.getRoleName() + "'失败,角色权限已存在");
|
| | | return R.fail("修改角色'" + role.getRoleName() + "'失败,角色权限已存在"); |
| | | }
|
| | | role.setUpdateBy(getUsername());
|
| | |
|
| | |
| | | loginUser.setPermissions(permissionService.getMenuPermission(loginUser.getUser()));
|
| | | tokenService.setLoginUser(loginUser);
|
| | | }
|
| | | return success();
|
| | | return R.ok(); |
| | | }
|
| | | return error("修改角色'" + role.getRoleName() + "'失败,请联系管理员");
|
| | | return R.fail("修改角色'" + role.getRoleName() + "'失败,请联系管理员"); |
| | | }
|
| | |
|
| | | /**
|
| | |
| | | @PreAuthorize("@ss.hasPermi('system:role:edit')")
|
| | | @Log(title = "角色管理", businessType = BusinessType.UPDATE)
|
| | | @PutMapping("/dataScope")
|
| | | public AjaxResult dataScope(@RequestBody SysRole role)
|
| | | public R<?> dataScope(@RequestBody SysRole role) |
| | | {
|
| | | roleService.checkRoleAllowed(role);
|
| | | roleService.checkRoleDataScope(role.getRoleId());
|
| | | return toAjax(roleService.authDataScope(role));
|
| | | roleService.authDataScope(role); |
| | | return R.ok(); |
| | | }
|
| | |
|
| | | /**
|
| | |
| | | @PreAuthorize("@ss.hasPermi('system:role:edit')")
|
| | | @Log(title = "角色管理", businessType = BusinessType.UPDATE)
|
| | | @PutMapping("/changeStatus")
|
| | | public AjaxResult changeStatus(@RequestBody SysRole role)
|
| | | public R<?> changeStatus(@RequestBody SysRole role) |
| | | {
|
| | | roleService.checkRoleAllowed(role);
|
| | | roleService.checkRoleDataScope(role.getRoleId());
|
| | | role.setUpdateBy(getUsername());
|
| | | return toAjax(roleService.updateRoleStatus(role));
|
| | | roleService.updateRoleStatus(role); |
| | | return R.ok(); |
| | | }
|
| | |
|
| | | /**
|
| | |
| | | @PreAuthorize("@ss.hasPermi('system:role:remove')")
|
| | | @Log(title = "角色管理", businessType = BusinessType.DELETE)
|
| | | @DeleteMapping("/{roleIds}")
|
| | | public AjaxResult remove(@PathVariable Long[] roleIds)
|
| | | public R<?> remove(@PathVariable Long[] roleIds) |
| | | {
|
| | | return toAjax(roleService.deleteRoleByIds(roleIds));
|
| | | roleService.deleteRoleByIds(roleIds); |
| | | return R.ok(); |
| | | }
|
| | |
|
| | | /**
|
| | |
| | | */
|
| | | @PreAuthorize("@ss.hasPermi('system:role:query')")
|
| | | @GetMapping("/optionselect")
|
| | | public AjaxResult optionselect()
|
| | | public R<?> optionselect() |
| | | {
|
| | | return success(roleService.selectRoleAll());
|
| | | return R.ok(roleService.selectRoleAll()); |
| | | }
|
| | |
|
| | | /**
|
| | |
| | | @PreAuthorize("@ss.hasPermi('system:role:edit')")
|
| | | @Log(title = "角色管理", businessType = BusinessType.GRANT)
|
| | | @PutMapping("/authUser/cancel")
|
| | | public AjaxResult cancelAuthUser(@RequestBody SysUserRole userRole)
|
| | | public R<?> cancelAuthUser(@RequestBody SysUserRole userRole) |
| | | {
|
| | | return toAjax(roleService.deleteAuthUser(userRole));
|
| | | roleService.deleteAuthUser(userRole); |
| | | return R.ok(); |
| | | }
|
| | |
|
| | | /**
|
| | |
| | | @PreAuthorize("@ss.hasPermi('system:role:edit')")
|
| | | @Log(title = "角色管理", businessType = BusinessType.GRANT)
|
| | | @PutMapping("/authUser/cancelAll")
|
| | | public AjaxResult cancelAuthUserAll(Long roleId, Long[] userIds)
|
| | | public R<?> cancelAuthUserAll(Long roleId, Long[] userIds) |
| | | {
|
| | | return toAjax(roleService.deleteAuthUsers(roleId, userIds));
|
| | | roleService.deleteAuthUsers(roleId, userIds); |
| | | return R.ok(); |
| | | }
|
| | |
|
| | | /**
|
| | |
| | | @PreAuthorize("@ss.hasPermi('system:role:edit')")
|
| | | @Log(title = "角色管理", businessType = BusinessType.GRANT)
|
| | | @PutMapping("/authUser/selectAll")
|
| | | public AjaxResult selectAuthUserAll(Long roleId, Long[] userIds)
|
| | | public R<?> selectAuthUserAll(Long roleId, Long[] userIds) |
| | | {
|
| | | roleService.checkRoleDataScope(roleId);
|
| | | return toAjax(roleService.insertAuthUsers(roleId, userIds));
|
| | | roleService.insertAuthUsers(roleId, userIds); |
| | | return R.ok(); |
| | | }
|
| | |
|
| | | /**
|
| | |
| | | */
|
| | | @PreAuthorize("@ss.hasPermi('system:role:query')")
|
| | | @GetMapping(value = "/deptTree/{roleId}")
|
| | | public AjaxResult deptTree(@PathVariable("roleId") Long roleId)
|
| | | public R<?> deptTree(@PathVariable("roleId") Long roleId) |
| | | {
|
| | | AjaxResult ajax = AjaxResult.success();
|
| | | ajax.put("checkedKeys", deptService.selectDeptListByRoleId(roleId));
|
| | | ajax.put("depts", deptService.selectDeptTreeList(new SysDept()));
|
| | | return ajax;
|
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("checkedKeys", deptService.selectDeptListByRoleId(roleId)); |
| | | map.put("depts", deptService.selectDeptTreeList(new SysDept())); |
| | | return R.ok(map); |
| | | }
|
| | | }
|