Quellcode durchsuchen

分配菜单展示

黄远 vor 4 Jahren
Ursprung
Commit
7129c16d22

+ 41 - 4
lift-system-service/src/main/java/cn/com/ty/lift/system/user/service/impl/MenuService.java

@@ -159,14 +159,19 @@ public class MenuService extends ServiceImpl<MenuMapper, Menu> implements IMenuS
         List<CompanyMenu> needDeleteCompanyMenuList = companyMenuService.list(new QueryWrapper<CompanyMenu>()
                 .eq("company_id", companyId)
         );
-        List<Long> companyMenuIds = ProjectUtils.getAttrList(needDeleteCompanyMenuList, "id", null);
-        if (companyMenuIds.size() > 0) {
-            if (!companyMenuService.removeByIds(companyMenuIds)) {
-                return RestResponse.fail(ApiConstants.RESULT_ERROR, "删除公司菜单关联关系失败");
+        if (needDeleteCompanyMenuList != null && needDeleteCompanyMenuList.size() > 0) {
+            List<Long> companyMenuIds = needDeleteCompanyMenuList.stream().map(CompanyMenu::getMenuId).
+                    collect(Collectors.toList());
+            if (companyMenuIds.size() > 0) {
+                if (!companyMenuService.removeByIds(companyMenuIds)) {
+                    return RestResponse.fail(ApiConstants.RESULT_ERROR, "删除公司菜单关联关系失败");
+                }
             }
         }
         //获取菜单id列表
         List<Long> menuIdList = ProjectUtils.getLongIdFromIds(menuRequest.getMenuIds());
+        //获取菜单下的所有按钮
+        menuIdList = getAllMenuButtonIds(menuIdList);
         List<CompanyMenu> needSaveCompanyMenuList = new ArrayList<>();
         if (menuIdList.size() > 0) {
             for (Long menuId : menuIdList) {
@@ -186,6 +191,38 @@ public class MenuService extends ServiceImpl<MenuMapper, Menu> implements IMenuS
         return null;
     }
 
+    /**
+     * @param menuIdList 菜单id
+     * @return 所有菜单id
+     * @methodName getAllMenuButtonIds
+     * @Desc 获取所有菜单id
+     * @Author huangyuan
+     * @Date 2020/7/7 12:16 下午
+     */
+    private List<Long> getAllMenuButtonIds(List<Long> menuIdList) {
+        if (menuIdList != null && menuIdList.size() > 0) {
+            List<Menu> menuList = (List<Menu>) this.listByIds(menuIdList);
+            //获取二级菜单
+            List<Menu> secondMenuList = menuList.stream().filter(menu -> !ApiConstants.ROOT_MENU_PARENT_ID.
+                    equals(menu.getParentId())).collect(Collectors.toList());
+            if (secondMenuList.size() > 0) {
+                List<Long> secondMenuIdList = secondMenuList.stream().map(menu -> Long.
+                        parseLong(menu.getId().toString())).collect(Collectors.toList());
+                //获取二级菜单下的按钮
+                List<Menu> buttonList = list(Wrappers.<Menu>query().
+                        in(secondMenuIdList.size() > 0, "parent_id", secondMenuIdList)
+                );
+                if(buttonList != null && buttonList.size() > 0) {
+                    //分配按钮添加
+                    List<Long> buttonIdList = buttonList.stream().map(menu -> Long.
+                            parseLong(menu.getId().toString())).collect(Collectors.toList());
+                    menuIdList.addAll(buttonIdList);
+                }
+            }
+        }
+        return menuIdList;
+    }
+
     @Override
     public List<Menu> getMenuTree(List<Menu> menuList) {
         return TreeUtil.listToTree(menuList, ApiConstants.MENU_PARENT_ATTR, ApiConstants.ROOT_MENU_PARENT_ID, "id");