| | |
| | | package com.ruoyi.system.controller.system; |
| | | |
| | | import cn.dev33.satoken.annotation.SaCheckPermission; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import cn.dev33.satoken.exception.NotLoginException; |
| | | import cn.dev33.satoken.stp.StpUtil; |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import com.ruoyi.common.core.constant.GlobalConstants; |
| | | import com.ruoyi.common.core.constant.UserConstants; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.domain.model.LoginUser; |
| | | import com.ruoyi.common.web.core.BaseController; |
| | | import com.ruoyi.common.excel.utils.ExcelUtil; |
| | | import com.ruoyi.common.log.annotation.Log; |
| | | import com.ruoyi.common.log.enums.BusinessType; |
| | | import com.ruoyi.common.mybatis.core.page.PageQuery; |
| | | import com.ruoyi.common.mybatis.core.page.TableDataInfo; |
| | | import com.ruoyi.common.satoken.utils.LoginHelper; |
| | | import com.ruoyi.system.domain.SysDept; |
| | | import com.ruoyi.system.domain.SysUser; |
| | | import com.ruoyi.common.web.core.BaseController; |
| | | import com.ruoyi.system.domain.SysUserRole; |
| | | import com.ruoyi.system.domain.bo.SysDeptBo; |
| | | import com.ruoyi.system.domain.bo.SysRoleBo; |
| | | import com.ruoyi.system.domain.bo.SysUserBo; |
| | | import com.ruoyi.system.domain.vo.DeptTreeSelectVo; |
| | | import com.ruoyi.system.domain.vo.SysRoleVo; |
| | | import com.ruoyi.system.domain.vo.SysUserVo; |
| | | import com.ruoyi.system.service.ISysDeptService; |
| | | import com.ruoyi.system.service.ISysPermissionService; |
| | | import com.ruoyi.system.service.ISysRoleService; |
| | | import com.ruoyi.system.service.ISysUserService; |
| | | import com.ruoyi.system.service.SysPermissionService; |
| | | import jakarta.servlet.http.HttpServletResponse; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 角色信息 |
| | |
| | | private final ISysRoleService roleService; |
| | | private final ISysUserService userService; |
| | | private final ISysDeptService deptService; |
| | | private final SysPermissionService permissionService; |
| | | private final ISysPermissionService permissionService; |
| | | |
| | | /** |
| | | * 获取角色信息列表 |
| | |
| | | } |
| | | |
| | | if (roleService.updateRole(role) > 0) { |
| | | // 更新缓存用户权限 |
| | | LoginUser loginUser = LoginHelper.getLoginUser(); |
| | | SysUser sysUser = userService.selectUserById(loginUser.getUserId()); |
| | | if (ObjectUtil.isNotNull(sysUser) && !LoginHelper.isAdmin()) { |
| | | loginUser.setMenuPermission(permissionService.getMenuPermission(sysUser)); |
| | | LoginHelper.setLoginUser(loginUser); |
| | | List<String> keys = StpUtil.searchTokenValue("", 0, -1, false); |
| | | if (CollUtil.isEmpty(keys)) { |
| | | return R.ok(); |
| | | } |
| | | // 角色关联的在线用户量过大会导致redis阻塞卡顿 谨慎操作 |
| | | keys.parallelStream().forEach(key -> { |
| | | String token = key.replace(GlobalConstants.LOGIN_TOKEN_KEY, ""); |
| | | // 如果已经过期则跳过 |
| | | if (StpUtil.stpLogic.getTokenActivityTimeoutByToken(token) < -1) { |
| | | return; |
| | | } |
| | | LoginUser loginUser = LoginHelper.getLoginUser(token); |
| | | if (loginUser.getRoles().stream().anyMatch(r -> r.getRoleId().equals(role.getRoleId()))) { |
| | | try { |
| | | StpUtil.logoutByTokenValue(token); |
| | | } catch (NotLoginException ignored) { |
| | | } |
| | | } |
| | | }); |
| | | return R.ok(); |
| | | } |
| | | return R.fail("修改角色'" + role.getRoleName() + "'失败,请联系管理员"); |
| | |
| | | */ |
| | | @SaCheckPermission("system:role:list") |
| | | @GetMapping("/authUser/allocatedList") |
| | | public TableDataInfo<SysUser> allocatedList(SysUser user, PageQuery pageQuery) { |
| | | public TableDataInfo<SysUserVo> allocatedList(SysUserBo user, PageQuery pageQuery) { |
| | | return userService.selectAllocatedList(user, pageQuery); |
| | | } |
| | | |
| | |
| | | */ |
| | | @SaCheckPermission("system:role:list") |
| | | @GetMapping("/authUser/unallocatedList") |
| | | public TableDataInfo<SysUser> unallocatedList(SysUser user, PageQuery pageQuery) { |
| | | public TableDataInfo<SysUserVo> unallocatedList(SysUserBo user, PageQuery pageQuery) { |
| | | return userService.selectUnallocatedList(user, pageQuery); |
| | | } |
| | | |
| | |
| | | */ |
| | | @SaCheckPermission("system:role:list") |
| | | @GetMapping(value = "/deptTree/{roleId}") |
| | | public R<Map<String, Object>> roleDeptTreeselect(@PathVariable("roleId") Long roleId) { |
| | | return R.ok(Map.of( |
| | | "checkedKeys", deptService.selectDeptListByRoleId(roleId), |
| | | "depts", deptService.selectDeptTreeList(new SysDept()) |
| | | )); |
| | | public R<DeptTreeSelectVo> roleDeptTreeselect(@PathVariable("roleId") Long roleId) { |
| | | DeptTreeSelectVo selectVo = new DeptTreeSelectVo(); |
| | | selectVo.setCheckedKeys(deptService.selectDeptListByRoleId(roleId)); |
| | | selectVo.setDepts(deptService.selectDeptTreeList(new SysDeptBo())); |
| | | return R.ok(selectVo); |
| | | } |
| | | } |