| | |
| | | import com.mzl.flower.dto.response.system.AppMenuDTO; |
| | | import com.mzl.flower.dto.response.system.AppMenuTreeDTO; |
| | | import com.mzl.flower.entity.system.AppMenu; |
| | | import com.mzl.flower.enums.TrueOrFalseEnum; |
| | | import com.mzl.flower.mapper.system.AppMenuMapper; |
| | | import com.mzl.flower.service.BaseService; |
| | | import com.mzl.flower.utils.TreeBuilderUtil; |
| | |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | | @Transactional |
| | |
| | | public void addMenu(CreateAppMenuDTO dto) { |
| | | AppMenu menu = new AppMenu(); |
| | | // 查找菜单名称是否已经存在 |
| | | if (menuMapper.selectCount(new QueryWrapper<AppMenu>() |
| | | .lambda().eq(AppMenu::getMenuName, dto.getMenuName()) |
| | | .eq(AppMenu::getStatus, Constants.STATUS_ACTIVE) |
| | | ) > 0) { |
| | | throw new ValidationException("菜单名称已经存在"); |
| | | } |
| | | // if (menuMapper.selectCount(new QueryWrapper<AppMenu>() |
| | | // .lambda().eq(AppMenu::getMenuName, dto.getMenuName()) |
| | | // .eq(AppMenu::getStatus, Constants.STATUS_ACTIVE) |
| | | // ) > 0) { |
| | | // throw new ValidationException("菜单名称已经存在"); |
| | | // } |
| | | // 查找权限标识是否已经存在 |
| | | if (menuMapper.selectCount(new QueryWrapper<AppMenu>().lambda().eq(AppMenu::getPermissionUq, dto.getPermissionUq()).eq(AppMenu::getStatus, Constants.STATUS_ACTIVE)) > 0) { |
| | | throw new ValidationException("权限标识已经存在"); |
| | |
| | | if(null==menu){ |
| | | throw new ValidationException("菜单不存在"); |
| | | } |
| | | if (menuMapper.selectCount(new QueryWrapper<AppMenu>().lambda().eq(AppMenu::getMenuName, dto.getMenuName()).eq(AppMenu::getStatus, Constants.STATUS_ACTIVE).ne(AppMenu::getId, menu.getId())) > 0) { |
| | | throw new ValidationException("菜单名称已经存在"); |
| | | } |
| | | // if (menuMapper.selectCount(new QueryWrapper<AppMenu>().lambda().eq(AppMenu::getMenuName, dto.getMenuName()).eq(AppMenu::getStatus, Constants.STATUS_ACTIVE).ne(AppMenu::getId, menu.getId())) > 0) { |
| | | // throw new ValidationException("菜单名称已经存在"); |
| | | // } |
| | | // 查找权限标识是否已经存在 |
| | | if (menuMapper.selectCount(new QueryWrapper<AppMenu>().lambda().eq(AppMenu::getPermissionUq, dto.getPermissionUq()).eq(AppMenu::getStatus, Constants.STATUS_ACTIVE).ne(AppMenu::getId, menu.getId())) > 0) { |
| | | throw new ValidationException("权限标识已经存在"); |
| | |
| | | // 获取供应商菜单信息 |
| | | public List<AppMenu> getPermissionMenu() { |
| | | |
| | | LambdaQueryWrapper<AppMenu> queryWrapper = new QueryWrapper<AppMenu>() |
| | | .lambda() |
| | | .eq(AppMenu::getStatus, Constants.STATUS_ACTIVE) |
| | | .eq(AppMenu::getSubaccountAccessFlag,Constants.CUSTOM01.ONE.getDesc()) |
| | | // .eq(AppMenu::getPermissionUq, Constants.APP_MENU_TYPE.SUPPLIER.getDesc()) |
| | | ; |
| | | List<AppMenu> list = menuMapper.selectList(queryWrapper); |
| | | List<AppMenu> list = getAppMenus(); |
| | | |
| | | if (!CollectionUtils.isEmpty(list)) { |
| | | |
| | |
| | | return null; |
| | | } |
| | | |
| | | private List<AppMenu> getAppMenus() { |
| | | LambdaQueryWrapper<AppMenu> queryWrapper = new QueryWrapper<AppMenu>() |
| | | .lambda() |
| | | .eq(AppMenu::getStatus, Constants.STATUS_ACTIVE) |
| | | .eq(AppMenu::getSubaccountAccessFlag,Constants.CUSTOM01.ONE.getDesc()) |
| | | // .eq(AppMenu::getPermissionUq, Constants.APP_MENU_TYPE.SUPPLIER.getDesc()) |
| | | ; |
| | | List<AppMenu> list = menuMapper.selectList(queryWrapper); |
| | | return list; |
| | | } |
| | | |
| | | |
| | | public List<AppMenu> getSupplierPermissionMenu() { |
| | | // 获取所有订单信息 |
| | | List<AppMenu> list = getAppMenus(); |
| | | // 遍历list,找到appMenu的permissionUq的值为supplier的菜单 |
| | | // 找到 permissionUq 为 supplier 的菜单 |
| | | List<AppMenu> supplierMenus = list.stream() |
| | | .filter(menu -> Constants.DEFAULT_SUB_ACCOUNT_SUPPLIER.equals(menu.getPermissionUq())) |
| | | .collect(Collectors.toList()); |
| | | if(!CollectionUtils.isEmpty(supplierMenus)){ |
| | | AppMenu appMenu = supplierMenus.get(0); |
| | | |
| | | // 递归查找所有子菜单 |
| | | List<AppMenu> allChildMenus = findAllChildren(appMenu.getId(), list); |
| | | |
| | | return allChildMenus; |
| | | } |
| | | |
| | | return new ArrayList<>(); |
| | | } |
| | | |
| | | public List<AppMenu> getPartnerPermissionMenu() { |
| | | // 获取所有订单信息 |
| | | List<AppMenu> list = getAppMenus(); |
| | | // 遍历list,找到appMenu的permissionUq的值为supplier的菜单 |
| | | // 找到 permissionUq 为 supplier 的菜单 |
| | | List<AppMenu> supplierMenus = list.stream() |
| | | .filter(menu -> Constants.DEFAULT_SUB_ACCOUNT_PARTNER.equals(menu.getPermissionUq())) |
| | | .collect(Collectors.toList()); |
| | | if(!CollectionUtils.isEmpty(supplierMenus)){ |
| | | AppMenu appMenu = supplierMenus.get(0); |
| | | |
| | | // 递归查找所有子菜单 |
| | | List<AppMenu> allChildMenus = findAllChildren(appMenu.getId(), list); |
| | | |
| | | return allChildMenus; |
| | | } |
| | | |
| | | return new ArrayList<>(); |
| | | } |
| | | |
| | | /** |
| | | * 递归查找所有子菜单 |
| | | * |
| | | * @param parentId 父菜单 ID |
| | | * @param allMenus 所有菜单列表 |
| | | * @return 所有子菜单 |
| | | */ |
| | | public static List<AppMenu> findAllChildren(String parentId, List<AppMenu> allMenus) { |
| | | List<AppMenu> children = allMenus.stream() |
| | | .filter(menu -> parentId.equals(menu.getParentId())) |
| | | .collect(Collectors.toList()); |
| | | |
| | | List<AppMenu> allChildren = new ArrayList<>(children); |
| | | for (AppMenu child : children) { |
| | | allChildren.addAll(findAllChildren(child.getId(), allMenus)); |
| | | } |
| | | |
| | | return allChildren; |
| | | } |
| | | |
| | | |
| | | } |