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 ec919f63..ed24ab4e 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 @@ -1,6 +1,7 @@ package com.ruoyi.system.service.impl; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.ObjectUtil; import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; @@ -402,20 +403,7 @@ public class SysUserServiceImpl implements ISysUserService { * @param user 用户对象 */ public void insertUserRole(SysUser user) { - Long[] roles = user.getRoleIds(); - if (ObjectUtil.isNotNull(roles)) { - // 新增用户与角色管理 - List list = new ArrayList(); - for (Long roleId : roles) { - SysUserRole ur = new SysUserRole(); - ur.setUserId(user.getUserId()); - ur.setRoleId(roleId); - list.add(ur); - } - if (list.size() > 0) { - userRoleMapper.insertBatch(list); - } - } + this.insertUserRole(user.getUserId(), user.getRoleIds()); } /** @@ -425,18 +413,16 @@ public class SysUserServiceImpl implements ISysUserService { */ public void insertUserPost(SysUser user) { Long[] posts = user.getPostIds(); - if (ObjectUtil.isNotNull(posts)) { + if (ArrayUtil.isNotEmpty(posts)) { // 新增用户与岗位管理 - List list = new ArrayList(); + List list = new ArrayList<>(posts.length); for (Long postId : posts) { SysUserPost up = new SysUserPost(); up.setUserId(user.getUserId()); up.setPostId(postId); list.add(up); } - if (list.size() > 0) { - userPostMapper.insertBatch(list); - } + userPostMapper.insertBatch(list); } } @@ -447,18 +433,16 @@ public class SysUserServiceImpl implements ISysUserService { * @param roleIds 角色组 */ public void insertUserRole(Long userId, Long[] roleIds) { - if (ObjectUtil.isNotNull(roleIds)) { + if (ArrayUtil.isNotEmpty(roleIds)) { // 新增用户与角色管理 - List list = new ArrayList(); + List list = new ArrayList<>(roleIds.length); for (Long roleId : roleIds) { SysUserRole ur = new SysUserRole(); ur.setUserId(userId); ur.setRoleId(roleId); list.add(ur); } - if (list.size() > 0) { - userRoleMapper.insertBatch(list); - } + userRoleMapper.insertBatch(list); } }