update 优化新增角色信息
This commit is contained in:
parent
d02bea85cb
commit
0ddba506bf
@ -4,6 +4,7 @@ import cn.dev33.satoken.exception.NotLoginException;
|
|||||||
import cn.dev33.satoken.stp.StpUtil;
|
import cn.dev33.satoken.stp.StpUtil;
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
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;
|
||||||
@ -39,6 +40,7 @@ import org.springframework.stereotype.Service;
|
|||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 角色 业务层处理
|
* 角色 业务层处理
|
||||||
@ -355,19 +357,18 @@ public class SysRoleServiceImpl implements ISysRoleService, RoleService {
|
|||||||
* @param role 角色对象
|
* @param role 角色对象
|
||||||
*/
|
*/
|
||||||
private int insertRoleMenu(SysRoleBo role) {
|
private int insertRoleMenu(SysRoleBo role) {
|
||||||
int rows = 1;
|
Long[] menuIds = role.getMenuIds();
|
||||||
// 新增用户与角色管理
|
if (ArrayUtil.isEmpty(menuIds)) {
|
||||||
List<SysRoleMenu> list = new ArrayList<>();
|
return 0;
|
||||||
for (Long menuId : role.getMenuIds()) {
|
|
||||||
SysRoleMenu rm = new SysRoleMenu();
|
|
||||||
rm.setRoleId(role.getRoleId());
|
|
||||||
rm.setMenuId(menuId);
|
|
||||||
list.add(rm);
|
|
||||||
}
|
}
|
||||||
if (CollUtil.isEmpty(list)) {
|
List<SysRoleMenu> roleMenuList = Arrays.stream(menuIds)
|
||||||
rows = roleMenuMapper.insertBatch(list) ? list.size() : 0;
|
.map(menuId -> {
|
||||||
}
|
SysRoleMenu roleMenu = new SysRoleMenu();
|
||||||
return rows;
|
roleMenu.setRoleId(role.getRoleId());
|
||||||
|
roleMenu.setMenuId(menuId);
|
||||||
|
return roleMenu;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
return roleMenuMapper.insertBatch(roleMenuList) ? roleMenuList.size() : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -376,19 +377,18 @@ public class SysRoleServiceImpl implements ISysRoleService, RoleService {
|
|||||||
* @param role 角色对象
|
* @param role 角色对象
|
||||||
*/
|
*/
|
||||||
private int insertRoleDept(SysRoleBo role) {
|
private int insertRoleDept(SysRoleBo role) {
|
||||||
int rows = 1;
|
Long[] deptIds = role.getDeptIds();
|
||||||
// 新增角色与部门(数据权限)管理
|
if (ArrayUtil.isEmpty(deptIds)) {
|
||||||
List<SysRoleDept> list = new ArrayList<>();
|
return 0;
|
||||||
for (Long deptId : role.getDeptIds()) {
|
|
||||||
SysRoleDept rd = new SysRoleDept();
|
|
||||||
rd.setRoleId(role.getRoleId());
|
|
||||||
rd.setDeptId(deptId);
|
|
||||||
list.add(rd);
|
|
||||||
}
|
}
|
||||||
if (CollUtil.isEmpty(list)) {
|
List<SysRoleDept> roleDeptList = Arrays.stream(deptIds)
|
||||||
rows = roleDeptMapper.insertBatch(list) ? list.size() : 0;
|
.map(deptId -> {
|
||||||
}
|
SysRoleDept roleDept = new SysRoleDept();
|
||||||
return rows;
|
roleDept.setRoleId(role.getRoleId());
|
||||||
|
roleDept.setDeptId(deptId);
|
||||||
|
return roleDept;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
return roleDeptMapper.insertBatch(roleDeptList) ? roleDeptList.size() : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user