Просмотр исходного кода

fix 修复 错误修改导致页面逻辑错误

疯狂的狮子Li 1 год назад
Родитель
Сommit
7147f81b42

+ 24 - 24
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysRoleServiceImpl.java

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