From b8a0affd03b5fa9fa33cd6f870e90394c2df86c7 Mon Sep 17 00:00:00 2001 From: 潘志宝 <979469083@qq.com> Date: 星期一, 06 一月 2025 13:31:07 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- iailab-module-system/iailab-module-system-biz/src/main/java/com/iailab/module/system/service/app/AppServiceImpl.java | 109 ++++++++++++++++++++++++++++++------------------------ 1 files changed, 61 insertions(+), 48 deletions(-) diff --git a/iailab-module-system/iailab-module-system-biz/src/main/java/com/iailab/module/system/service/app/AppServiceImpl.java b/iailab-module-system/iailab-module-system-biz/src/main/java/com/iailab/module/system/service/app/AppServiceImpl.java index c090de3..43bcb42 100644 --- a/iailab-module-system/iailab-module-system-biz/src/main/java/com/iailab/module/system/service/app/AppServiceImpl.java +++ b/iailab-module-system/iailab-module-system-biz/src/main/java/com/iailab/module/system/service/app/AppServiceImpl.java @@ -1,5 +1,6 @@ package com.iailab.module.system.service.app; +import cn.hutool.core.collection.CollUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.iailab.framework.common.pojo.PageResult; @@ -7,8 +8,11 @@ import com.iailab.framework.mybatis.core.query.LambdaQueryWrapperX; import com.iailab.framework.security.core.util.SecurityFrameworkUtils; import com.iailab.framework.tenant.core.aop.TenantIgnore; +import com.iailab.module.system.api.app.dto.AppMenuRespDTO; import com.iailab.module.system.controller.admin.app.vo.AppPageReqVO; import com.iailab.module.system.controller.admin.app.vo.AppSaveReqVO; +import com.iailab.module.system.controller.admin.auth.vo.AuthPermissionInfoRespVO; +import com.iailab.module.system.convert.auth.AuthConvert; import com.iailab.module.system.dal.dataobject.app.AppDO; import com.iailab.module.system.dal.dataobject.permission.MenuDO; import com.iailab.module.system.dal.dataobject.permission.RoleDO; @@ -22,8 +26,10 @@ import com.iailab.module.system.dal.mysql.tenant.TenantMapper; import com.iailab.module.system.dal.mysql.tenant.TenantPackageMapper; import com.iailab.module.system.enums.permission.MenuTypeEnum; +import com.iailab.module.system.service.permission.MenuService; import com.iailab.module.system.service.permission.PermissionService; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.ObjectUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -32,6 +38,7 @@ import java.util.*; import static com.iailab.framework.common.exception.util.ServiceExceptionUtil.exception; +import static com.iailab.framework.common.util.collection.CollectionUtils.convertSet; import static com.iailab.framework.tenant.core.context.TenantContextHolder.getTenantId; import static com.iailab.module.system.enums.ErrorCodeConstants.MENU_EXISTS_CHILDREN; import static com.iailab.module.system.enums.ErrorCodeConstants.MENU_NOT_EXISTS; @@ -65,6 +72,9 @@ @Resource private TenantMapper tenantMapper; + + @Resource + private MenuService menuService; @Override @@ -124,13 +134,7 @@ //查询系统应用菜单 // List<MenuDO> menuDOS = menuMapper.selectList(menuDOLambdaQueryWrapperX); // List<AppDO> systemApps = convertMenuToApp(menuDOS); - //创建一个系统管理应用菜单 - AppDO aDo = new AppDO(); - aDo.setAppType(1); - aDo.setAppName("系统管理"); - aDo.setOrderNum(0); List<AppDO> systemApps = new ArrayList<>(); - systemApps.add(aDo); List<AppDO> appDOS = appMapper.selectList(); //暂时先遍历处理应用菜单和应用类型 appDOS.stream().forEach(appDO -> { @@ -147,7 +151,7 @@ public AppDO getAppByTenantId(Long tenantId) { //暂时支持一个租户对应一个应用 List<AppDO> appDOS = appMapper.selectList(new LambdaQueryWrapper<AppDO>().eq(AppDO::getTenantId, tenantId)); - if(ObjectUtils.isNotEmpty(appDOS)) { + if(CollectionUtils.isNotEmpty(appDOS)) { return appDOS.get(0); } else { AppDO appDO = new AppDO(); @@ -157,27 +161,27 @@ } } -// @Override -// public List<MenuRespDTO> getAppMenu(Long id) { -// -// List<MenuDO> children = new LinkedList<>(); -// // 遍历每一层 -// Collection<Long> parentIds = Collections.singleton(id); -// for (int i = 0; i < Short.MAX_VALUE; i++) { // 使用 Short.MAX_VALUE 避免 bug 场景下,存在死循环 -// // 查询当前层,所有的子应用菜单 -// List<MenuDO> menus = menuMapper.selectListByParentId(parentIds); -// // 1. 如果没有子菜单,则结束遍历 -// if (CollUtil.isEmpty(menus)) { -// break; -// } -// // 2. 如果有子应用菜单,继续遍历 -// children.addAll(menus); -// parentIds = convertSet(menus, MenuDO::getId); -// } -// children = menuService.filterDisableMenus(children); -// return AuthConvert.INSTANCE.buildMenuTree(id, children); -// -// } + @Override + public List<AuthPermissionInfoRespVO.MenuVO> getAppMenu(Long id) { + MenuDO menuDO = menuMapper.selectById(id); + List<MenuDO> children = new LinkedList<>(); + // 遍历每一层 + Collection<Long> parentIds = Collections.singleton(id); + for (int i = 0; i < Short.MAX_VALUE; i++) { // 使用 Short.MAX_VALUE 避免 bug 场景下,存在死循环 + // 查询当前层,所有的子应用菜单 + List<MenuDO> menus = menuMapper.selectListByParentId(parentIds); + // 1. 如果没有子菜单,则结束遍历 + if (CollUtil.isEmpty(menus)) { + break; + } + // 2. 如果有子应用菜单,继续遍历 + children.addAll(menus); + parentIds = convertSet(menus, MenuDO::getId); + } + children = menuService.filterDisableMenus(children); + return AuthConvert.INSTANCE.buildMenuTree(children, id, menuDO.getPath()); + + } private void dealAppMenu(Integer type, AppDO app){ String loginUserNickname = SecurityFrameworkUtils.getLoginUserNickname(); @@ -191,9 +195,10 @@ if(type == 1){ menuDO.setCreator(loginUserNickname); menuDO.setCreateTime(app.getCreateTime()); + menuDO.setIcon("fa-solid:border-none"); //默认icon menuMapper.insert(menuDO); - //内置租户角色分配菜单 - assignRoleMenu(menuDO.getId(), app.getTenantId()); +// //内置租户角色分配菜单 +// assignRoleMenu(menuDO.getId(), app.getTenantId()); } else if(type == 2){ LambdaUpdateWrapper<MenuDO> updateWrapper = new LambdaUpdateWrapper<>(); updateWrapper.eq(MenuDO::getAppId, app.getId()); @@ -207,8 +212,8 @@ menuDO.setCreator(loginUserNickname); menuDO.setCreateTime(app.getCreateTime()); menuMapper.insert(menuDO); - //内置租户角色分配菜单 - assignRoleMenu(menuDO.getId(), app.getTenantId()); +// //内置租户角色分配菜单 +// assignRoleMenu(menuDO.getId(), app.getTenantId()); } } else if(type == 3){ //删除租户、角色权限 @@ -216,25 +221,28 @@ LambdaQueryWrapperX<MenuDO> menuWrapper = new LambdaQueryWrapperX<>(); menuWrapper.eq(MenuDO::getAppId, app.getId()); menuWrapper.eq(MenuDO::getType, MenuTypeEnum.DIR.getType()); + menuWrapper.eq(MenuDO::getParentId, 0); MenuDO menu = menuMapper.selectOne(menuWrapper); TenantDO tenantDO = tenantMapper.selectById(app.getTenantId()); - TenantPackageDO tenantPackageDO = tenantPackageMapper.selectById(tenantDO.getPackageId()); - Set<Long> menuIds = tenantPackageDO.getMenuIds(); - menuIds.remove(menu.getId()); - // 校验是否还有子菜单 - if (menuMapper.selectCountByParentId(menu.getId()) > 0) { - throw exception(MENU_EXISTS_CHILDREN); + if(ObjectUtils.isNotEmpty(menu) && ObjectUtils.isNotEmpty(tenantDO)) { + TenantPackageDO tenantPackageDO = tenantPackageMapper.selectById(tenantDO.getPackageId()); + Set<Long> menuIds = tenantPackageDO.getMenuIds(); + menuIds.remove(menu.getId()); + // 校验是否还有子菜单 + if (menuMapper.selectCountByParentId(menu.getId()) > 0) { + throw exception(MENU_EXISTS_CHILDREN); + } + // 校验删除的菜单是否存在 + if (menuMapper.selectById(menu.getId()) == null) { + throw exception(MENU_NOT_EXISTS); + } + // 标记删除 + menuMapper.deleteById(menu.getId()); + // 删除授予给角色的权限 + permissionService.processMenuDeleted(menu.getId()); + //删除菜单 + menuMapper.delete(menuWrapper); } - // 校验删除的菜单是否存在 - if (menuMapper.selectById(menu.getId()) == null) { - throw exception(MENU_NOT_EXISTS); - } - // 标记删除 - menuMapper.deleteById(menu.getId()); - // 删除授予给角色的权限 - permissionService.processMenuDeleted(menu.getId()); - //删除菜单 - menuMapper.delete(menuWrapper); } } @@ -269,4 +277,9 @@ return appDOS; } + public List<AppDO> selectBatchIds(List<Long> ids) { + List<AppDO> appDOS = appMapper.selectBatchIds(ids); + return appDOS; + } + } \ No newline at end of file -- Gitblit v1.9.3