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