【7.6.0】【sys】【menu】调整api位置:获取菜单对应的应用id(可以批量获取)

pull/57/head
fengshuonan 2023-06-26 21:52:56 +08:00
parent 616bf10208
commit 7cd3c1becd
5 changed files with 50 additions and 30 deletions

View File

@ -27,6 +27,7 @@ package cn.stylefeng.roses.kernel.sys.api;
import cn.stylefeng.roses.kernel.sys.api.pojo.menu.UserAppMenuInfo; import cn.stylefeng.roses.kernel.sys.api.pojo.menu.UserAppMenuInfo;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Set; import java.util.Set;
/** /**
@ -47,4 +48,13 @@ public interface SysMenuServiceApi {
*/ */
List<UserAppMenuInfo> getUserAppMenuDetailList(Set<Long> menuIdList); List<UserAppMenuInfo> getUserAppMenuDetailList(Set<Long> menuIdList);
/**
* id
*
* @return keyidvalueid
* @author fengshuonan
* @since 2023/6/26 21:47
*/
Map<Long, Long> getMenuAppId(List<Long> menuIdList);
} }

View File

@ -1,5 +1,6 @@
package cn.stylefeng.roses.kernel.sys.modular.menu.service; package cn.stylefeng.roses.kernel.sys.modular.menu.service;
import cn.stylefeng.roses.kernel.sys.api.SysMenuServiceApi;
import cn.stylefeng.roses.kernel.sys.modular.menu.entity.SysMenu; import cn.stylefeng.roses.kernel.sys.modular.menu.entity.SysMenu;
import cn.stylefeng.roses.kernel.sys.modular.menu.pojo.request.SysMenuRequest; import cn.stylefeng.roses.kernel.sys.modular.menu.pojo.request.SysMenuRequest;
import cn.stylefeng.roses.kernel.sys.modular.menu.pojo.response.AppGroupDetail; import cn.stylefeng.roses.kernel.sys.modular.menu.pojo.response.AppGroupDetail;
@ -14,7 +15,7 @@ import java.util.Set;
* @author fengshuonan * @author fengshuonan
* @date 2023/06/10 21:28 * @date 2023/06/10 21:28
*/ */
public interface SysMenuService extends IService<SysMenu> { public interface SysMenuService extends IService<SysMenu>, SysMenuServiceApi {
/** /**
* *
@ -69,14 +70,6 @@ public interface SysMenuService extends IService<SysMenu> {
*/ */
boolean validateMenuBindApp(Set<Long> appIdList); boolean validateMenuBindApp(Set<Long> appIdList);
/**
* appId
*
* @author fengshuonan
* @since 2023/6/13 22:49
*/
Long getMenuAppId(Long menuId);
/** /**
* *
* *

View File

@ -1,6 +1,7 @@
package cn.stylefeng.roses.kernel.sys.modular.menu.service.impl; package cn.stylefeng.roses.kernel.sys.modular.menu.service.impl;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.stylefeng.roses.kernel.db.api.factory.PageFactory; import cn.stylefeng.roses.kernel.db.api.factory.PageFactory;
import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory; import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory;
@ -24,6 +25,7 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -53,7 +55,8 @@ public class SysMenuOptionsServiceImpl extends ServiceImpl<SysMenuOptionsMapper,
BeanUtil.copyProperties(sysMenuOptionsRequest, sysMenuOptions); BeanUtil.copyProperties(sysMenuOptionsRequest, sysMenuOptions);
// 获取菜单的应用id // 获取菜单的应用id
Long appId = sysMenuService.getMenuAppId(sysMenuOptionsRequest.getMenuId()); Map<Long, Long> menuAppId = sysMenuService.getMenuAppId(ListUtil.list(false, sysMenuOptionsRequest.getMenuId()));
Long appId = menuAppId.get(sysMenuOptionsRequest.getMenuId());
sysMenuOptions.setAppId(appId); sysMenuOptions.setAppId(appId);
this.save(sysMenuOptions); this.save(sysMenuOptions);

View File

@ -9,7 +9,6 @@ import cn.stylefeng.roses.kernel.rule.constants.SymbolConstant;
import cn.stylefeng.roses.kernel.rule.constants.TreeConstants; import cn.stylefeng.roses.kernel.rule.constants.TreeConstants;
import cn.stylefeng.roses.kernel.rule.exception.base.ServiceException; import cn.stylefeng.roses.kernel.rule.exception.base.ServiceException;
import cn.stylefeng.roses.kernel.rule.tree.buildpids.PidStructureBuildUtil; import cn.stylefeng.roses.kernel.rule.tree.buildpids.PidStructureBuildUtil;
import cn.stylefeng.roses.kernel.sys.api.SysMenuServiceApi;
import cn.stylefeng.roses.kernel.sys.api.callback.RemoveMenuCallbackApi; import cn.stylefeng.roses.kernel.sys.api.callback.RemoveMenuCallbackApi;
import cn.stylefeng.roses.kernel.sys.api.pojo.menu.UserAppMenuInfo; import cn.stylefeng.roses.kernel.sys.api.pojo.menu.UserAppMenuInfo;
import cn.stylefeng.roses.kernel.sys.modular.app.service.SysAppService; import cn.stylefeng.roses.kernel.sys.modular.app.service.SysAppService;
@ -28,10 +27,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList; import java.util.*;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@ -41,7 +37,7 @@ import java.util.stream.Collectors;
* @date 2023/06/10 21:28 * @date 2023/06/10 21:28
*/ */
@Service @Service
public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> implements SysMenuService, SysMenuServiceApi { public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> implements SysMenuService {
@Resource @Resource
private SysAppService sysAppService; private SysAppService sysAppService;
@ -127,19 +123,6 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
return count > 0; return count > 0;
} }
@Override
public Long getMenuAppId(Long menuId) {
LambdaQueryWrapper<SysMenu> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(SysMenu::getMenuId, menuId);
queryWrapper.select(SysMenu::getAppId);
SysMenu one = this.getOne(queryWrapper, false);
if (one != null) {
return one.getAppId();
} else {
return null;
}
}
@Override @Override
public List<SysMenu> getTotalMenus() { public List<SysMenu> getTotalMenus() {
LambdaQueryWrapper<SysMenu> menuLambdaQueryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<SysMenu> menuLambdaQueryWrapper = new LambdaQueryWrapper<>();
@ -281,6 +264,34 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
return result; return result;
} }
@Override
public Map<Long, Long> getMenuAppId(List<Long> menuIdList) {
// 定义返回结果
HashMap<Long, Long> menuIdAppIdMap = new HashMap<>();
if (ObjectUtil.isEmpty(menuIdList)) {
return menuIdAppIdMap;
}
// 查询数据库菜单id对应的应用id集合
LambdaQueryWrapper<SysMenu> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.in(SysMenu::getMenuId, menuIdList);
queryWrapper.select(SysMenu::getAppId);
List<SysMenu> queryList = this.list(queryWrapper);
if (ObjectUtil.isEmpty(queryList)) {
return menuIdAppIdMap;
}
// 制作映射关系
for (SysMenu sysMenu : queryList) {
menuIdAppIdMap.put(sysMenu.getMenuId(), sysMenu.getAppId());
}
return menuIdAppIdMap;
}
/** /**
* *
* *

View File

@ -1,6 +1,7 @@
package cn.stylefeng.roses.kernel.sys.modular.role.service.impl; package cn.stylefeng.roses.kernel.sys.modular.role.service.impl;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.stylefeng.roses.kernel.db.api.factory.PageFactory; import cn.stylefeng.roses.kernel.db.api.factory.PageFactory;
import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory; import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory;
@ -32,6 +33,7 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -169,7 +171,8 @@ public class SysRoleMenuServiceImpl extends ServiceImpl<SysRoleMenuMapper, SysRo
SysRoleMenu sysRoleMenu = new SysRoleMenu(); SysRoleMenu sysRoleMenu = new SysRoleMenu();
sysRoleMenu.setRoleId(roleId); sysRoleMenu.setRoleId(roleId);
sysRoleMenu.setMenuId(menuId); sysRoleMenu.setMenuId(menuId);
Long appId = sysMenuService.getMenuAppId(menuId); Map<Long, Long> menuAppIdMap = sysMenuService.getMenuAppId(ListUtil.list(false, menuId));
Long appId = menuAppIdMap.get(menuId);
sysRoleMenu.setAppId(appId); sysRoleMenu.setAppId(appId);
// 2. 查询菜单下所有的菜单功能 // 2. 查询菜单下所有的菜单功能