zss
8 天以前 11502c7f9f26edda0733c43a17b5b773ee8447e4
src/main/java/com/ruoyi/project/system/controller/SysRoleController.java
@@ -1,16 +1,9 @@
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;
@@ -29,15 +22,19 @@
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;
/**
 * 角色信息
 *
 *
 * @author ruoyi
 */
@RestController
@@ -75,10 +72,10 @@
     */
    @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));
    }
    /**
@@ -87,19 +84,18 @@
    @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));
    }
@@ -109,20 +105,20 @@
    @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());
        if (roleService.updateRole(role) > 0)
        {
            // 更新缓存用户权限
@@ -133,9 +129,9 @@
                loginUser.setPermissions(permissionService.getMenuPermission(loginUser.getUser()));
                tokenService.setLoginUser(loginUser);
            }
            return R.ok();
            return success();
        }
        return R.fail("修改角色'" + role.getRoleName() + "'失败,请联系管理员");
        return error("修改角色'" + role.getRoleName() + "'失败,请联系管理员");
    }
    /**
@@ -144,12 +140,11 @@
    @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));
    }
    /**
@@ -158,13 +153,12 @@
    @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));
    }
    /**
@@ -173,10 +167,9 @@
    @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));
    }
    /**
@@ -184,9 +177,9 @@
     */
    @PreAuthorize("@ss.hasPermi('system:role:query')")
    @GetMapping("/optionselect")
    public R<?> optionselect()
    public AjaxResult optionselect()
    {
        return R.ok(roleService.selectRoleAll());
        return success(roleService.selectRoleAll());
    }
    /**
@@ -219,10 +212,9 @@
    @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));
    }
    /**
@@ -231,10 +223,9 @@
    @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));
    }
    /**
@@ -243,11 +234,10 @@
    @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));
    }
    /**
@@ -255,11 +245,11 @@
     */
    @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;
    }
}
}