提交代码

dev
胡锐 7 months ago
parent a7b3369b15
commit f29a651ad9
  1. 81
      bweb/src/main/java/com/bweb/controller/SecMenuController.java
  2. 6
      service/src/main/java/com/hfkj/dao/SecRoleMenuRelMapperExt.java
  3. 6
      service/src/main/java/com/hfkj/service/SecRoleMenuRelService.java
  4. 8
      service/src/main/java/com/hfkj/service/impl/SecMenuServiceImpl.java
  5. 7
      service/src/main/java/com/hfkj/service/impl/SecRoleMenuRelServiceImpl.java

@ -170,44 +170,17 @@ public class SecMenuController {
}
}
@RequestMapping(value="/queryAssignMenuTree",method = RequestMethod.GET)
@RequestMapping(value="/queryRoleMenuArray",method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "查询分配菜单树")
public ResponseData queryAssignMenuTree(@RequestParam(value = "roleId" , required = true) Long roleId) {
public ResponseData queryRoleMenuArray(@RequestParam(value = "roleId" , required = true) Long roleId) {
try {
List<MenuTreeModel> treeModelList = new ArrayList<>();
MenuTreeModel menuTree;
// 查询角色菜单权限
List<SecRoleMenuRel> roleMenuList = secRoleMenuRelService.getRelListByRole(roleId);
// 获取系统菜单
List<SecMenu> sysMenuList = secMenuService.getAllList();
Map<Long, SecRoleMenuRel> roleMenuRelMap = secRoleMenuRelService.getRelListByRole(roleId)
.stream()
.collect(Collectors.toMap(SecRoleMenuRel::getMenuId, Function.identity()));
// 获取系统顶级菜单
List<SecMenu> topLevelMenuList = sysMenuList.stream().filter(o -> o.getMenuPSid() == null)
.sorted(Comparator.comparing(SecMenu::getMenuSort))
.collect(Collectors.toList());
for (SecMenu topLevelMenu : topLevelMenuList) {
menuTree = new MenuTreeModel();
menuTree.setId(topLevelMenu.getId());
menuTree.setMenuName(topLevelMenu.getMenuName());
menuTree.setMenuType(topLevelMenu.getMenuType());
menuTree.setMenuUrl(topLevelMenu.getMenuUrl());
menuTree.setMenuUrlImg(topLevelMenu.getMenuUrlImg());
menuTree.setMenuPSid(topLevelMenu.getMenuPSid());
menuTree.setMenuSort(topLevelMenu.getMenuSort());
menuTree.setMenuDesc(topLevelMenu.getMenuDesc());
// 递归子菜单
menuTree.setChildMenuList(recursionMenu(sysMenuList, roleMenuRelMap, topLevelMenu.getId()));
// 获取角色菜单
menuTree.setAuthority(roleMenuRelMap.get(topLevelMenu.getId()) != null ? true : false);
treeModelList.add(menuTree);
}
return ResponseMsgUtil.success(treeModelList);
return ResponseMsgUtil.success(roleMenuList.stream().map(SecRoleMenuRel::getMenuId).collect(Collectors.toList())
.stream().map(Object::toString).collect(Collectors.toList()));
} catch (Exception e) {
log.error("error!",e);
@ -229,10 +202,10 @@ public class SecMenuController {
}
}
@RequestMapping(value="/queryRoleMenuTreeCustomized",method = RequestMethod.POST)
@RequestMapping(value="/queryMenuTree",method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "查询角色菜单树")
public ResponseData queryRoleMenuTreeCustomized(@RequestParam(value = "roleId" , required = false) Long roleId) {
public ResponseData queryMenuTree() {
try {
List<Map<String,Object>> mapList = new ArrayList<>();
Map<String,Object> map;
@ -252,7 +225,7 @@ public class SecMenuController {
map.put("key", ""+topLevelMenu.getId());
map.put("title", topLevelMenu.getMenuName());
// 获取下级菜单
map.put("children", recursionMenu2(menuList, topLevelMenu.getId()));
map.put("children", recursionMenu(menuList, topLevelMenu.getId()));
mapList.add(map);
}
}
@ -271,7 +244,7 @@ public class SecMenuController {
* @param parentMenuId 父级菜单id
* @return
*/
public List<Map<String,Object>> recursionMenu2(List<SecMenu> dataSource, Long parentMenuId) {
public List<Map<String,Object>> recursionMenu(List<SecMenu> dataSource, Long parentMenuId) {
List<Map<String,Object>> mapList = new ArrayList<>();
Map<String,Object> map;
@ -285,7 +258,7 @@ public class SecMenuController {
map.put("key", ""+menu.getId());
map.put("title", menu.getMenuName());
// 获取下级菜单
List<Map<String, Object>> recursioned = recursionMenu2(dataSource, menu.getId());
List<Map<String, Object>> recursioned = recursionMenu(dataSource, menu.getId());
if (recursioned.isEmpty()) {
map.put("isLeaf", true);
} else {
@ -297,36 +270,4 @@ public class SecMenuController {
return mapList;
}
/**
* 递归菜单
* @param sysMenu 系统菜单
* @param roleMenuRel 角色菜单
* @param parentMenuId 父类菜单id
* @return
*/
public List<MenuTreeModel> recursionMenu(List<SecMenu> sysMenu, Map<Long, SecRoleMenuRel> roleMenuRel, Long parentMenuId) {
List<MenuTreeModel> treeModelList = new ArrayList<>();
MenuTreeModel menuTree;
List<SecMenu> collect = sysMenu.stream()
.filter(o -> o.getMenuPSid() != null && o.getMenuPSid().equals(parentMenuId))
.sorted(Comparator.comparing(SecMenu::getMenuSort))
.collect(Collectors.toList());
for (SecMenu menu : collect) {
menuTree = new MenuTreeModel();
menuTree.setId(menu.getId());
menuTree.setMenuName(menu.getMenuName());
menuTree.setMenuType(menu.getMenuType());
menuTree.setMenuUrl(menu.getMenuUrl());
menuTree.setMenuUrlImg(menu.getMenuUrlImg());
menuTree.setMenuPSid(menu.getMenuPSid());
menuTree.setMenuSort(menu.getMenuSort());
menuTree.setMenuDesc(menu.getMenuDesc());
// 获取角色菜单
menuTree.setAuthority(roleMenuRel.get(menuTree.getId()) != null ? true : false);
menuTree.setChildMenuList(recursionMenu(sysMenu, roleMenuRel, menu.getId()));
treeModelList.add(menuTree);
}
return treeModelList;
}
}

@ -13,9 +13,9 @@ public interface SecRoleMenuRelMapperExt {
@Insert({"<script>" +
" insert into sec_role_menu_rel (role_id, menu_id) " +
" VALUES " +
" <foreach collection='list' item='item' index='index' separator=','>" +
" (#{item.roleId, #{menuId})" +
" values " +
" <foreach collection='list' item='item' index='index' separator=','>",
" ( #{item.roleId}, #{item.menuId} )" +
" </foreach>" +
" </script>"})
void batchAdd(@Param("list") List<SecRoleMenuRel> list);

@ -23,6 +23,12 @@ public interface SecRoleMenuRelService {
*/
void delete(Long relId);
/**
* 删除
* @param roleId 角色id
*/
void deleteByRole(Long roleId);
/**
* 查询角色菜单关系
* @param roleId 角色id

@ -166,8 +166,8 @@ public class SecMenuServiceImpl implements SecMenuService {
if (secRole == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的角色");
}
// 查询角色菜单
List<SecRoleMenuRel> roleMenuList = secRoleMenuRelService.getRelListByRole(roleId);
// 删除角色权限旧数据
secRoleMenuRelService.deleteByRole(roleId);
SecRoleMenuRel rel;
List<SecRoleMenuRel> relList = new ArrayList<>();
@ -177,11 +177,9 @@ public class SecMenuServiceImpl implements SecMenuService {
rel.setMenuId(menuId);
relList.add(rel);
}
// 数据集合并
relList.addAll(roleMenuList);
// 根据菜单id去重
List<SecRoleMenuRel> collectList = relList.stream().filter(StreamUtil.distinctByKey(b -> b.getMenuId())).collect(Collectors.toList());
// 绑定角色与菜单关系
// 角色新菜单权限
secRoleMenuRelService.batchAdd(collectList);
// 更新缓存
redisUtil.hdel(CACHE_ROLE_MENU, ""+roleId);

@ -30,6 +30,13 @@ public class SecRoleMenuRelServiceImpl implements SecRoleMenuRelService {
secRoleMenuRelMapper.deleteByPrimaryKey(relId);
}
@Override
public void deleteByRole(Long roleId) {
SecRoleMenuRelExample example = new SecRoleMenuRelExample();
example.createCriteria().andRoleIdEqualTo(roleId);
secRoleMenuRelMapper.deleteByExample(example);
}
@Override
public List<SecRoleMenuRel> getRelListByRole(Long roleId) {
SecRoleMenuRelExample example = new SecRoleMenuRelExample();

Loading…
Cancel
Save