| @@ -79,4 +79,5 @@ public class Constant { | |||
| public final static String Sex_Men = "0"; | |||
| public final static String Admin = "admin"; | |||
| } | |||
| @@ -4,6 +4,8 @@ import java.util.Set; | |||
| import javax.validation.constraints.NotBlank; | |||
| import javax.validation.constraints.NotNull; | |||
| import javax.validation.constraints.Size; | |||
| import com.ruoyi.system.api.constant.Constant; | |||
| import org.apache.commons.lang3.builder.ToStringBuilder; | |||
| import org.apache.commons.lang3.builder.ToStringStyle; | |||
| import com.ruoyi.common.core.annotation.Excel; | |||
| @@ -12,230 +14,225 @@ import com.ruoyi.common.core.web.domain.BaseEntity; | |||
| /** | |||
| * 角色表 sys_role | |||
| * | |||
| * | |||
| * @author ruoyi | |||
| */ | |||
| public class SysRole extends BaseEntity | |||
| { | |||
| public class SysRole extends BaseEntity { | |||
| private static final long serialVersionUID = 1L; | |||
| /** 角色ID */ | |||
| /** | |||
| * 角色ID | |||
| */ | |||
| @Excel(name = "角色序号", cellType = ColumnType.NUMERIC) | |||
| private Long roleId; | |||
| /** 角色名称 */ | |||
| /** | |||
| * 角色名称 | |||
| */ | |||
| @Excel(name = "角色名称") | |||
| private String roleName; | |||
| /** 角色权限 */ | |||
| /** | |||
| * 角色权限 | |||
| */ | |||
| @Excel(name = "角色权限") | |||
| private String roleKey; | |||
| /** 角色排序 */ | |||
| /** | |||
| * 角色排序 | |||
| */ | |||
| @Excel(name = "角色排序") | |||
| private Integer roleSort; | |||
| /** 数据范围(1:所有数据权限;2:自定义数据权限;3:本部门数据权限;4:本部门及以下数据权限;5:仅本人数据权限) */ | |||
| /** | |||
| * 数据范围(1:所有数据权限;2:自定义数据权限;3:本部门数据权限;4:本部门及以下数据权限;5:仅本人数据权限) | |||
| */ | |||
| @Excel(name = "数据范围", readConverterExp = "1=所有数据权限,2=自定义数据权限,3=本部门数据权限,4=本部门及以下数据权限,5=仅本人数据权限") | |||
| private String dataScope; | |||
| /** 菜单树选择项是否关联显示( 0:父子不互相关联显示 1:父子互相关联显示) */ | |||
| /** | |||
| * 菜单树选择项是否关联显示( 0:父子不互相关联显示 1:父子互相关联显示) | |||
| */ | |||
| private boolean menuCheckStrictly; | |||
| /** 部门树选择项是否关联显示(0:父子不互相关联显示 1:父子互相关联显示 ) */ | |||
| /** | |||
| * 部门树选择项是否关联显示(0:父子不互相关联显示 1:父子互相关联显示 ) | |||
| */ | |||
| private boolean deptCheckStrictly; | |||
| /** 角色状态(0正常 1停用) */ | |||
| /** | |||
| * 角色状态(0正常 1停用) | |||
| */ | |||
| @Excel(name = "角色状态", readConverterExp = "0=正常,1=停用") | |||
| private String status; | |||
| /** 删除标志(0代表存在 2代表删除) */ | |||
| /** | |||
| * 删除标志(0代表存在 2代表删除) | |||
| */ | |||
| private String delFlag; | |||
| /** 用户是否存在此角色标识 默认不存在 */ | |||
| /** | |||
| * 用户是否存在此角色标识 默认不存在 | |||
| */ | |||
| private boolean flag = false; | |||
| /** 菜单组 */ | |||
| /** | |||
| * 菜单组 | |||
| */ | |||
| private Long[] menuIds; | |||
| /** 部门组(数据权限) */ | |||
| /** | |||
| * 部门组(数据权限) | |||
| */ | |||
| private Long[] deptIds; | |||
| /** 角色菜单权限 */ | |||
| /** | |||
| * 角色菜单权限 | |||
| */ | |||
| private Set<String> permissions; | |||
| public SysRole() | |||
| { | |||
| public SysRole() { | |||
| } | |||
| public SysRole(Long roleId) | |||
| { | |||
| public SysRole(Long roleId) { | |||
| this.roleId = roleId; | |||
| } | |||
| public Long getRoleId() | |||
| { | |||
| public Long getRoleId() { | |||
| return roleId; | |||
| } | |||
| public void setRoleId(Long roleId) | |||
| { | |||
| public void setRoleId(Long roleId) { | |||
| this.roleId = roleId; | |||
| } | |||
| public boolean isAdmin() | |||
| { | |||
| return isAdmin(this.roleId); | |||
| public boolean isAdmin() { | |||
| return isAdmin(this.roleKey); | |||
| } | |||
| public static boolean isAdmin(Long roleId) | |||
| { | |||
| return roleId != null && 1L == roleId; | |||
| public static boolean isAdmin(String roleKey) { | |||
| return Constant.Admin.equals(roleKey); | |||
| } | |||
| @NotBlank(message = "角色名称不能为空") | |||
| @Size(min = 0, max = 30, message = "角色名称长度不能超过30个字符") | |||
| public String getRoleName() | |||
| { | |||
| public String getRoleName() { | |||
| return roleName; | |||
| } | |||
| public void setRoleName(String roleName) | |||
| { | |||
| public void setRoleName(String roleName) { | |||
| this.roleName = roleName; | |||
| } | |||
| @NotBlank(message = "权限字符不能为空") | |||
| @Size(min = 0, max = 100, message = "权限字符长度不能超过100个字符") | |||
| public String getRoleKey() | |||
| { | |||
| public String getRoleKey() { | |||
| return roleKey; | |||
| } | |||
| public void setRoleKey(String roleKey) | |||
| { | |||
| public void setRoleKey(String roleKey) { | |||
| this.roleKey = roleKey; | |||
| } | |||
| @NotNull(message = "显示顺序不能为空") | |||
| public Integer getRoleSort() | |||
| { | |||
| public Integer getRoleSort() { | |||
| return roleSort; | |||
| } | |||
| public void setRoleSort(Integer roleSort) | |||
| { | |||
| public void setRoleSort(Integer roleSort) { | |||
| this.roleSort = roleSort; | |||
| } | |||
| public String getDataScope() | |||
| { | |||
| public String getDataScope() { | |||
| return dataScope; | |||
| } | |||
| public void setDataScope(String dataScope) | |||
| { | |||
| public void setDataScope(String dataScope) { | |||
| this.dataScope = dataScope; | |||
| } | |||
| public boolean isMenuCheckStrictly() | |||
| { | |||
| public boolean isMenuCheckStrictly() { | |||
| return menuCheckStrictly; | |||
| } | |||
| public void setMenuCheckStrictly(boolean menuCheckStrictly) | |||
| { | |||
| public void setMenuCheckStrictly(boolean menuCheckStrictly) { | |||
| this.menuCheckStrictly = menuCheckStrictly; | |||
| } | |||
| public boolean isDeptCheckStrictly() | |||
| { | |||
| public boolean isDeptCheckStrictly() { | |||
| return deptCheckStrictly; | |||
| } | |||
| public void setDeptCheckStrictly(boolean deptCheckStrictly) | |||
| { | |||
| public void setDeptCheckStrictly(boolean deptCheckStrictly) { | |||
| this.deptCheckStrictly = deptCheckStrictly; | |||
| } | |||
| public String getStatus() | |||
| { | |||
| public String getStatus() { | |||
| return status; | |||
| } | |||
| public void setStatus(String status) | |||
| { | |||
| public void setStatus(String status) { | |||
| this.status = status; | |||
| } | |||
| public String getDelFlag() | |||
| { | |||
| public String getDelFlag() { | |||
| return delFlag; | |||
| } | |||
| public void setDelFlag(String delFlag) | |||
| { | |||
| public void setDelFlag(String delFlag) { | |||
| this.delFlag = delFlag; | |||
| } | |||
| public boolean isFlag() | |||
| { | |||
| public boolean isFlag() { | |||
| return flag; | |||
| } | |||
| public void setFlag(boolean flag) | |||
| { | |||
| public void setFlag(boolean flag) { | |||
| this.flag = flag; | |||
| } | |||
| public Long[] getMenuIds() | |||
| { | |||
| public Long[] getMenuIds() { | |||
| return menuIds; | |||
| } | |||
| public void setMenuIds(Long[] menuIds) | |||
| { | |||
| public void setMenuIds(Long[] menuIds) { | |||
| this.menuIds = menuIds; | |||
| } | |||
| public Long[] getDeptIds() | |||
| { | |||
| public Long[] getDeptIds() { | |||
| return deptIds; | |||
| } | |||
| public void setDeptIds(Long[] deptIds) | |||
| { | |||
| public void setDeptIds(Long[] deptIds) { | |||
| this.deptIds = deptIds; | |||
| } | |||
| public Set<String> getPermissions() | |||
| { | |||
| public Set<String> getPermissions() { | |||
| return permissions; | |||
| } | |||
| public void setPermissions(Set<String> permissions) | |||
| { | |||
| public void setPermissions(Set<String> permissions) { | |||
| this.permissions = permissions; | |||
| } | |||
| @Override | |||
| public String toString() { | |||
| return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) | |||
| .append("roleId", getRoleId()) | |||
| .append("roleName", getRoleName()) | |||
| .append("roleKey", getRoleKey()) | |||
| .append("roleSort", getRoleSort()) | |||
| .append("dataScope", getDataScope()) | |||
| .append("menuCheckStrictly", isMenuCheckStrictly()) | |||
| .append("deptCheckStrictly", isDeptCheckStrictly()) | |||
| .append("status", getStatus()) | |||
| .append("delFlag", getDelFlag()) | |||
| .append("createBy", getCreateBy()) | |||
| .append("createTime", getCreateTime()) | |||
| .append("updateBy", getUpdateBy()) | |||
| .append("updateTime", getUpdateTime()) | |||
| .append("remark", getRemark()) | |||
| .toString(); | |||
| return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE) | |||
| .append("roleId", getRoleId()) | |||
| .append("roleName", getRoleName()) | |||
| .append("roleKey", getRoleKey()) | |||
| .append("roleSort", getRoleSort()) | |||
| .append("dataScope", getDataScope()) | |||
| .append("menuCheckStrictly", isMenuCheckStrictly()) | |||
| .append("deptCheckStrictly", isDeptCheckStrictly()) | |||
| .append("status", getStatus()) | |||
| .append("delFlag", getDelFlag()) | |||
| .append("createBy", getCreateBy()) | |||
| .append("createTime", getCreateTime()) | |||
| .append("updateBy", getUpdateBy()) | |||
| .append("updateTime", getUpdateTime()) | |||
| .append("remark", getRemark()) | |||
| .toString(); | |||
| } | |||
| } | |||
| @@ -155,13 +155,13 @@ public class SysUser extends BaseEntity { | |||
| this.userId = userId; | |||
| } | |||
| public boolean isAdmin() { | |||
| return isAdmin(this.userId); | |||
| } | |||
| public static boolean isAdmin(Long userId) { | |||
| return userId != null && 1L == userId; | |||
| } | |||
| // public boolean isAdmin() { | |||
| // return isAdmin(this.userId); | |||
| // } | |||
| // | |||
| // public static boolean isAdmin(Long userId) { | |||
| // return userId != null && 1L == userId; | |||
| // } | |||
| public Long getDeptId() { | |||
| return deptId; | |||
| @@ -70,12 +70,12 @@ public class DataScopeAspect | |||
| { | |||
| SysUser currentUser = loginUser.getSysUser(); | |||
| // 如果是超级管理员,则不过滤数据 | |||
| if (StringUtils.isNotNull(currentUser) && !currentUser.isAdmin()) | |||
| { | |||
| // if (StringUtils.isNotNull(currentUser) && !currentUser.isAdmin()) | |||
| // { | |||
| String permission = StringUtils.defaultIfEmpty(controllerDataScope.permission(), SecurityContextHolder.getPermission()); | |||
| dataScopeFilter(joinPoint, currentUser, controllerDataScope.deptAlias(), | |||
| controllerDataScope.userAlias(), permission); | |||
| } | |||
| // } | |||
| } | |||
| } | |||
| @@ -1,6 +1,8 @@ | |||
| package com.ruoyi.system.controller; | |||
| import java.util.List; | |||
| import com.ruoyi.system.api.constant.Constant; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.validation.annotation.Validated; | |||
| import org.springframework.web.bind.annotation.DeleteMapping; | |||
| @@ -41,8 +43,7 @@ public class SysMenuController extends BaseController | |||
| @GetMapping("/list") | |||
| public AjaxResult list(SysMenu menu) | |||
| { | |||
| Long userId = SecurityUtils.getUserId(); | |||
| List<SysMenu> menus = menuService.selectMenuList(menu, userId); | |||
| List<SysMenu> menus = menuService.selectMenuList(menu); | |||
| return success(menus); | |||
| } | |||
| @@ -62,8 +63,7 @@ public class SysMenuController extends BaseController | |||
| @GetMapping("/treeselect") | |||
| public AjaxResult treeselect(SysMenu menu) | |||
| { | |||
| Long userId = SecurityUtils.getUserId(); | |||
| List<SysMenu> menus = menuService.selectMenuList(menu, userId); | |||
| List<SysMenu> menus = menuService.selectMenuList(menu); | |||
| return success(menuService.buildMenuTreeSelect(menus)); | |||
| } | |||
| @@ -73,8 +73,7 @@ public class SysMenuController extends BaseController | |||
| @GetMapping(value = "/roleMenuTreeselect/{roleId}") | |||
| public AjaxResult roleMenuTreeselect(@PathVariable("roleId") Long roleId) | |||
| { | |||
| Long userId = SecurityUtils.getUserId(); | |||
| List<SysMenu> menus = menuService.selectMenuList(userId); | |||
| List<SysMenu> menus = menuService.selectMenuList(new SysMenu()); | |||
| AjaxResult ajax = AjaxResult.success(); | |||
| ajax.put("checkedKeys", menuService.selectMenuListByRoleId(roleId)); | |||
| ajax.put("menus", menuService.buildMenuTreeSelect(menus)); | |||
| @@ -271,7 +271,7 @@ public class SysUserController extends BaseController { | |||
| SysUser user = userService.selectUserById(userId); | |||
| List<SysRole> roles = roleService.selectRolesByUserId(userId); | |||
| ajax.put("user", user); | |||
| ajax.put("roles", SysUser.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList())); | |||
| ajax.put("roles", roles); | |||
| return ajax; | |||
| } | |||
| @@ -13,13 +13,6 @@ import com.ruoyi.system.domain.vo.TreeSelect; | |||
| */ | |||
| public interface ISysMenuService | |||
| { | |||
| /** | |||
| * 根据用户查询系统菜单列表 | |||
| * | |||
| * @param userId 用户ID | |||
| * @return 菜单列表 | |||
| */ | |||
| public List<SysMenu> selectMenuList(Long userId); | |||
| /** | |||
| * 根据用户查询系统菜单列表 | |||
| @@ -28,7 +21,7 @@ public interface ISysMenuService | |||
| * @param userId 用户ID | |||
| * @return 菜单列表 | |||
| */ | |||
| public List<SysMenu> selectMenuList(SysMenu menu, Long userId); | |||
| public List<SysMenu> selectMenuList(SysMenu menu); | |||
| /** | |||
| * 根据用户ID查询权限 | |||
| @@ -89,6 +89,11 @@ public interface ISysRoleService | |||
| */ | |||
| public void checkRoleDataScope(Long roleId); | |||
| public Boolean checkIsAdmin(); | |||
| public Boolean checkIsAdmin(Long userId); | |||
| /** | |||
| * 通过角色ID查询角色使用数量 | |||
| * | |||
| @@ -190,8 +190,8 @@ public class SysDeptServiceImpl implements ISysDeptService | |||
| @Override | |||
| public void checkDeptDataScope(Long deptId) | |||
| { | |||
| if (!SysUser.isAdmin(SecurityUtils.getUserId())) | |||
| { | |||
| // if (!SysUser.isAdmin(SecurityUtils.getUserId())) | |||
| // { | |||
| SysDept dept = new SysDept(); | |||
| dept.setDeptId(deptId); | |||
| List<SysDept> depts = SpringUtils.getAopProxy(this).selectDeptList(dept); | |||
| @@ -199,7 +199,7 @@ public class SysDeptServiceImpl implements ISysDeptService | |||
| { | |||
| throw new ServiceException("没有权限访问部门数据!"); | |||
| } | |||
| } | |||
| // } | |||
| } | |||
| /** | |||
| @@ -8,6 +8,9 @@ import java.util.LinkedList; | |||
| import java.util.List; | |||
| import java.util.Set; | |||
| import java.util.stream.Collectors; | |||
| import com.ruoyi.system.api.constant.Constant; | |||
| import com.ruoyi.system.service.ISysRoleService; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Service; | |||
| import com.ruoyi.common.core.constant.Constants; | |||
| @@ -27,12 +30,11 @@ import com.ruoyi.system.service.ISysMenuService; | |||
| /** | |||
| * 菜单 业务层处理 | |||
| * | |||
| * | |||
| * @author ruoyi | |||
| */ | |||
| @Service | |||
| public class SysMenuServiceImpl implements ISysMenuService | |||
| { | |||
| public class SysMenuServiceImpl implements ISysMenuService { | |||
| public static final String PREMISSION_STRING = "perms[\"{0}\"]"; | |||
| @Autowired | |||
| @@ -44,36 +46,23 @@ public class SysMenuServiceImpl implements ISysMenuService | |||
| @Autowired | |||
| private SysRoleMenuMapper roleMenuMapper; | |||
| /** | |||
| * 根据用户查询系统菜单列表 | |||
| * | |||
| * @param userId 用户ID | |||
| * @return 菜单列表 | |||
| */ | |||
| @Override | |||
| public List<SysMenu> selectMenuList(Long userId) | |||
| { | |||
| return selectMenuList(new SysMenu(), userId); | |||
| } | |||
| @Autowired | |||
| private ISysRoleService sysRoleService; | |||
| /** | |||
| * 查询系统菜单列表 | |||
| * | |||
| * | |||
| * @param menu 菜单信息 | |||
| * @return 菜单列表 | |||
| */ | |||
| @Override | |||
| public List<SysMenu> selectMenuList(SysMenu menu, Long userId) | |||
| { | |||
| List<SysMenu> menuList = null; | |||
| public List<SysMenu> selectMenuList(SysMenu menu) { | |||
| List<SysMenu> menuList; | |||
| // 管理员显示所有菜单信息 | |||
| if (SysUser.isAdmin(userId)) | |||
| { | |||
| if (sysRoleService.checkIsAdmin()) { | |||
| menuList = menuMapper.selectMenuList(menu); | |||
| } | |||
| else | |||
| { | |||
| menu.getParams().put("userId", userId); | |||
| } else { | |||
| menu.getParams().put("userId", SecurityUtils.getUserId()); | |||
| menuList = menuMapper.selectMenuListByUserId(menu); | |||
| } | |||
| return menuList; | |||
| @@ -81,19 +70,16 @@ public class SysMenuServiceImpl implements ISysMenuService | |||
| /** | |||
| * 根据用户ID查询权限 | |||
| * | |||
| * | |||
| * @param userId 用户ID | |||
| * @return 权限列表 | |||
| */ | |||
| @Override | |||
| public Set<String> selectMenuPermsByUserId(Long userId) | |||
| { | |||
| public Set<String> selectMenuPermsByUserId(Long userId) { | |||
| List<String> perms = menuMapper.selectMenuPermsByUserId(userId); | |||
| Set<String> permsSet = new HashSet<>(); | |||
| for (String perm : perms) | |||
| { | |||
| if (StringUtils.isNotEmpty(perm)) | |||
| { | |||
| for (String perm : perms) { | |||
| if (StringUtils.isNotEmpty(perm)) { | |||
| permsSet.addAll(Arrays.asList(perm.trim().split(","))); | |||
| } | |||
| } | |||
| @@ -102,19 +88,16 @@ public class SysMenuServiceImpl implements ISysMenuService | |||
| /** | |||
| * 根据角色ID查询权限 | |||
| * | |||
| * | |||
| * @param roleId 角色ID | |||
| * @return 权限列表 | |||
| */ | |||
| @Override | |||
| public Set<String> selectMenuPermsByRoleId(Long roleId) | |||
| { | |||
| public Set<String> selectMenuPermsByRoleId(Long roleId) { | |||
| List<String> perms = menuMapper.selectMenuPermsByRoleId(roleId); | |||
| Set<String> permsSet = new HashSet<>(); | |||
| for (String perm : perms) | |||
| { | |||
| if (StringUtils.isNotEmpty(perm)) | |||
| { | |||
| for (String perm : perms) { | |||
| if (StringUtils.isNotEmpty(perm)) { | |||
| permsSet.addAll(Arrays.asList(perm.trim().split(","))); | |||
| } | |||
| } | |||
| @@ -123,20 +106,16 @@ public class SysMenuServiceImpl implements ISysMenuService | |||
| /** | |||
| * 根据用户ID查询菜单 | |||
| * | |||
| * | |||
| * @param userId 用户名称 | |||
| * @return 菜单列表 | |||
| */ | |||
| @Override | |||
| public List<SysMenu> selectMenuTreeByUserId(Long userId) | |||
| { | |||
| List<SysMenu> menus = null; | |||
| if (SecurityUtils.isAdmin(userId)) | |||
| { | |||
| public List<SysMenu> selectMenuTreeByUserId(Long userId) { | |||
| List<SysMenu> menus; | |||
| if (sysRoleService.checkIsAdmin()) { | |||
| menus = menuMapper.selectMenuTreeAll(); | |||
| } | |||
| else | |||
| { | |||
| } else { | |||
| menus = menuMapper.selectMenuTreeByUserId(userId); | |||
| } | |||
| return getChildPerms(menus, 0); | |||
| @@ -144,29 +123,26 @@ public class SysMenuServiceImpl implements ISysMenuService | |||
| /** | |||
| * 根据角色ID查询菜单树信息 | |||
| * | |||
| * | |||
| * @param roleId 角色ID | |||
| * @return 选中菜单列表 | |||
| */ | |||
| @Override | |||
| public List<Long> selectMenuListByRoleId(Long roleId) | |||
| { | |||
| public List<Long> selectMenuListByRoleId(Long roleId) { | |||
| SysRole role = roleMapper.selectRoleById(roleId); | |||
| return menuMapper.selectMenuListByRoleId(roleId, role.isMenuCheckStrictly()); | |||
| } | |||
| /** | |||
| * 构建前端路由所需要的菜单 | |||
| * | |||
| * | |||
| * @param menus 菜单列表 | |||
| * @return 路由列表 | |||
| */ | |||
| @Override | |||
| public List<RouterVo> buildMenus(List<SysMenu> menus) | |||
| { | |||
| public List<RouterVo> buildMenus(List<SysMenu> menus) { | |||
| List<RouterVo> routers = new LinkedList<RouterVo>(); | |||
| for (SysMenu menu : menus) | |||
| { | |||
| for (SysMenu menu : menus) { | |||
| RouterVo router = new RouterVo(); | |||
| router.setHidden("1".equals(menu.getVisible())); | |||
| router.setName(getRouteName(menu)); | |||
| @@ -175,14 +151,11 @@ public class SysMenuServiceImpl implements ISysMenuService | |||
| router.setQuery(menu.getQuery()); | |||
| router.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon(), StringUtils.equals("1", menu.getIsCache()), menu.getPath())); | |||
| List<SysMenu> cMenus = menu.getChildren(); | |||
| if (StringUtils.isNotEmpty(cMenus) && UserConstants.TYPE_DIR.equals(menu.getMenuType())) | |||
| { | |||
| if (StringUtils.isNotEmpty(cMenus) && UserConstants.TYPE_DIR.equals(menu.getMenuType())) { | |||
| router.setAlwaysShow(true); | |||
| router.setRedirect("noRedirect"); | |||
| router.setChildren(buildMenus(cMenus)); | |||
| } | |||
| else if (isMenuFrame(menu)) | |||
| { | |||
| } else if (isMenuFrame(menu)) { | |||
| router.setMeta(null); | |||
| List<RouterVo> childrenList = new ArrayList<RouterVo>(); | |||
| RouterVo children = new RouterVo(); | |||
| @@ -193,9 +166,7 @@ public class SysMenuServiceImpl implements ISysMenuService | |||
| children.setQuery(menu.getQuery()); | |||
| childrenList.add(children); | |||
| router.setChildren(childrenList); | |||
| } | |||
| else if (menu.getParentId().intValue() == 0 && isInnerLink(menu)) | |||
| { | |||
| } else if (menu.getParentId().intValue() == 0 && isInnerLink(menu)) { | |||
| router.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon())); | |||
| router.setPath("/"); | |||
| List<RouterVo> childrenList = new ArrayList<RouterVo>(); | |||
| @@ -215,27 +186,23 @@ public class SysMenuServiceImpl implements ISysMenuService | |||
| /** | |||
| * 构建前端所需要树结构 | |||
| * | |||
| * | |||
| * @param menus 菜单列表 | |||
| * @return 树结构列表 | |||
| */ | |||
| @Override | |||
| public List<SysMenu> buildMenuTree(List<SysMenu> menus) | |||
| { | |||
| public List<SysMenu> buildMenuTree(List<SysMenu> menus) { | |||
| List<SysMenu> returnList = new ArrayList<SysMenu>(); | |||
| List<Long> tempList = menus.stream().map(SysMenu::getMenuId).collect(Collectors.toList()); | |||
| for (Iterator<SysMenu> iterator = menus.iterator(); iterator.hasNext();) | |||
| { | |||
| for (Iterator<SysMenu> iterator = menus.iterator(); iterator.hasNext(); ) { | |||
| SysMenu menu = (SysMenu) iterator.next(); | |||
| // 如果是顶级节点, 遍历该父节点的所有子节点 | |||
| if (!tempList.contains(menu.getParentId())) | |||
| { | |||
| if (!tempList.contains(menu.getParentId())) { | |||
| recursionFn(menus, menu); | |||
| returnList.add(menu); | |||
| } | |||
| } | |||
| if (returnList.isEmpty()) | |||
| { | |||
| if (returnList.isEmpty()) { | |||
| returnList = menus; | |||
| } | |||
| return returnList; | |||
| @@ -243,104 +210,95 @@ public class SysMenuServiceImpl implements ISysMenuService | |||
| /** | |||
| * 构建前端所需要下拉树结构 | |||
| * | |||
| * | |||
| * @param menus 菜单列表 | |||
| * @return 下拉树结构列表 | |||
| */ | |||
| @Override | |||
| public List<TreeSelect> buildMenuTreeSelect(List<SysMenu> menus) | |||
| { | |||
| public List<TreeSelect> buildMenuTreeSelect(List<SysMenu> menus) { | |||
| List<SysMenu> menuTrees = buildMenuTree(menus); | |||
| return menuTrees.stream().map(TreeSelect::new).collect(Collectors.toList()); | |||
| } | |||
| /** | |||
| * 根据菜单ID查询信息 | |||
| * | |||
| * | |||
| * @param menuId 菜单ID | |||
| * @return 菜单信息 | |||
| */ | |||
| @Override | |||
| public SysMenu selectMenuById(Long menuId) | |||
| { | |||
| public SysMenu selectMenuById(Long menuId) { | |||
| return menuMapper.selectMenuById(menuId); | |||
| } | |||
| /** | |||
| * 是否存在菜单子节点 | |||
| * | |||
| * | |||
| * @param menuId 菜单ID | |||
| * @return 结果 | |||
| */ | |||
| @Override | |||
| public boolean hasChildByMenuId(Long menuId) | |||
| { | |||
| public boolean hasChildByMenuId(Long menuId) { | |||
| int result = menuMapper.hasChildByMenuId(menuId); | |||
| return result > 0; | |||
| } | |||
| /** | |||
| * 查询菜单使用数量 | |||
| * | |||
| * | |||
| * @param menuId 菜单ID | |||
| * @return 结果 | |||
| */ | |||
| @Override | |||
| public boolean checkMenuExistRole(Long menuId) | |||
| { | |||
| public boolean checkMenuExistRole(Long menuId) { | |||
| int result = roleMenuMapper.checkMenuExistRole(menuId); | |||
| return result > 0; | |||
| } | |||
| /** | |||
| * 新增保存菜单信息 | |||
| * | |||
| * | |||
| * @param menu 菜单信息 | |||
| * @return 结果 | |||
| */ | |||
| @Override | |||
| public int insertMenu(SysMenu menu) | |||
| { | |||
| public int insertMenu(SysMenu menu) { | |||
| return menuMapper.insertMenu(menu); | |||
| } | |||
| /** | |||
| * 修改保存菜单信息 | |||
| * | |||
| * | |||
| * @param menu 菜单信息 | |||
| * @return 结果 | |||
| */ | |||
| @Override | |||
| public int updateMenu(SysMenu menu) | |||
| { | |||
| public int updateMenu(SysMenu menu) { | |||
| return menuMapper.updateMenu(menu); | |||
| } | |||
| /** | |||
| * 删除菜单管理信息 | |||
| * | |||
| * | |||
| * @param menuId 菜单ID | |||
| * @return 结果 | |||
| */ | |||
| @Override | |||
| public int deleteMenuById(Long menuId) | |||
| { | |||
| public int deleteMenuById(Long menuId) { | |||
| return menuMapper.deleteMenuById(menuId); | |||
| } | |||
| /** | |||
| * 校验菜单名称是否唯一 | |||
| * | |||
| * | |||
| * @param menu 菜单信息 | |||
| * @return 结果 | |||
| */ | |||
| @Override | |||
| public boolean checkMenuNameUnique(SysMenu menu) | |||
| { | |||
| public boolean checkMenuNameUnique(SysMenu menu) { | |||
| Long menuId = StringUtils.isNull(menu.getMenuId()) ? -1L : menu.getMenuId(); | |||
| SysMenu info = menuMapper.checkMenuNameUnique(menu.getMenuName(), menu.getParentId()); | |||
| if (StringUtils.isNotNull(info) && info.getMenuId().longValue() != menuId.longValue()) | |||
| { | |||
| if (StringUtils.isNotNull(info) && info.getMenuId().longValue() != menuId.longValue()) { | |||
| return UserConstants.NOT_UNIQUE; | |||
| } | |||
| return UserConstants.UNIQUE; | |||
| @@ -348,16 +306,14 @@ public class SysMenuServiceImpl implements ISysMenuService | |||
| /** | |||
| * 获取路由名称 | |||
| * | |||
| * | |||
| * @param menu 菜单信息 | |||
| * @return 路由名称 | |||
| */ | |||
| public String getRouteName(SysMenu menu) | |||
| { | |||
| public String getRouteName(SysMenu menu) { | |||
| String routerName = StringUtils.capitalize(menu.getPath()); | |||
| // 非外链并且是一级目录(类型为目录) | |||
| if (isMenuFrame(menu)) | |||
| { | |||
| if (isMenuFrame(menu)) { | |||
| routerName = StringUtils.EMPTY; | |||
| } | |||
| return routerName; | |||
| @@ -365,27 +321,23 @@ public class SysMenuServiceImpl implements ISysMenuService | |||
| /** | |||
| * 获取路由地址 | |||
| * | |||
| * | |||
| * @param menu 菜单信息 | |||
| * @return 路由地址 | |||
| */ | |||
| public String getRouterPath(SysMenu menu) | |||
| { | |||
| public String getRouterPath(SysMenu menu) { | |||
| String routerPath = menu.getPath(); | |||
| // 内链打开外网方式 | |||
| if (menu.getParentId().intValue() != 0 && isInnerLink(menu)) | |||
| { | |||
| if (menu.getParentId().intValue() != 0 && isInnerLink(menu)) { | |||
| routerPath = innerLinkReplaceEach(routerPath); | |||
| } | |||
| // 非外链并且是一级目录(类型为目录) | |||
| if (0 == menu.getParentId().intValue() && UserConstants.TYPE_DIR.equals(menu.getMenuType()) | |||
| && UserConstants.NO_FRAME.equals(menu.getIsFrame())) | |||
| { | |||
| && UserConstants.NO_FRAME.equals(menu.getIsFrame())) { | |||
| routerPath = "/" + menu.getPath(); | |||
| } | |||
| // 非外链并且是一级目录(类型为菜单) | |||
| else if (isMenuFrame(menu)) | |||
| { | |||
| else if (isMenuFrame(menu)) { | |||
| routerPath = "/"; | |||
| } | |||
| return routerPath; | |||
| @@ -393,23 +345,17 @@ public class SysMenuServiceImpl implements ISysMenuService | |||
| /** | |||
| * 获取组件信息 | |||
| * | |||
| * | |||
| * @param menu 菜单信息 | |||
| * @return 组件信息 | |||
| */ | |||
| public String getComponent(SysMenu menu) | |||
| { | |||
| public String getComponent(SysMenu menu) { | |||
| String component = UserConstants.LAYOUT; | |||
| if (StringUtils.isNotEmpty(menu.getComponent()) && !isMenuFrame(menu)) | |||
| { | |||
| if (StringUtils.isNotEmpty(menu.getComponent()) && !isMenuFrame(menu)) { | |||
| component = menu.getComponent(); | |||
| } | |||
| else if (StringUtils.isEmpty(menu.getComponent()) && menu.getParentId().intValue() != 0 && isInnerLink(menu)) | |||
| { | |||
| } else if (StringUtils.isEmpty(menu.getComponent()) && menu.getParentId().intValue() != 0 && isInnerLink(menu)) { | |||
| component = UserConstants.INNER_LINK; | |||
| } | |||
| else if (StringUtils.isEmpty(menu.getComponent()) && isParentView(menu)) | |||
| { | |||
| } else if (StringUtils.isEmpty(menu.getComponent()) && isParentView(menu)) { | |||
| component = UserConstants.PARENT_VIEW; | |||
| } | |||
| return component; | |||
| @@ -417,54 +363,48 @@ public class SysMenuServiceImpl implements ISysMenuService | |||
| /** | |||
| * 是否为菜单内部跳转 | |||
| * | |||
| * | |||
| * @param menu 菜单信息 | |||
| * @return 结果 | |||
| */ | |||
| public boolean isMenuFrame(SysMenu menu) | |||
| { | |||
| public boolean isMenuFrame(SysMenu menu) { | |||
| return menu.getParentId().intValue() == 0 && UserConstants.TYPE_MENU.equals(menu.getMenuType()) | |||
| && menu.getIsFrame().equals(UserConstants.NO_FRAME); | |||
| } | |||
| /** | |||
| * 是否为内链组件 | |||
| * | |||
| * | |||
| * @param menu 菜单信息 | |||
| * @return 结果 | |||
| */ | |||
| public boolean isInnerLink(SysMenu menu) | |||
| { | |||
| public boolean isInnerLink(SysMenu menu) { | |||
| return menu.getIsFrame().equals(UserConstants.NO_FRAME) && StringUtils.ishttp(menu.getPath()); | |||
| } | |||
| /** | |||
| * 是否为parent_view组件 | |||
| * | |||
| * | |||
| * @param menu 菜单信息 | |||
| * @return 结果 | |||
| */ | |||
| public boolean isParentView(SysMenu menu) | |||
| { | |||
| public boolean isParentView(SysMenu menu) { | |||
| return menu.getParentId().intValue() != 0 && UserConstants.TYPE_DIR.equals(menu.getMenuType()); | |||
| } | |||
| /** | |||
| * 根据父节点的ID获取所有子节点 | |||
| * | |||
| * @param list 分类表 | |||
| * | |||
| * @param list 分类表 | |||
| * @param parentId 传入的父节点ID | |||
| * @return String | |||
| */ | |||
| public List<SysMenu> getChildPerms(List<SysMenu> list, int parentId) | |||
| { | |||
| public List<SysMenu> getChildPerms(List<SysMenu> list, int parentId) { | |||
| List<SysMenu> returnList = new ArrayList<SysMenu>(); | |||
| for (Iterator<SysMenu> iterator = list.iterator(); iterator.hasNext();) | |||
| { | |||
| for (Iterator<SysMenu> iterator = list.iterator(); iterator.hasNext(); ) { | |||
| SysMenu t = (SysMenu) iterator.next(); | |||
| // 一、根据传入的某个父节点ID,遍历该父节点的所有子节点 | |||
| if (t.getParentId() == parentId) | |||
| { | |||
| if (t.getParentId() == parentId) { | |||
| recursionFn(list, t); | |||
| returnList.add(t); | |||
| } | |||
| @@ -474,19 +414,16 @@ public class SysMenuServiceImpl implements ISysMenuService | |||
| /** | |||
| * 递归列表 | |||
| * | |||
| * | |||
| * @param list 分类表 | |||
| * @param t 子节点 | |||
| * @param t 子节点 | |||
| */ | |||
| private void recursionFn(List<SysMenu> list, SysMenu t) | |||
| { | |||
| private void recursionFn(List<SysMenu> list, SysMenu t) { | |||
| // 得到子节点列表 | |||
| List<SysMenu> childList = getChildList(list, t); | |||
| t.setChildren(childList); | |||
| for (SysMenu tChild : childList) | |||
| { | |||
| if (hasChild(list, tChild)) | |||
| { | |||
| for (SysMenu tChild : childList) { | |||
| if (hasChild(list, tChild)) { | |||
| recursionFn(list, tChild); | |||
| } | |||
| } | |||
| @@ -495,15 +432,12 @@ public class SysMenuServiceImpl implements ISysMenuService | |||
| /** | |||
| * 得到子节点列表 | |||
| */ | |||
| private List<SysMenu> getChildList(List<SysMenu> list, SysMenu t) | |||
| { | |||
| private List<SysMenu> getChildList(List<SysMenu> list, SysMenu t) { | |||
| List<SysMenu> tlist = new ArrayList<SysMenu>(); | |||
| Iterator<SysMenu> it = list.iterator(); | |||
| while (it.hasNext()) | |||
| { | |||
| while (it.hasNext()) { | |||
| SysMenu n = (SysMenu) it.next(); | |||
| if (n.getParentId().longValue() == t.getMenuId().longValue()) | |||
| { | |||
| if (n.getParentId().longValue() == t.getMenuId().longValue()) { | |||
| tlist.add(n); | |||
| } | |||
| } | |||
| @@ -513,19 +447,17 @@ public class SysMenuServiceImpl implements ISysMenuService | |||
| /** | |||
| * 判断是否有子节点 | |||
| */ | |||
| private boolean hasChild(List<SysMenu> list, SysMenu t) | |||
| { | |||
| private boolean hasChild(List<SysMenu> list, SysMenu t) { | |||
| return getChildList(list, t).size() > 0; | |||
| } | |||
| /** | |||
| * 内链域名特殊字符替换 | |||
| * | |||
| * | |||
| * @return 替换后的内链域名 | |||
| */ | |||
| public String innerLinkReplaceEach(String path) | |||
| { | |||
| return StringUtils.replaceEach(path, new String[] { Constants.HTTP, Constants.HTTPS, Constants.WWW, ".", ":" }, | |||
| new String[] { "", "", "", "/", "/" }); | |||
| public String innerLinkReplaceEach(String path) { | |||
| return StringUtils.replaceEach(path, new String[]{Constants.HTTP, Constants.HTTPS, Constants.WWW, ".", ":"}, | |||
| new String[]{"", "", "", "/", "/"}); | |||
| } | |||
| } | |||
| @@ -3,6 +3,8 @@ package com.ruoyi.system.service.impl; | |||
| import java.util.HashSet; | |||
| import java.util.List; | |||
| import java.util.Set; | |||
| import com.ruoyi.system.api.constant.Constant; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Service; | |||
| import org.springframework.util.CollectionUtils; | |||
| @@ -37,9 +39,9 @@ public class SysPermissionServiceImpl implements ISysPermissionService | |||
| { | |||
| Set<String> roles = new HashSet<String>(); | |||
| // 管理员拥有所有权限 | |||
| if (user.isAdmin()) | |||
| if (roleService.checkIsAdmin()) | |||
| { | |||
| roles.add("admin"); | |||
| roles.add(Constant.Admin); | |||
| } | |||
| else | |||
| { | |||
| @@ -59,7 +61,7 @@ public class SysPermissionServiceImpl implements ISysPermissionService | |||
| { | |||
| Set<String> perms = new HashSet<String>(); | |||
| // 管理员拥有所有权限 | |||
| if (user.isAdmin()) | |||
| if (roleService.checkIsAdmin()) | |||
| { | |||
| perms.add("*:*:*"); | |||
| } | |||
| @@ -5,6 +5,8 @@ import java.util.Arrays; | |||
| import java.util.HashSet; | |||
| import java.util.List; | |||
| import java.util.Set; | |||
| import com.ruoyi.system.api.constant.Constant; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Service; | |||
| import org.springframework.transaction.annotation.Transactional; | |||
| @@ -27,12 +29,11 @@ import com.ruoyi.system.service.ISysRoleService; | |||
| /** | |||
| * 角色 业务层处理 | |||
| * | |||
| * | |||
| * @author ruoyi | |||
| */ | |||
| @Service | |||
| public class SysRoleServiceImpl implements ISysRoleService | |||
| { | |||
| public class SysRoleServiceImpl implements ISysRoleService { | |||
| @Autowired | |||
| private SysRoleMapper roleMapper; | |||
| @@ -47,34 +48,29 @@ public class SysRoleServiceImpl implements ISysRoleService | |||
| /** | |||
| * 根据条件分页查询角色数据 | |||
| * | |||
| * | |||
| * @param role 角色信息 | |||
| * @return 角色数据集合信息 | |||
| */ | |||
| @Override | |||
| @DataScope(deptAlias = "d") | |||
| public List<SysRole> selectRoleList(SysRole role) | |||
| { | |||
| public List<SysRole> selectRoleList(SysRole role) { | |||
| return roleMapper.selectRoleList(role); | |||
| } | |||
| /** | |||
| * 根据用户ID查询角色 | |||
| * | |||
| * | |||
| * @param userId 用户ID | |||
| * @return 角色列表 | |||
| */ | |||
| @Override | |||
| public List<SysRole> selectRolesByUserId(Long userId) | |||
| { | |||
| public List<SysRole> selectRolesByUserId(Long userId) { | |||
| List<SysRole> userRoles = roleMapper.selectRolePermissionByUserId(userId); | |||
| List<SysRole> roles = selectRoleAll(); | |||
| for (SysRole role : roles) | |||
| { | |||
| for (SysRole userRole : userRoles) | |||
| { | |||
| if (role.getRoleId().longValue() == userRole.getRoleId().longValue()) | |||
| { | |||
| for (SysRole role : roles) { | |||
| for (SysRole userRole : userRoles) { | |||
| if (role.getRoleId().longValue() == userRole.getRoleId().longValue()) { | |||
| role.setFlag(true); | |||
| break; | |||
| } | |||
| @@ -85,19 +81,16 @@ public class SysRoleServiceImpl implements ISysRoleService | |||
| /** | |||
| * 根据用户ID查询权限 | |||
| * | |||
| * | |||
| * @param userId 用户ID | |||
| * @return 权限列表 | |||
| */ | |||
| @Override | |||
| public Set<String> selectRolePermissionByUserId(Long userId) | |||
| { | |||
| public Set<String> selectRolePermissionByUserId(Long userId) { | |||
| List<SysRole> perms = roleMapper.selectRolePermissionByUserId(userId); | |||
| Set<String> permsSet = new HashSet<>(); | |||
| for (SysRole perm : perms) | |||
| { | |||
| if (StringUtils.isNotNull(perm)) | |||
| { | |||
| for (SysRole perm : perms) { | |||
| if (StringUtils.isNotNull(perm)) { | |||
| permsSet.addAll(Arrays.asList(perm.getRoleKey().trim().split(","))); | |||
| } | |||
| } | |||
| @@ -106,52 +99,47 @@ public class SysRoleServiceImpl implements ISysRoleService | |||
| /** | |||
| * 查询所有角色 | |||
| * | |||
| * | |||
| * @return 角色列表 | |||
| */ | |||
| @Override | |||
| public List<SysRole> selectRoleAll() | |||
| { | |||
| public List<SysRole> selectRoleAll() { | |||
| return SpringUtils.getAopProxy(this).selectRoleList(new SysRole()); | |||
| } | |||
| /** | |||
| * 根据用户ID获取角色选择框列表 | |||
| * | |||
| * | |||
| * @param userId 用户ID | |||
| * @return 选中角色ID列表 | |||
| */ | |||
| @Override | |||
| public List<Long> selectRoleListByUserId(Long userId) | |||
| { | |||
| public List<Long> selectRoleListByUserId(Long userId) { | |||
| return roleMapper.selectRoleListByUserId(userId); | |||
| } | |||
| /** | |||
| * 通过角色ID查询角色 | |||
| * | |||
| * | |||
| * @param roleId 角色ID | |||
| * @return 角色对象信息 | |||
| */ | |||
| @Override | |||
| public SysRole selectRoleById(Long roleId) | |||
| { | |||
| public SysRole selectRoleById(Long roleId) { | |||
| return roleMapper.selectRoleById(roleId); | |||
| } | |||
| /** | |||
| * 校验角色名称是否唯一 | |||
| * | |||
| * | |||
| * @param role 角色信息 | |||
| * @return 结果 | |||
| */ | |||
| @Override | |||
| public boolean checkRoleNameUnique(SysRole role) | |||
| { | |||
| public boolean checkRoleNameUnique(SysRole role) { | |||
| Long roleId = StringUtils.isNull(role.getRoleId()) ? -1L : role.getRoleId(); | |||
| SysRole info = roleMapper.checkRoleNameUnique(role.getRoleName()); | |||
| if (StringUtils.isNotNull(info) && info.getRoleId().longValue() != roleId.longValue()) | |||
| { | |||
| if (StringUtils.isNotNull(info) && info.getRoleId().longValue() != roleId.longValue()) { | |||
| return UserConstants.NOT_UNIQUE; | |||
| } | |||
| return UserConstants.UNIQUE; | |||
| @@ -159,17 +147,15 @@ public class SysRoleServiceImpl implements ISysRoleService | |||
| /** | |||
| * 校验角色权限是否唯一 | |||
| * | |||
| * | |||
| * @param role 角色信息 | |||
| * @return 结果 | |||
| */ | |||
| @Override | |||
| public boolean checkRoleKeyUnique(SysRole role) | |||
| { | |||
| public boolean checkRoleKeyUnique(SysRole role) { | |||
| Long roleId = StringUtils.isNull(role.getRoleId()) ? -1L : role.getRoleId(); | |||
| SysRole info = roleMapper.checkRoleKeyUnique(role.getRoleKey()); | |||
| if (StringUtils.isNotNull(info) && info.getRoleId().longValue() != roleId.longValue()) | |||
| { | |||
| if (StringUtils.isNotNull(info) && info.getRoleId().longValue() != roleId.longValue()) { | |||
| return UserConstants.NOT_UNIQUE; | |||
| } | |||
| return UserConstants.UNIQUE; | |||
| @@ -177,61 +163,68 @@ public class SysRoleServiceImpl implements ISysRoleService | |||
| /** | |||
| * 校验角色是否允许操作 | |||
| * | |||
| * | |||
| * @param role 角色信息 | |||
| */ | |||
| @Override | |||
| public void checkRoleAllowed(SysRole role) | |||
| { | |||
| public void checkRoleAllowed(SysRole role) { | |||
| Set<String> roles = SecurityUtils.getLoginUser().getRoles(); | |||
| if (StringUtils.isNotNull(role.getRoleId()) && role.isAdmin() && !roles.contains("admin")) | |||
| { | |||
| if (StringUtils.isNotNull(role.getRoleId()) && role.isAdmin() && !roles.contains(Constant.Admin)) { | |||
| throw new ServiceException("不允许操作超级管理员角色"); | |||
| } | |||
| } | |||
| /** | |||
| * 校验角色是否有数据权限 | |||
| * | |||
| * | |||
| * @param roleId 角色id | |||
| */ | |||
| @Override | |||
| public void checkRoleDataScope(Long roleId) | |||
| { | |||
| if (!SysUser.isAdmin(SecurityUtils.getUserId())) | |||
| { | |||
| public void checkRoleDataScope(Long roleId) { | |||
| if (!checkIsAdmin()) { | |||
| SysRole role = new SysRole(); | |||
| role.setRoleId(roleId); | |||
| List<SysRole> roles = SpringUtils.getAopProxy(this).selectRoleList(role); | |||
| if (StringUtils.isEmpty(roles)) | |||
| { | |||
| if (StringUtils.isEmpty(roles)) { | |||
| throw new ServiceException("没有权限访问角色数据!"); | |||
| } | |||
| } | |||
| } | |||
| public Boolean checkIsAdmin() { | |||
| return SecurityUtils.getLoginUser().getRoles().contains(Constant.Admin); | |||
| } | |||
| public Boolean checkIsAdmin(Long userId) { | |||
| List<SysRole> sysRoles = roleMapper.selectRolePermissionByUserId(userId); | |||
| for (SysRole role : sysRoles) { | |||
| if (role.isAdmin()) { | |||
| return true; | |||
| } | |||
| } | |||
| return false; | |||
| } | |||
| /** | |||
| * 通过角色ID查询角色使用数量 | |||
| * | |||
| * | |||
| * @param roleId 角色ID | |||
| * @return 结果 | |||
| */ | |||
| @Override | |||
| public int countUserRoleByRoleId(Long roleId) | |||
| { | |||
| public int countUserRoleByRoleId(Long roleId) { | |||
| return userRoleMapper.countUserRoleByRoleId(roleId); | |||
| } | |||
| /** | |||
| * 新增保存角色信息 | |||
| * | |||
| * | |||
| * @param role 角色信息 | |||
| * @return 结果 | |||
| */ | |||
| @Override | |||
| @Transactional(rollbackFor = Exception.class) | |||
| public int insertRole(SysRole role) | |||
| { | |||
| public int insertRole(SysRole role) { | |||
| // 新增角色信息 | |||
| roleMapper.insertRole(role); | |||
| return insertRoleMenu(role); | |||
| @@ -239,14 +232,13 @@ public class SysRoleServiceImpl implements ISysRoleService | |||
| /** | |||
| * 修改保存角色信息 | |||
| * | |||
| * | |||
| * @param role 角色信息 | |||
| * @return 结果 | |||
| */ | |||
| @Override | |||
| @Transactional(rollbackFor = Exception.class) | |||
| public int updateRole(SysRole role) | |||
| { | |||
| public int updateRole(SysRole role) { | |||
| // 修改角色信息 | |||
| roleMapper.updateRole(role); | |||
| // 删除角色与菜单关联 | |||
| @@ -256,26 +248,24 @@ public class SysRoleServiceImpl implements ISysRoleService | |||
| /** | |||
| * 修改角色状态 | |||
| * | |||
| * | |||
| * @param role 角色信息 | |||
| * @return 结果 | |||
| */ | |||
| @Override | |||
| public int updateRoleStatus(SysRole role) | |||
| { | |||
| public int updateRoleStatus(SysRole role) { | |||
| return roleMapper.updateRole(role); | |||
| } | |||
| /** | |||
| * 修改数据权限信息 | |||
| * | |||
| * | |||
| * @param role 角色信息 | |||
| * @return 结果 | |||
| */ | |||
| @Override | |||
| @Transactional(rollbackFor = Exception.class) | |||
| public int authDataScope(SysRole role) | |||
| { | |||
| public int authDataScope(SysRole role) { | |||
| // 修改角色信息 | |||
| roleMapper.updateRole(role); | |||
| // 删除角色与部门关联 | |||
| @@ -286,23 +276,20 @@ public class SysRoleServiceImpl implements ISysRoleService | |||
| /** | |||
| * 新增角色菜单信息 | |||
| * | |||
| * | |||
| * @param role 角色对象 | |||
| */ | |||
| public int insertRoleMenu(SysRole role) | |||
| { | |||
| public int insertRoleMenu(SysRole role) { | |||
| int rows = 1; | |||
| // 新增用户与角色管理 | |||
| List<SysRoleMenu> list = new ArrayList<SysRoleMenu>(); | |||
| for (Long menuId : role.getMenuIds()) | |||
| { | |||
| for (Long menuId : role.getMenuIds()) { | |||
| SysRoleMenu rm = new SysRoleMenu(); | |||
| rm.setRoleId(role.getRoleId()); | |||
| rm.setMenuId(menuId); | |||
| list.add(rm); | |||
| } | |||
| if (list.size() > 0) | |||
| { | |||
| if (list.size() > 0) { | |||
| rows = roleMenuMapper.batchRoleMenu(list); | |||
| } | |||
| return rows; | |||
| @@ -313,20 +300,17 @@ public class SysRoleServiceImpl implements ISysRoleService | |||
| * | |||
| * @param role 角色对象 | |||
| */ | |||
| public int insertRoleDept(SysRole role) | |||
| { | |||
| public int insertRoleDept(SysRole role) { | |||
| int rows = 1; | |||
| // 新增角色与部门(数据权限)管理 | |||
| List<SysRoleDept> list = new ArrayList<SysRoleDept>(); | |||
| for (Long deptId : role.getDeptIds()) | |||
| { | |||
| for (Long deptId : role.getDeptIds()) { | |||
| SysRoleDept rd = new SysRoleDept(); | |||
| rd.setRoleId(role.getRoleId()); | |||
| rd.setDeptId(deptId); | |||
| list.add(rd); | |||
| } | |||
| if (list.size() > 0) | |||
| { | |||
| if (list.size() > 0) { | |||
| rows = roleDeptMapper.batchRoleDept(list); | |||
| } | |||
| return rows; | |||
| @@ -334,14 +318,13 @@ public class SysRoleServiceImpl implements ISysRoleService | |||
| /** | |||
| * 通过角色ID删除角色 | |||
| * | |||
| * | |||
| * @param roleId 角色ID | |||
| * @return 结果 | |||
| */ | |||
| @Override | |||
| @Transactional(rollbackFor = Exception.class) | |||
| public int deleteRoleById(Long roleId) | |||
| { | |||
| public int deleteRoleById(Long roleId) { | |||
| // 删除角色与菜单关联 | |||
| roleMenuMapper.deleteRoleMenuByRoleId(roleId); | |||
| // 删除角色与部门关联 | |||
| @@ -351,21 +334,18 @@ public class SysRoleServiceImpl implements ISysRoleService | |||
| /** | |||
| * 批量删除角色信息 | |||
| * | |||
| * | |||
| * @param roleIds 需要删除的角色ID | |||
| * @return 结果 | |||
| */ | |||
| @Override | |||
| @Transactional(rollbackFor = Exception.class) | |||
| public int deleteRoleByIds(Long[] roleIds) | |||
| { | |||
| for (Long roleId : roleIds) | |||
| { | |||
| public int deleteRoleByIds(Long[] roleIds) { | |||
| for (Long roleId : roleIds) { | |||
| checkRoleAllowed(new SysRole(roleId)); | |||
| checkRoleDataScope(roleId); | |||
| SysRole role = selectRoleById(roleId); | |||
| if (countUserRoleByRoleId(roleId) > 0) | |||
| { | |||
| if (countUserRoleByRoleId(roleId) > 0) { | |||
| throw new ServiceException(String.format("%1$s已分配,不能删除", role.getRoleName())); | |||
| } | |||
| } | |||
| @@ -378,43 +358,39 @@ public class SysRoleServiceImpl implements ISysRoleService | |||
| /** | |||
| * 取消授权用户角色 | |||
| * | |||
| * | |||
| * @param userRole 用户和角色关联信息 | |||
| * @return 结果 | |||
| */ | |||
| @Override | |||
| public int deleteAuthUser(SysUserRole userRole) | |||
| { | |||
| public int deleteAuthUser(SysUserRole userRole) { | |||
| return userRoleMapper.deleteUserRoleInfo(userRole); | |||
| } | |||
| /** | |||
| * 批量取消授权用户角色 | |||
| * | |||
| * @param roleId 角色ID | |||
| * | |||
| * @param roleId 角色ID | |||
| * @param userIds 需要取消授权的用户数据ID | |||
| * @return 结果 | |||
| */ | |||
| @Override | |||
| public int deleteAuthUsers(Long roleId, Long[] userIds) | |||
| { | |||
| public int deleteAuthUsers(Long roleId, Long[] userIds) { | |||
| return userRoleMapper.deleteUserRoleInfos(roleId, userIds); | |||
| } | |||
| /** | |||
| * 批量选择授权用户角色 | |||
| * | |||
| * @param roleId 角色ID | |||
| * | |||
| * @param roleId 角色ID | |||
| * @param userIds 需要授权的用户数据ID | |||
| * @return 结果 | |||
| */ | |||
| @Override | |||
| public int insertAuthUsers(Long roleId, Long[] userIds) | |||
| { | |||
| public int insertAuthUsers(Long roleId, Long[] userIds) { | |||
| // 新增用户与角色管理 | |||
| List<SysUserRole> list = new ArrayList<SysUserRole>(); | |||
| for (Long userId : userIds) | |||
| { | |||
| for (Long userId : userIds) { | |||
| SysUserRole ur = new SysUserRole(); | |||
| ur.setUserId(userId); | |||
| ur.setRoleId(roleId); | |||
| @@ -20,6 +20,7 @@ import com.ruoyi.system.domain.SysUserPost; | |||
| import com.ruoyi.system.domain.SysUserRole; | |||
| import com.ruoyi.system.mapper.*; | |||
| import com.ruoyi.system.service.ISysConfigService; | |||
| import com.ruoyi.system.service.ISysRoleService; | |||
| import com.ruoyi.system.service.ISysUserService; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| @@ -74,6 +75,9 @@ public class SysUserServiceImpl implements ISysUserService { | |||
| @Autowired | |||
| private TokenService tokenService; | |||
| @Autowired | |||
| private ISysRoleService roleService; | |||
| /** | |||
| * 根据条件分页查询用户列表 | |||
| * | |||
| @@ -217,7 +221,7 @@ public class SysUserServiceImpl implements ISysUserService { | |||
| */ | |||
| @Override | |||
| public void checkUserAllowed(SysUser user) { | |||
| if (StringUtils.isNotNull(user.getUserId()) && user.isAdmin() && !SecurityUtils.getUserId().equals(user.getUserId())) { | |||
| if (StringUtils.isNotNull(user.getUserId()) && roleService.checkIsAdmin() && !SecurityUtils.getUserId().equals(user.getUserId())) { | |||
| throw new ServiceException("不允许操作超级管理员用户"); | |||
| } | |||
| } | |||
| @@ -229,7 +233,7 @@ public class SysUserServiceImpl implements ISysUserService { | |||
| */ | |||
| @Override | |||
| public void checkUserDataScope(Long userId) { | |||
| if (!SysUser.isAdmin(SecurityUtils.getUserId())) { | |||
| if (!roleService.checkIsAdmin()) { | |||
| SysUser user = new SysUser(); | |||
| user.setUserId(userId); | |||
| List<SysUser> users = SpringUtils.getAopProxy(this).selectUserList(user); | |||