Explorar o código

权限菜单bug

shiqian %!s(int64=4) %!d(string=hai) anos
pai
achega
8481f8c965

+ 29 - 14
boman-modules/boman-system/src/main/java/com/boman/system/service/impl/SysRoleMenuServiceImpl.java

@@ -1,5 +1,6 @@
 package com.boman.system.service.impl;
 
+import com.boman.common.core.utils.aop.ProxyUtils;
 import com.boman.common.core.utils.collection.CollectionUtils;
 import com.boman.domain.constant.TableNameConst;
 import com.boman.domain.dto.RoleMenuDto;
@@ -11,6 +12,7 @@ import com.boman.web.core.api.RemoteObjService;
 import com.google.common.collect.Lists;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.aop.framework.AopContext;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Isolation;
 import org.springframework.transaction.annotation.Transactional;
@@ -60,8 +62,6 @@ public class SysRoleMenuServiceImpl implements ISysRoleMenuService{
             // 此方法只找到menu的祖宗十八代,但是不包含自己
             menuService.recGetParent(allMenus, Collections.singletonList(menu), parentList);
             parentList.add(menu);
-
-            List<String> head = requireNonNull(dto.getHead(), "操作为空");
             List<SysMenu> childList = menuService.getChildList(allMenus, menu);
             if (isEmpty(childList)) {
                 return 0;
@@ -71,18 +71,33 @@ public class SysRoleMenuServiceImpl implements ISysRoleMenuService{
             List<SysMenu> originChildList = Lists.newArrayList(childList);
             // 把parentList放进去
             childList.addAll(parentList);
-            // 根据子菜单和前台传过来的head来判断包含AMD...中的哪些
-            childList = buildBtnByHead(head, childList);
-            List<Long> childIdList = map(childList, SysMenu::getId);
-            List<SysRoleMenu> roleMenuList = buildRoleMenu(roleId, childIdList);
-            List<Long> distinct = CollectionUtils.addAllDistinct(childIdList, map(originChildList, SysMenu::getId));
-            try {
-                // 先删除,再添加,防止联合索引报错
-                deleteByRoleIdList(Collections.singletonList(roleId), distinct);
-                effective += batchRoleMenu(roleMenuList);
-            } catch (Exception e) {
-                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
-                e.printStackTrace();
+
+            ISysRoleMenuService proxyService = ProxyUtils.proxy();
+            List<String> head = dto.getHead();
+            List<Long> menuIdList;
+            List<SysRoleMenu> roleMenuList;
+            if (isNotEmpty(head)) {
+                // 根据子菜单和前台传过来的head来判断包含AMD...中的哪些
+                childList = buildBtnByHead(head, childList);
+                List<Long> childIdList = map(childList, SysMenu::getId);
+                roleMenuList = buildRoleMenu(roleId, childIdList);
+                menuIdList = CollectionUtils.addAllDistinct(childIdList, map(originChildList, SysMenu::getId));
+                try {
+                    // 先删除,再添加,防止联合索引报错
+                    proxyService.deleteByRoleIdList(Collections.singletonList(roleId), menuIdList);
+                    effective += proxyService.batchRoleMenu(roleMenuList);
+                } catch (Exception e) {
+                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+                    e.printStackTrace();
+                }
+            } else {
+                try {
+                    // 先删除,再添加,防止联合索引报错
+                    proxyService.deleteByRoleIdList(Collections.singletonList(roleId), map(childList, SysMenu::getId));
+                } catch (Exception e) {
+                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+                    e.printStackTrace();
+                }
             }
         }