From d877cf557db5452093087fabb4479a10497ee218 Mon Sep 17 00:00:00 2001
From: zhanzhiqin <895896009@qq.com>
Date: 星期一, 28 二月 2022 18:25:32 +0800
Subject: [PATCH] fix

---
 ximon-admin/src/main/java/com/sandu/ximon/admin/service/RoleService.java |   21 +++++++++++++++------
 1 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/ximon-admin/src/main/java/com/sandu/ximon/admin/service/RoleService.java b/ximon-admin/src/main/java/com/sandu/ximon/admin/service/RoleService.java
index 04f943a..4fb38f6 100644
--- a/ximon-admin/src/main/java/com/sandu/ximon/admin/service/RoleService.java
+++ b/ximon-admin/src/main/java/com/sandu/ximon/admin/service/RoleService.java
@@ -4,6 +4,7 @@
 import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.github.pagehelper.PageHelper;
+import com.sandu.common.enums.RoleLevelStatus;
 import com.sandu.common.execption.BusinessException;
 import com.sandu.common.execption.EntityExistException;
 import com.sandu.common.service.impl.BaseServiceImpl;
@@ -80,10 +81,13 @@
 
     @Transactional(rollbackFor = Exception.class)
     public boolean addRole(RoleParam param) {
+        if(param.getMenuIdList().isEmpty()){
+            throw new BusinessException("鏉冮檺鍙傛暟寮傚父");
+        }
         Role role = new Role();
         role.setName(param.getName());
         role.setRemark(param.getRemark());
-        role.setLevel(2);
+        role.setLevel(RoleLevelStatus.COMMON.getCode());
         if(!save(role)){
             throw new BusinessException("娣诲姞瑙掕壊澶辫触");
         }
@@ -101,6 +105,7 @@
         }
         assertLevels(role.getLevel());
         Role update = new Role();
+        update.setId(roleId);
         update.setName(param.getName());
         update.setRemark(param.getRemark());
         if(!updateById(update)){
@@ -113,8 +118,12 @@
     }
 
 
-
-    private int assertLevels(Integer level) {
+    /**
+     * 鍒ゆ柇褰撳墠瑙掕壊鑳戒笉鑳芥搷浣滅洰鏍囩敤鎴� 涓嶈鐨勮瘽鐩存帴鎶涘嚭寮傚父
+     * @param roleLevel 鐩爣鐢ㄦ埛鐨勬渶楂樿鑹茬瓑绾�
+     * @return 鎿嶄綔浜虹殑鏈�楂樿鑹茬瓑绾�
+     */
+    public int assertLevels(Integer roleLevel) {
         Long userId = SecurityUtils.getUserId();
         List<Role> roles = listByAdminId(userId);
         if(CollectionUtil.isEmpty(roles)){
@@ -122,9 +131,9 @@
         }
         List<Integer> levels = roles.stream().map(Role::getLevel).collect(Collectors.toList());
         int min = Collections.min(levels);
-        if (level != null) {
-            if (level < min) {
-                throw new BusinessException("鏉冮檺涓嶈冻锛屼綘鐨勮鑹茬骇鍒細" + min + "锛屼綆浜庢搷浣滅殑瑙掕壊绾у埆锛�" + level);
+        if (roleLevel != null) {
+            if (roleLevel < min) {
+                throw new BusinessException("鏉冮檺涓嶈冻锛屼綘鐨勮鑹茬骇鍒細" + min + "锛屼綆浜庢搷浣滅殑瑙掕壊绾у埆锛�" + roleLevel);
             }
         }
         return min;

--
Gitblit v1.9.3