refactor(system): 重构系统模块中的菜单和角色关联关系

This commit is contained in:
2026-01-15 21:52:56 +08:00
parent 8918ce781b
commit 9e306aadc5
102 changed files with 819 additions and 538 deletions
@@ -18,12 +18,14 @@ package cn.odboy.system.dal.model.response;
import cn.odboy.base.KitBaseUserTimeTb;
import cn.odboy.system.constant.SystemDataScopeEnum;
import cn.odboy.system.dal.dataobject.SystemDeptTb;
import cn.odboy.system.dal.dataobject.SystemMenuTb;
import cn.odboy.system.dal.dataobject.SystemUserTb;
import io.swagger.annotations.ApiModelProperty;
import java.util.Objects;
import java.util.Set;
import lombok.Getter;
import lombok.Setter;
import java.util.List;
import java.util.Objects;
import java.util.Set;
@Getter
@Setter
@@ -45,7 +47,7 @@ public class SystemRoleVo extends KitBaseUserTimeTb {
@ApiModelProperty(value = "用户", hidden = true)
private Set<SystemUserTb> users;
@ApiModelProperty(value = "菜单", hidden = true)
private Set<SystemMenuVo> menus;
private Set<SystemMenuTb> menus;
@ApiModelProperty(value = "部门", hidden = true)
private Set<SystemDeptTb> depts;
@@ -66,5 +68,4 @@ public class SystemRoleVo extends KitBaseUserTimeTb {
return Objects.hash(id);
}
}
@@ -15,11 +15,13 @@
*/
package cn.odboy.system.dal.mysql;
import cn.odboy.system.dal.dataobject.SystemMenuTb;
import cn.odboy.system.dal.dataobject.SystemRoleMenuTb;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Set;
/**
* 角色菜单关联 Mapper
@@ -29,5 +31,9 @@ import org.apache.ibatis.annotations.Param;
@Mapper
public interface SystemRoleMenuMapper extends BaseMapper<SystemRoleMenuTb> {
List<String> listMenuPermissionByRoleIds(@Param("roleIds") List<Long> roleIds);
Set<String> listMenuPermissionByRoleIds(@Param("roleIds") Set<Long> roleIds);
List<SystemMenuTb> listMenuWithRoleIdsNeButton(@Param("roleIds") Set<Long> roleIds);
List<SystemMenuTb> listMenuWithRoleIds(@Param("roleIds") Set<Long> roleIds);
}
@@ -28,7 +28,7 @@ public interface SystemUserRoleMapper extends BaseMapper<SystemUserRoleTb> {
Set<SystemRoleTb> listUserRoleByUserId(@Param("userId") Long userId);
List<Integer> listUserRoleLevelByUserId(@Param("userId") Long userId);
Set<Integer> listUserRoleLevelByUserId(@Param("userId") Long userId);
List<Long> listUserRoleIdByUserId(@Param("userId") Long userId);
Set<Long> listUserRoleIdByUserId(@Param("userId") Long userId);
}
@@ -27,14 +27,19 @@ import cn.odboy.system.dal.model.request.SystemQueryMenuArgs;
import cn.odboy.system.dal.model.response.SystemMenuMetaVo;
import cn.odboy.system.dal.model.response.SystemMenuRouterVo;
import cn.odboy.system.dal.model.response.SystemMenuVo;
import cn.odboy.system.dal.model.response.SystemRoleVo;
import cn.odboy.system.dal.mysql.SystemMenuMapper;
import cn.odboy.system.framework.permission.core.KitSecurityHelper;
import cn.odboy.util.KitBeanUtil;
import cn.odboy.util.KitClassUtil;
import cn.odboy.util.KitValidUtil;
import cn.odboy.util.xlsx.KitExcelExporter;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashSet;
@@ -44,11 +49,6 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
public class SystemMenuService {
@@ -202,20 +202,20 @@ public class SystemMenuService {
*/
@Transactional(rollbackFor = Exception.class)
public void deleteMenuByIds(Set<Long> ids) {
// Set<SystemMenuVo> menuSet = new HashSet<>();
// for (Long id : ids) {
// List<SystemMenuVo> menuList = this.listMenuByPid(id);
// menuSet.add(this.getMenuVoById(id));
// menuSet = this.queryChildMenuByArgs(menuList, menuSet);
// }
// List<Long> menuIds = menuSet.stream().map(SystemMenuVo::getId).filter(Objects::nonNull).distinct().collect(Collectors.toList());
// if (CollUtil.isNotEmpty(menuIds)) {
// systemRoleMenuService.deleteRoleMenuByMenuIds(menuIds);
// systemMenuMapper.deleteByIds(menuIds);
// }
// for (SystemMenuVo menu : menuSet) {
// this.updateMenuSubCnt(menu.getPid());
// }
// Set<SystemMenuVo> menuSet = new HashSet<>();
// for (Long id : ids) {
// List<SystemMenuVo> menuList = this.listMenuByPid(id);
// menuSet.add(this.getMenuVoById(id));
// menuSet = this.queryChildMenuByArgs(menuList, menuSet);
// }
// List<Long> menuIds = menuSet.stream().map(SystemMenuVo::getId).filter(Objects::nonNull).distinct().collect(Collectors.toList());
// if (CollUtil.isNotEmpty(menuIds)) {
// systemRoleMenuService.deleteRoleMenuByMenuIds(menuIds);
// systemMenuMapper.deleteByIds(menuIds);
// }
// for (SystemMenuVo menu : menuSet) {
// this.updateMenuSubCnt(menu.getPid());
// }
// ========= 优化 20260114 =========
if (CollUtil.isEmpty(ids)) {
return;
@@ -245,8 +245,7 @@ public class SystemMenuService {
Set<Long> result = new HashSet<>(rootIds);
Set<Long> currentLevelIds = new HashSet<>(rootIds);
// 构建父ID到子菜单的映射
Map<Long, List<SystemMenuTb>> parentToChildrenMap = allMenus.stream()
.filter(menu -> menu.getPid() != null)
Map<Long, List<SystemMenuTb>> parentToChildrenMap = allMenus.stream().filter(menu -> menu.getPid() != null)
.collect(Collectors.groupingBy(SystemMenuTb::getPid));
while (!currentLevelIds.isEmpty()) {
Set<Long> nextLevelIds = new HashSet<>();
@@ -271,10 +270,9 @@ public class SystemMenuService {
*/
private void updateParentMenuCounts(Set<Long> deletedMenuIds, List<SystemMenuTb> allMenus) {
// 获取被删除菜单的父ID
Set<Long> parentIds = allMenus.stream()
.filter(menu -> deletedMenuIds.contains(menu.getId()) && menu.getPid() != null)
.map(SystemMenuTb::getPid)
.collect(Collectors.toSet());
Set<Long> parentIds =
allMenus.stream().filter(menu -> deletedMenuIds.contains(menu.getId()) && menu.getPid() != null)
.map(SystemMenuTb::getPid).collect(Collectors.toSet());
// 更新每个父菜单的子节点计数
for (Long parentId : parentIds) {
proxyService.updateMenuSubCnt(parentId);
@@ -336,29 +334,30 @@ public class SystemMenuService {
* @param currentUserId /
* @return /
*/
public List<SystemMenuVo> listMenuByUserId(Long currentUserId) {
List<SystemRoleVo> roles = systemUserRoleService.listRoleVoByUsersId(currentUserId);
Set<Long> roleIds = roles.stream().map(SystemRoleVo::getId).collect(Collectors.toSet());
return new ArrayList<>(systemRoleMenuService.queryMenuByRoleIds(roleIds));
public List<SystemMenuTb> listMenuByUserId(Long currentUserId) {
// List<SystemRoleVo> roles = systemUserRoleService.listRoleVoByUsersId(currentUserId);
// Set<Long> roleIds = roles.stream().map(SystemRoleVo::getId).collect(Collectors.toSet());
Set<Long> roleIds = systemUserRoleService.listUserRoleIdByUserId(currentUserId);
return systemRoleMenuService.listMenuByRoleIds(roleIds, false);
}
/**
* 查询所有子节点, 包含自身ID
*
* @param menuList /
* @param menuSet /
* @return /
*/
public Set<SystemMenuTb> queryChildMenuByArgs(List<SystemMenuTb> menuList, Set<SystemMenuTb> menuSet) {
for (SystemMenuTb menu : menuList) {
menuSet.add(menu);
List<SystemMenuTb> menus = this.listMenuByPid(menu.getId());
if (CollUtil.isNotEmpty(menus)) {
queryChildMenuByArgs(menus, menuSet);
}
}
return menuSet;
}
// /**
// * 查询所有子节点, 包含自身ID
// *
// * @param menuList /
// * @param menuSet /
// * @return /
// */
// public Set<SystemMenuTb> queryChildMenuByArgs(List<SystemMenuTb> menuList, Set<SystemMenuTb> menuSet) {
// for (SystemMenuTb menu : menuList) {
// menuSet.add(menu);
// List<SystemMenuTb> menus = this.listMenuByPid(menu.getId());
// if (CollUtil.isNotEmpty(menus)) {
// queryChildMenuByArgs(menus, menuSet);
// }
// }
// return menuSet;
// }
/**
* 懒加载菜单数据
@@ -401,14 +400,15 @@ public class SystemMenuService {
* @param menus 原始数据
* @return /
*/
public List<SystemMenuVo> buildMenuTree(List<SystemMenuVo> menus) {
public List<SystemMenuVo> buildMenuTree(List<SystemMenuTb> menus) {
List<SystemMenuVo> systemMenuVos = KitBeanUtil.copyToList(menus, SystemMenuVo.class);
List<SystemMenuVo> trees = new ArrayList<>();
Set<Long> ids = new HashSet<>();
for (SystemMenuVo menu : menus) {
for (SystemMenuVo menu : systemMenuVos) {
if (menu.getPid() == null) {
trees.add(menu);
}
for (SystemMenuVo it : menus) {
for (SystemMenuVo it : systemMenuVos) {
if (menu.getId().equals(it.getPid())) {
if (menu.getChildren() == null) {
menu.setChildren(new ArrayList<>());
@@ -419,7 +419,7 @@ public class SystemMenuService {
}
}
if (CollUtil.isNotEmpty(trees)) {
trees = menus.stream().filter(s -> !ids.contains(s.getId())).collect(Collectors.toList());
trees = systemMenuVos.stream().filter(s -> !ids.contains(s.getId())).collect(Collectors.toList());
}
return trees;
}
@@ -530,27 +530,28 @@ public class SystemMenuService {
}
public List<SystemMenuRouterVo> buildFrontMenus() {
List<SystemMenuVo> originMenus = this.listMenuByUserId(KitSecurityHelper.getCurrentUserId());
List<SystemMenuTb> originMenus = this.listMenuByUserId(KitSecurityHelper.getCurrentUserId());
List<SystemMenuVo> targetMenus = this.buildMenuTree(originMenus);
return this.buildMenuVo(targetMenus);
}
public Set<Long> listChildMenuSetByMenuId(Long id) {
Set<SystemMenuTb> menuSet = new HashSet<>();
List<SystemMenuTb> menuList = this.listMenuByPid(id);
menuSet.add(this.getMenuById(id));
menuSet = this.queryChildMenuByArgs(menuList, menuSet);
return menuSet.stream().map(SystemMenuVo::getId).collect(Collectors.toSet());
// Set<SystemMenuTb> menuSet = new HashSet<>();
// List<SystemMenuTb> menuList = this.listMenuByPid(id);
// menuSet.add(this.getMenuById(id));
// menuSet = this.queryChildMenuByArgs(menuList, menuSet);
// return menuSet.stream().map(SystemMenuTb::getId).collect(Collectors.toSet());
List<SystemMenuTb> allMenus = systemMenuMapper.listAll();
return this.getAllMenuIdsWithChildren(CollUtil.newHashSet(id), allMenus);
}
public List<SystemMenuVo> listMenuSuperior(List<Long> ids) {
Set<SystemMenuTb> menus;
List<SystemMenuVo> systemMenuTbs;
if (CollUtil.isNotEmpty(ids)) {
menus = new LinkedHashSet<>(this.listMenuByIds(ids));
for (SystemMenuTb menu : menus) {
List<SystemMenuVo> menuList = this.querySuperiorMenuByArgs(menu, new ArrayList<>());
for (SystemMenuVo data : menuList) {
List<SystemMenuTb> menuList = this.querySuperiorMenuByArgs(menu, new ArrayList<>());
for (SystemMenuTb data : menuList) {
if (data.getId().equals(menu.getPid())) {
data.setSubCount(data.getSubCount() - 1);
}
@@ -559,12 +560,12 @@ public class SystemMenuService {
}
// 编辑菜单时不显示自己以及自己下级的数据, 避免出现PID数据环形问题
menus = menus.stream().filter(i -> !ids.contains(i.getId())).collect(Collectors.toSet());
List<SystemMenuVo> newMenuList = new ArrayList<>(menus);
systemMenuTbs = this.buildMenuTree(newMenuList);
List<SystemMenuTb> newMenuList = new ArrayList<>(menus);
return this.buildMenuTree(newMenuList);
} else {
systemMenuTbs = this.listMenuByPid(null);
List<SystemMenuTb> records = this.listMenuByPid(null);
return KitBeanUtil.copyToList(records, SystemMenuVo.class);
}
return systemMenuTbs;
}
public void exportMenuXlsx(HttpServletResponse response, SystemQueryMenuArgs args) throws Exception {
@@ -19,27 +19,21 @@ import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import cn.odboy.system.dal.dataobject.SystemMenuTb;
import cn.odboy.system.dal.dataobject.SystemRoleMenuTb;
import cn.odboy.system.dal.model.response.SystemMenuVo;
import cn.odboy.system.dal.mysql.SystemMenuMapper;
import cn.odboy.system.dal.mysql.SystemRoleMenuMapper;
import cn.odboy.util.KitBeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
@Service
public class SystemRoleMenuService {
@Autowired
private SystemRoleMenuMapper systemRoleMenuMapper;
@Autowired
private SystemMenuMapper systemMenuMapper;
/**
* 删除角色菜单关联 -> TestPassed
@@ -60,10 +54,10 @@ public class SystemRoleMenuService {
* @param roleId 角色id
*/
@Transactional(rollbackFor = Exception.class)
public void batchInsertRoleMenu(Set<SystemMenuVo> menus, Long roleId) {
public void batchInsertRoleMenu(Set<SystemMenuTb> menus, Long roleId) {
if (CollUtil.isNotEmpty(menus)) {
List<SystemRoleMenuTb> records = new ArrayList<>();
for (SystemMenuVo menu : menus) {
for (SystemMenuTb menu : menus) {
SystemRoleMenuTb record = new SystemRoleMenuTb();
record.setMenuId(menu.getId());
record.setRoleId(roleId);
@@ -87,26 +81,31 @@ public class SystemRoleMenuService {
}
}
public LinkedHashSet<SystemMenuVo> queryMenuByRoleIds(Set<Long> roleIds) {
/**
* @param roleIds 角色id集合 -> TestPassed
* @return /
*/
public List<SystemMenuTb> listMenuByRoleIds(Set<Long> roleIds, boolean hasButton) {
if (CollUtil.isEmpty(roleIds)) {
return new LinkedHashSet<>();
return new ArrayList<>();
}
LambdaQueryWrapper<SystemRoleMenuTb> roleMenuWrapper = new LambdaQueryWrapper<>();
roleMenuWrapper.in(SystemRoleMenuTb::getRoleId, roleIds);
List<Long> menuIds = systemRoleMenuMapper.selectList(roleMenuWrapper).stream().map(SystemRoleMenuTb::getMenuId)
.collect(Collectors.toList());
if (CollUtil.isEmpty(menuIds)) {
return new LinkedHashSet<>();
// LambdaQueryWrapper<SystemRoleMenuTb> roleMenuWrapper = new LambdaQueryWrapper<>();
// roleMenuWrapper.in(SystemRoleMenuTb::getRoleId, roleIds);
// List<Long> menuIds = systemRoleMenuMapper.selectList(roleMenuWrapper).stream().map(SystemRoleMenuTb::getMenuId)
// .collect(Collectors.toList());
// if (CollUtil.isEmpty(menuIds)) {
// return new ArrayList<>();
// }
// LambdaQueryWrapper<SystemMenuTb> menuWrapper = new LambdaQueryWrapper<>();
// menuWrapper.in(SystemMenuTb::getId, menuIds);
// // 排除"按钮"
// menuWrapper.ne(SystemMenuTb::getType, 2);
// menuWrapper.orderByAsc(SystemMenuTb::getMenuSort);
// return systemMenuMapper.selectList(menuWrapper);
if (hasButton){
return systemRoleMenuMapper.listMenuWithRoleIds(roleIds);
}
LambdaQueryWrapper<SystemMenuTb> menuWrapper = new LambdaQueryWrapper<>();
menuWrapper.in(SystemMenuTb::getId, menuIds);
// 排除"按钮"
menuWrapper.ne(SystemMenuTb::getType, 2);
menuWrapper.orderByAsc(SystemMenuTb::getMenuSort);
List<SystemMenuTb> systemMenuTbs = systemMenuMapper.selectList(menuWrapper);
List<SystemMenuVo> systemMenuVos = KitBeanUtil.copyToList(systemMenuTbs, SystemMenuVo.class);
return new LinkedHashSet<>(systemMenuVos);
return systemRoleMenuMapper.listMenuWithRoleIdsNeButton(roleIds);
}
/**
@@ -124,8 +123,14 @@ public class SystemRoleMenuService {
systemRoleMenuMapper.delete(wrapper);
}
public List<String> listMenuPermissionByRoleIds(List<Long> roleIds) {
List<String> permissions = systemRoleMenuMapper.listMenuPermissionByRoleIds(roleIds);
/**
* 根据角色id集合查询菜单权限 -> TestPassed
*
* @param roleIds 角色id集合
* @return /
*/
public List<String> listMenuPermissionByRoleIds(Set<Long> roleIds) {
Set<String> permissions = systemRoleMenuMapper.listMenuPermissionByRoleIds(roleIds);
return permissions.stream().filter(StrUtil::isNotBlank).collect(Collectors.toList());
}
}
@@ -20,11 +20,11 @@ import cn.hutool.core.lang.Dict;
import cn.hutool.core.util.StrUtil;
import cn.odboy.base.KitPageResult;
import cn.odboy.framework.exception.BadRequestException;
import cn.odboy.system.dal.dataobject.SystemMenuTb;
import cn.odboy.system.dal.dataobject.SystemRoleTb;
import cn.odboy.system.dal.model.export.SystemRoleExportRowVo;
import cn.odboy.system.dal.model.request.SystemCreateRoleArgs;
import cn.odboy.system.dal.model.request.SystemQueryRoleArgs;
import cn.odboy.system.dal.model.response.SystemMenuVo;
import cn.odboy.system.dal.model.response.SystemRoleCodeVo;
import cn.odboy.system.dal.model.response.SystemRoleVo;
import cn.odboy.system.dal.model.response.SystemUserVo;
@@ -36,16 +36,16 @@ import cn.odboy.util.xlsx.KitExcelExporter;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
public class SystemRoleService {
@@ -128,7 +128,7 @@ public class SystemRoleService {
checkRoleLevels(role.getLevel());
// 更新菜单
systemRoleMenuService.deleteRoleMenuByRoleId(role.getId());
Set<SystemMenuVo> menus = args.getMenus();
Set<SystemMenuTb> menus = args.getMenus();
if (CollUtil.isNotEmpty(menus)) {
systemRoleMenuService.batchInsertRoleMenu(menus, role.getId());
}
@@ -218,7 +218,7 @@ public class SystemRoleService {
// permissions = roles.stream().flatMap(role -> role.getMenus().stream()).map(SystemMenuVo::getPermission)
// .filter(StrUtil::isNotBlank).collect(Collectors.toSet());
// return permissions.stream().map(SystemRoleCodeVo::new).collect(Collectors.toList());
List<Long> roleIds = systemUserRoleService.listUserRoleIdByUserId(user.getId());
Set<Long> roleIds = systemUserRoleService.listUserRoleIdByUserId(user.getId());
// 查询角色权限
if (CollUtil.isNotEmpty(roleIds)) {
return systemRoleMenuService.listMenuPermissionByRoleIds(roleIds).stream().map(SystemRoleCodeVo::new).collect(Collectors.toList());
@@ -257,7 +257,7 @@ public class SystemRoleService {
* @return /
*/
private int checkRoleLevels(Integer level) {
List<Integer> levels = systemUserRoleService.listUserRoleLevelByUserId(KitSecurityHelper.getCurrentUserId());
Set<Integer> levels = systemUserRoleService.listUserRoleLevelByUserId(KitSecurityHelper.getCurrentUserId());
int min = Collections.min(levels);
if (level != null) {
if (level < min) {
@@ -18,9 +18,9 @@ package cn.odboy.system.service;
import cn.hutool.core.collection.CollUtil;
import cn.odboy.framework.exception.BadRequestException;
import cn.odboy.system.dal.dataobject.SystemDeptTb;
import cn.odboy.system.dal.dataobject.SystemMenuTb;
import cn.odboy.system.dal.dataobject.SystemRoleTb;
import cn.odboy.system.dal.dataobject.SystemUserRoleTb;
import cn.odboy.system.dal.model.response.SystemMenuVo;
import cn.odboy.system.dal.model.response.SystemRoleVo;
import cn.odboy.system.dal.model.response.SystemUserVo;
import cn.odboy.system.dal.mysql.SystemRoleMapper;
@@ -28,15 +28,16 @@ import cn.odboy.system.dal.mysql.SystemUserRoleMapper;
import cn.odboy.system.framework.permission.core.KitSecurityHelper;
import cn.odboy.util.KitBeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
public class SystemUserRoleService {
@@ -91,8 +92,8 @@ public class SystemUserRoleService {
}
SystemRoleVo roleVo = KitBeanUtil.copyToClass(role, SystemRoleVo.class);
// 查询关联的菜单信息
Set<SystemMenuVo> menus = systemRoleMenuService.queryMenuByRoleIds(Collections.singleton(role.getId()));
roleVo.setMenus(menus);
List<SystemMenuTb> menus = systemRoleMenuService.listMenuByRoleIds(Collections.singleton(role.getId()), true);
roleVo.setMenus(new HashSet<>(menus));
// 查询关联的部门信息
Set<SystemDeptTb> depts = systemRoleDeptService.listUserDeptByRoleId(role.getId());
roleVo.setDepts(depts);
@@ -140,7 +141,7 @@ public class SystemUserRoleService {
* @param args /
*/
public void checkLevel(SystemUserVo args) {
List<Integer> roleLevels = systemUserRoleMapper.listUserRoleLevelByUserId(KitSecurityHelper.getCurrentUserId());
Set<Integer> roleLevels = systemUserRoleMapper.listUserRoleLevelByUserId(KitSecurityHelper.getCurrentUserId());
Integer currentLevel = Collections.min(roleLevels);
Integer optLevel = this.getDeptLevelByRoles(args.getRoles());
if (currentLevel > optLevel) {
@@ -164,7 +165,7 @@ public class SystemUserRoleService {
* @param userId /
* @return /
*/
public List<Integer> listUserRoleLevelByUserId(Long userId) {
public Set<Integer> listUserRoleLevelByUserId(Long userId) {
return systemUserRoleMapper.listUserRoleLevelByUserId(userId);
}
@@ -174,7 +175,7 @@ public class SystemUserRoleService {
* @param userId /
* @return /
*/
public List<Long> listUserRoleIdByUserId(Long userId) {
public Set<Long> listUserRoleIdByUserId(Long userId) {
return systemUserRoleMapper.listUserRoleIdByUserId(userId);
}
@@ -1,16 +1,40 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="cn.odboy.system.dal.mysql.SystemRoleMenuMapper">
<select id="listMenuPermissionByRoleIds" resultType="java.lang.String">
SELECT DISTINCT
t2.permission
FROM
system_roles_menus t1
LEFT JOIN system_menu t2 ON t1.menu_id = t2.menu_id
WHERE
t1.role_id IN
<foreach collection="roleIds" item="roleId" open="(" close=")" separator=",">
#{roleId}
</foreach>
</select>
<select id="listMenuPermissionByRoleIds" resultType="java.lang.String">
SELECT DISTINCT
t2.permission
FROM
system_roles_menus t1
LEFT JOIN system_menu t2 ON t1.menu_id = t2.menu_id
WHERE
t1.role_id IN
<foreach collection="roleIds" item="roleId" open="(" close=")" separator=",">
#{roleId}
</foreach>
</select>
<select id="listMenuWithRoleIdsNeButton" resultType="cn.odboy.system.dal.dataobject.SystemMenuTb">
SELECT t2.*,
t2.menu_id AS id
FROM system_roles_menus t1
LEFT JOIN system_menu t2 ON t1.menu_id = t2.menu_id
WHERE t2.`type` != 2 AND t1.role_id IN
<foreach collection="roleIds" item="roleId" open="(" close=")" separator=",">
#{roleId}
</foreach>
ORDER BY
menu_sort ASC
</select>
<select id="listMenuWithRoleIds" resultType="cn.odboy.system.dal.dataobject.SystemMenuTb">
SELECT t2.*,
t2.menu_id AS id
FROM system_roles_menus t1
LEFT JOIN system_menu t2 ON t1.menu_id = t2.menu_id
WHERE t1.role_id IN
<foreach collection="roleIds" item="roleId" open="(" close=")" separator=",">
#{roleId}
</foreach>
ORDER BY
menu_sort ASC
</select>
</mapper>