|
|
@ -27,7 +27,9 @@ import org.dromara.system.mapper.SysRoleMapper;
|
|
|
|
import org.dromara.system.mapper.SysRoleMenuMapper;
|
|
|
|
import org.dromara.system.mapper.SysRoleMenuMapper;
|
|
|
|
import org.dromara.system.mapper.SysTenantPackageMapper;
|
|
|
|
import org.dromara.system.mapper.SysTenantPackageMapper;
|
|
|
|
import org.dromara.system.service.ISysMenuService;
|
|
|
|
import org.dromara.system.service.ISysMenuService;
|
|
|
|
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
|
@ -170,20 +172,74 @@ public class SysMenuServiceImpl implements ISysMenuService {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<Long> selectMenuListByPackageId(Long packageId) {
|
|
|
|
public List<Long> selectMenuListByPackageId(Long packageId) {
|
|
|
|
|
|
|
|
// 1. 查询套餐信息
|
|
|
|
SysTenantPackage tenantPackage = tenantPackageMapper.selectById(packageId);
|
|
|
|
SysTenantPackage tenantPackage = tenantPackageMapper.selectById(packageId);
|
|
|
|
List<Long> menuIds = StringUtils.splitTo(tenantPackage.getMenuIds(), Convert::toLong);
|
|
|
|
List<Long> menuIds = StringUtils.splitTo(tenantPackage.getMenuIds(), Convert::toLong);
|
|
|
|
if (CollUtil.isEmpty(menuIds)) {
|
|
|
|
if (CollUtil.isEmpty(menuIds)) {
|
|
|
|
return new ArrayList<>();
|
|
|
|
return new ArrayList<>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 2. 初始化结果列表
|
|
|
|
|
|
|
|
List<Long> result = new ArrayList<>();
|
|
|
|
|
|
|
|
int batchSize = 500; // 每批处理1000个参数
|
|
|
|
|
|
|
|
|
|
|
|
List<Long> parentIds = null;
|
|
|
|
List<Long> parentIds = null;
|
|
|
|
if (tenantPackage.getMenuCheckStrictly()) {
|
|
|
|
if (tenantPackage.getMenuCheckStrictly()) {
|
|
|
|
parentIds = baseMapper.selectObjs(new LambdaQueryWrapper<SysMenu>()
|
|
|
|
parentIds = baseMapper.selectObjs(new LambdaQueryWrapper<SysMenu>()
|
|
|
|
.select(SysMenu::getParentId)
|
|
|
|
.select(SysMenu::getParentId)
|
|
|
|
.in(SysMenu::getMenuId, menuIds), x -> {return Convert.toLong(x);});
|
|
|
|
.in(SysMenu::getMenuId, menuIds), x -> {
|
|
|
|
|
|
|
|
return Convert.toLong(x);
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return baseMapper.selectObjs(new LambdaQueryWrapper<SysMenu>()
|
|
|
|
if (tenantPackage.getMenuCheckStrictly()) {
|
|
|
|
.in(SysMenu::getMenuId, menuIds)
|
|
|
|
parentIds = new ArrayList<>();
|
|
|
|
.notIn(CollUtil.isNotEmpty(parentIds), SysMenu::getMenuId, parentIds), x -> {return Convert.toLong(x);});
|
|
|
|
// 分批查询父ID
|
|
|
|
|
|
|
|
for (int i = 0; i < menuIds.size(); i += batchSize) {
|
|
|
|
|
|
|
|
int endIndex = Math.min(i + batchSize, menuIds.size());
|
|
|
|
|
|
|
|
List<Long> batchMenuIds = menuIds.subList(i, endIndex);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<Long> batchParentIds = baseMapper.selectObjs(
|
|
|
|
|
|
|
|
new LambdaQueryWrapper<SysMenu>()
|
|
|
|
|
|
|
|
.select(SysMenu::getParentId)
|
|
|
|
|
|
|
|
.in(SysMenu::getMenuId, batchMenuIds),
|
|
|
|
|
|
|
|
x -> {
|
|
|
|
|
|
|
|
return Convert.toLong(x);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
parentIds.addAll(batchParentIds);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 4. 分批查询最终结果
|
|
|
|
|
|
|
|
for (int i = 0; i < menuIds.size(); i += batchSize) {
|
|
|
|
|
|
|
|
int endIndex = Math.min(i + batchSize, menuIds.size());
|
|
|
|
|
|
|
|
List<Long> batchMenuIds = menuIds.subList(i, endIndex);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LambdaQueryWrapper<SysMenu> wrapper = new LambdaQueryWrapper<SysMenu>()
|
|
|
|
|
|
|
|
.in(SysMenu::getMenuId, batchMenuIds);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 如果有父ID,也需要分批处理
|
|
|
|
|
|
|
|
if (CollUtil.isNotEmpty(parentIds)) {
|
|
|
|
|
|
|
|
for (int j = 0; j < parentIds.size(); j += batchSize) {
|
|
|
|
|
|
|
|
int parentEndIndex = Math.min(j + batchSize, parentIds.size());
|
|
|
|
|
|
|
|
List<Long> batchParentIds = parentIds.subList(j, parentEndIndex);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wrapper.notIn(SysMenu::getMenuId, batchParentIds);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 执行查询并收集结果
|
|
|
|
|
|
|
|
List<Long> batchResult = baseMapper.selectObjs(wrapper, x -> {
|
|
|
|
|
|
|
|
return Convert.toLong(x);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
result.addAll(batchResult);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// 如果没有父ID,直接查询
|
|
|
|
|
|
|
|
List<Long> batchResult = baseMapper.selectObjs(wrapper, x -> {
|
|
|
|
|
|
|
|
return Convert.toLong(x);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
result.addAll(batchResult);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -301,7 +357,10 @@ public class SysMenuServiceImpl implements ISysMenuService {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public int insertMenu(SysMenuBo bo) {
|
|
|
|
public int insertMenu(SysMenuBo bo) {
|
|
|
|
SysMenu menu = MapstructUtils.convert(bo, SysMenu.class);
|
|
|
|
SysMenu menu = MapstructUtils.convert(bo, SysMenu.class);
|
|
|
|
return baseMapper.insert(menu);
|
|
|
|
int insert = baseMapper.insert(menu);
|
|
|
|
|
|
|
|
assert menu != null;
|
|
|
|
|
|
|
|
bo.setMenuId(menu.getMenuId());
|
|
|
|
|
|
|
|
return insert;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -342,6 +401,84 @@ public class SysMenuServiceImpl implements ISysMenuService {
|
|
|
|
return !exist;
|
|
|
|
return !exist;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 复制菜单
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param menuId 源菜单ID
|
|
|
|
|
|
|
|
* @param menu 新菜单信息
|
|
|
|
|
|
|
|
* @return 结果
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
|
|
|
public int copyMenu(Long menuId, SysMenuBo menu) {
|
|
|
|
|
|
|
|
// 1. 获取源菜单信息
|
|
|
|
|
|
|
|
SysMenuVo sourceMenu = selectMenuById(menuId);
|
|
|
|
|
|
|
|
if (sourceMenu == null) {
|
|
|
|
|
|
|
|
throw new RuntimeException("源菜单不存在");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 2. 创建新菜单对象
|
|
|
|
|
|
|
|
SysMenuBo newMenu = new SysMenuBo();
|
|
|
|
|
|
|
|
BeanUtils.copyProperties(sourceMenu, newMenu);
|
|
|
|
|
|
|
|
newMenu.setMenuId(null);
|
|
|
|
|
|
|
|
newMenu.setCreateTime(null);
|
|
|
|
|
|
|
|
newMenu.setMenuName(menu.getMenuName());
|
|
|
|
|
|
|
|
newMenu.setParentId(menu.getParentId());
|
|
|
|
|
|
|
|
newMenu.setOrderNum(menu.getOrderNum());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 3. 检查菜单名称是否唯一
|
|
|
|
|
|
|
|
if (!checkMenuNameUnique(newMenu)) {
|
|
|
|
|
|
|
|
throw new RuntimeException("菜单名称已存在");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 4. 插入新菜单
|
|
|
|
|
|
|
|
int rows = insertMenu(newMenu);
|
|
|
|
|
|
|
|
if (rows > 0) {
|
|
|
|
|
|
|
|
// 5. 获取新插入菜单的ID
|
|
|
|
|
|
|
|
Long newMenuId = newMenu.getMenuId();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 6. 递归复制子菜单
|
|
|
|
|
|
|
|
copyChildMenus(menuId, newMenuId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return rows;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 递归复制子菜单
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param sourceParentId 源父菜单ID
|
|
|
|
|
|
|
|
* @param targetParentId 目标父菜单ID
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private void copyChildMenus(Long sourceParentId, Long targetParentId) {
|
|
|
|
|
|
|
|
// 1. 查询源父菜单的所有子菜单
|
|
|
|
|
|
|
|
List<SysMenuVo> children = baseMapper.selectVoList(
|
|
|
|
|
|
|
|
new LambdaQueryWrapper<SysMenu>()
|
|
|
|
|
|
|
|
.eq(SysMenu::getParentId, sourceParentId)
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 2. 递归复制每个子菜单
|
|
|
|
|
|
|
|
if (CollUtil.isNotEmpty(children)) {
|
|
|
|
|
|
|
|
for (SysMenuVo child : children) {
|
|
|
|
|
|
|
|
// 2.1 创建新的子菜单对象
|
|
|
|
|
|
|
|
SysMenuBo newChildMenu = new SysMenuBo();
|
|
|
|
|
|
|
|
BeanUtils.copyProperties(child, newChildMenu);
|
|
|
|
|
|
|
|
newChildMenu.setMenuId(null);
|
|
|
|
|
|
|
|
newChildMenu.setCreateTime(null);
|
|
|
|
|
|
|
|
newChildMenu.setParentId(targetParentId);
|
|
|
|
|
|
|
|
newChildMenu.setMenuName(child.getMenuName());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 2.2 插入新的子菜单
|
|
|
|
|
|
|
|
int rows = insertMenu(newChildMenu);
|
|
|
|
|
|
|
|
if (rows > 0) {
|
|
|
|
|
|
|
|
// 2.3 获取新插入的子菜单ID
|
|
|
|
|
|
|
|
Long newChildMenuId = newChildMenu.getMenuId();
|
|
|
|
|
|
|
|
// 2.4 递归复制下一级子菜单
|
|
|
|
|
|
|
|
copyChildMenus(child.getMenuId(), newChildMenuId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 根据父节点的ID获取所有子节点
|
|
|
|
* 根据父节点的ID获取所有子节点
|
|
|
|
*
|
|
|
|
*
|
|
|
|