diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysRoleController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysRoleController.java index 5768806c2..00a8a008b 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysRoleController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysRoleController.java @@ -112,7 +112,7 @@ public class SysRoleController extends BaseController { // 更新缓存用户权限 LoginUser loginUser = getLoginUser(); SysUser sysUser = userService.selectUserById(loginUser.getUserId()); - if (ObjectUtil.isNotNull(sysUser) && !sysUser.isAdmin()) { + if (ObjectUtil.isNotNull(sysUser) && !LoginHelper.isAdmin()) { loginUser.setMenuPermission(permissionService.getMenuPermission(sysUser)); LoginHelper.setLoginUser(loginUser); } diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/helper/LoginHelper.java b/ruoyi-common/src/main/java/com/ruoyi/common/helper/LoginHelper.java index 05e370b5d..cee0e93ae 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/helper/LoginHelper.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/helper/LoginHelper.java @@ -2,7 +2,6 @@ package com.ruoyi.common.helper; import cn.dev33.satoken.context.SaHolder; import cn.dev33.satoken.stp.StpUtil; -import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.ObjectUtil; import com.ruoyi.common.constant.UserConstants; import com.ruoyi.common.core.domain.model.LoginUser; @@ -15,11 +14,11 @@ import lombok.NoArgsConstructor; /** * 登录鉴权助手 - * + *

* user_type 为 用户类型 同一个用户表 可以有多种用户类型 例如 pc,app * deivce 为 设备类型 同一个用户类型 可以有 多种设备类型 例如 web,ios * 可以组成 用户类型与设备类型多对多的 权限灵活控制 - * + *

* 多用户体系 针对 多种用户类型 但权限控制不一致 * 可以组成 多用户类型表与多设备类型 分别控制权限 * diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/SysPermissionService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/SysPermissionService.java index 97ff4801a..79d6e2522 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/SysPermissionService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/SysPermissionService.java @@ -1,5 +1,6 @@ package com.ruoyi.system.service; +import cn.hutool.core.collection.CollUtil; import com.ruoyi.common.core.domain.entity.SysRole; import com.ruoyi.common.core.domain.entity.SysUser; import lombok.RequiredArgsConstructor; @@ -28,7 +29,7 @@ public class SysPermissionService { * @return 角色权限信息 */ public Set getRolePermission(SysUser user) { - Set roles = new HashSet(); + Set roles = new HashSet<>(); // 管理员拥有所有权限 if (user.isAdmin()) { roles.add("admin"); @@ -45,13 +46,13 @@ public class SysPermissionService { * @return 菜单权限信息 */ public Set getMenuPermission(SysUser user) { - Set perms = new HashSet(); + Set perms = new HashSet<>(); // 管理员拥有所有权限 if (user.isAdmin()) { perms.add("*:*:*"); } else { List roles = user.getRoles(); - if (!roles.isEmpty() && roles.size() > 1) { + if (CollUtil.isNotEmpty(roles)) { // 多角色设置permissions属性,以便数据权限匹配权限 for (SysRole role : roles) { Set rolePerms = menuService.selectMenuPermsByRoleId(role.getRoleId()); diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysConfigServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysConfigServiceImpl.java index c39ec74df..c77612e72 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysConfigServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysConfigServiceImpl.java @@ -205,9 +205,9 @@ public class SysConfigServiceImpl implements ISysConfigService, ConfigService { */ @Override public String checkConfigKeyUnique(SysConfig config) { - Long configId = ObjectUtil.isNull(config.getConfigId()) ? -1L : config.getConfigId(); + long configId = ObjectUtil.isNull(config.getConfigId()) ? -1L : config.getConfigId(); SysConfig info = baseMapper.selectOne(new LambdaQueryWrapper().eq(SysConfig::getConfigKey, config.getConfigKey())); - if (ObjectUtil.isNotNull(info) && info.getConfigId().longValue() != configId.longValue()) { + if (ObjectUtil.isNotNull(info) && info.getConfigId() != configId) { return UserConstants.NOT_UNIQUE; } return UserConstants.UNIQUE; diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java index 00b402467..afb7a3155 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java @@ -259,7 +259,7 @@ public class SysDeptServiceImpl implements ISysDeptService { dept.setAncestors(child.getAncestors().replaceFirst(oldAncestors, newAncestors)); list.add(dept); } - if (list.size() > 0) { + if (CollUtil.isNotEmpty(list)) { baseMapper.updateBatchById(list); } } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysMenuServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysMenuServiceImpl.java index 4d3406757..4056d5670 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysMenuServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysMenuServiceImpl.java @@ -153,7 +153,7 @@ public class SysMenuServiceImpl implements ISysMenuService { */ @Override public List buildMenus(List menus) { - List routers = new LinkedList(); + List routers = new LinkedList<>(); for (SysMenu menu : menus) { RouterVo router = new RouterVo(); router.setHidden("1".equals(menu.getVisible())); @@ -169,7 +169,7 @@ public class SysMenuServiceImpl implements ISysMenuService { router.setChildren(buildMenus(cMenus)); } else if (isMenuFrame(menu)) { router.setMeta(null); - List childrenList = new ArrayList(); + List childrenList = new ArrayList<>(); RouterVo children = new RouterVo(); children.setPath(menu.getPath()); children.setComponent(menu.getComponent()); @@ -181,7 +181,7 @@ public class SysMenuServiceImpl implements ISysMenuService { } else if (menu.getParentId().intValue() == 0 && isInnerLink(menu)) { router.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon())); router.setPath("/"); - List childrenList = new ArrayList(); + List childrenList = new ArrayList<>(); RouterVo children = new RouterVo(); String routerPath = innerLinkReplaceEach(menu.getPath()); children.setPath(routerPath); @@ -394,7 +394,7 @@ public class SysMenuServiceImpl implements ISysMenuService { * @return String */ public List getChildPerms(List list, int parentId) { - List returnList = new ArrayList(); + List returnList = new ArrayList<>(); for (SysMenu t : list) { // 一、根据传入的某个父节点ID,遍历该父节点的所有子节点 if (t.getParentId() == parentId) { @@ -433,7 +433,7 @@ public class SysMenuServiceImpl implements ISysMenuService { * 判断是否有子节点 */ private boolean hasChild(List list, SysMenu t) { - return getChildList(list, t).size() > 0; + return CollUtil.isNotEmpty(getChildList(list, t)); } /** diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java index e7e5b53c5..9e85bee57 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java @@ -14,6 +14,7 @@ import com.ruoyi.common.core.domain.entity.SysRole; import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.exception.ServiceException; import com.ruoyi.common.helper.LoginHelper; +import com.ruoyi.common.utils.StreamUtils; import com.ruoyi.system.domain.SysRoleDept; import com.ruoyi.system.domain.SysRoleMenu; import com.ruoyi.system.domain.SysUserRole; @@ -397,14 +398,13 @@ public class SysRoleServiceImpl implements ISysRoleService { public int insertAuthUsers(Long roleId, Long[] userIds) { // 新增用户与角色管理 int rows = 1; - List list = new ArrayList(); - for (Long userId : userIds) { + List list = StreamUtils.toList(Arrays.asList(userIds), userId -> { SysUserRole ur = new SysUserRole(); ur.setUserId(userId); ur.setRoleId(roleId); - list.add(ur); - } - if (list.size() > 0) { + return ur; + }); + if (CollUtil.isNotEmpty(list)) { rows = userRoleMapper.insertBatch(list) ? list.size() : 0; } return rows; diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java index 4e63f17ea..862d029d3 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java @@ -30,7 +30,6 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Map; @@ -211,7 +210,6 @@ public class SysUserServiceImpl implements ISysUserService { * 校验手机号码是否唯一 * * @param user 用户信息 - * @return */ @Override public String checkPhoneUnique(SysUser user) { @@ -228,7 +226,6 @@ public class SysUserServiceImpl implements ISysUserService { * 校验email是否唯一 * * @param user 用户信息 - * @return */ @Override public String checkEmailUnique(SysUser user) { @@ -417,13 +414,12 @@ public class SysUserServiceImpl implements ISysUserService { Long[] posts = user.getPostIds(); if (ArrayUtil.isNotEmpty(posts)) { // 新增用户与岗位管理 - List list = new ArrayList<>(posts.length); - for (Long postId : posts) { + List list = StreamUtils.toList(Arrays.asList(posts), postId -> { SysUserPost up = new SysUserPost(); up.setUserId(user.getUserId()); up.setPostId(postId); - list.add(up); - } + return up; + }); userPostMapper.insertBatch(list); } } @@ -437,13 +433,12 @@ public class SysUserServiceImpl implements ISysUserService { public void insertUserRole(Long userId, Long[] roleIds) { if (ArrayUtil.isNotEmpty(roleIds)) { // 新增用户与角色管理 - List list = new ArrayList<>(roleIds.length); - for (Long roleId : roleIds) { + List list = StreamUtils.toList(Arrays.asList(roleIds), roleId -> { SysUserRole ur = new SysUserRole(); ur.setUserId(userId); ur.setRoleId(roleId); - list.add(ur); - } + return ur; + }); userRoleMapper.insertBatch(list); } } diff --git a/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml b/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml index dacdcd8a6..06a653efe 100644 --- a/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml @@ -86,17 +86,17 @@