diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java index fcc9033..677f711 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java @@ -381,23 +381,7 @@ public class SysUserServiceImpl implements ISysUserService */ public void insertUserRole(SysUser user) { - Long[] roles = user.getRoleIds(); - if (StringUtils.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.batchUserRole(list); - } - } + this.insertUserRole(user.getUserId, user.getRoleIds()); } /** @@ -408,7 +392,7 @@ public class SysUserServiceImpl implements ISysUserService public void insertUserPost(SysUser user) { Long[] posts = user.getPostIds(); - if (StringUtils.isNotNull(posts)) + if (StringUtils.isNotEmpty(posts)) { // 新增用户与岗位管理 List list = new ArrayList(); @@ -419,10 +403,7 @@ public class SysUserServiceImpl implements ISysUserService up.setPostId(postId); list.add(up); } - if (list.size() > 0) - { - userPostMapper.batchUserPost(list); - } + userPostMapper.batchUserPost(list); } } @@ -434,7 +415,7 @@ public class SysUserServiceImpl implements ISysUserService */ public void insertUserRole(Long userId, Long[] roleIds) { - if (StringUtils.isNotNull(roleIds)) + if (StringUtils.isNotEmpty(roleIds)) { // 新增用户与角色管理 List list = new ArrayList(); @@ -445,10 +426,7 @@ public class SysUserServiceImpl implements ISysUserService ur.setRoleId(roleId); list.add(ur); } - if (list.size() > 0) - { - userRoleMapper.batchUserRole(list); - } + userRoleMapper.batchUserRole(list); } }