Browse Source

获取菜单列表

tags/v1.0.0^2
chengwang 1 year ago
parent
commit
67cbaeae63
4 changed files with 133 additions and 5 deletions
  1. +17
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/dto/MenuVo.java
  2. +17
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/dto/OpPermissionsVo.java
  3. +26
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/dto/RoleMenuPermissionDto.java
  4. +73
    -5
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/role/RoleServiceImpl.java

+ 17
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/dto/MenuVo.java View File

@@ -0,0 +1,17 @@
package com.tuoheng.admin.dto;


import com.tuoheng.admin.entity.Menu;
import lombok.Data;

/**
* @Author xiaoying
* @Date 2022/11/28 11:55
*/
@Data
public class MenuVo extends Menu {
/**
* 标识id
*/
private String identificationId;
}

+ 17
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/dto/OpPermissionsVo.java View File

@@ -0,0 +1,17 @@
package com.tuoheng.admin.dto;


import com.tuoheng.admin.entity.OpPermissions;
import lombok.Data;

/**
* @Author xiaoying
* @Date 2022/11/28 13:11
*/
@Data
public class OpPermissionsVo extends OpPermissions {
/**
* 标识id
*/
private String identificationId;
}

+ 26
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/dto/RoleMenuPermissionDto.java View File

@@ -0,0 +1,26 @@
package com.tuoheng.admin.dto;


import lombok.Data;

import java.util.List;

/**
* @Author xiaoying
* @Date 2022/11/28 13:16
*/
@Data
public class RoleMenuPermissionDto {
/**
* 角色id
*/
private Integer roleId;
/**
*对应的菜单集合->及子菜单(按钮)
*/
private List<MenuVo> opMenusList;
/**
* 对应的权限集合
*/
private List<OpPermissionsVo> permissionsList;
}

+ 73
- 5
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/role/RoleServiceImpl.java View File

@@ -7,22 +7,25 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tuoheng.admin.dto.MenuVo;
import com.tuoheng.admin.dto.OpPermissionsVo;
import com.tuoheng.admin.dto.RoleMenuPermissionDto;
import com.tuoheng.admin.dto.UserRoleDto;
import com.tuoheng.admin.entity.OpRolePermission;
import com.tuoheng.admin.entity.Role;
import com.tuoheng.admin.entity.RoleMenu;
import com.tuoheng.admin.entity.User;
import com.tuoheng.admin.entity.*;
import com.tuoheng.admin.enums.RoleEnum;
import com.tuoheng.admin.enums.code.role.RoleDeleteEnum;
import com.tuoheng.admin.mapper.*;
import com.tuoheng.admin.query.RoleClientQuery;
import com.tuoheng.admin.query.RoleQuery;
import com.tuoheng.admin.service.menu.IMenuService;
import com.tuoheng.admin.utils.CurrentUserUtil;
import com.tuoheng.admin.vo.RoleListVo;
import com.tuoheng.common.core.common.BaseEntity;
import com.tuoheng.common.core.common.BaseServiceImpl;
import com.tuoheng.common.core.utils.DateUtils;
import com.tuoheng.common.core.utils.JsonResult;
import com.tuoheng.common.core.utils.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@@ -49,6 +52,15 @@ public class RoleServiceImpl implements IRoleService {
@Autowired
private UserMapper userMapper;

@Autowired
private IMenuService menuService;

@Autowired
private MenuMapper menuMapper;

@Autowired
private OpPermissionsMapper opPermissionsMapper;



@Override
@@ -193,8 +205,64 @@ public class RoleServiceImpl implements IRoleService {
*/
@Override
public JsonResult getMenuList(RoleClientQuery query) {
RoleMenuPermissionDto dto = new RoleMenuPermissionDto();
Integer roleId = query.getRoleId();
List<Menu> menuList = menuMapper.selectList(Wrappers.<Menu>lambdaQuery()
.eq(Menu::getMark, 1)
.eq(Menu::getStatus, 1)
.eq(StringUtils.isNotEmpty(query.getClientId()), Menu::getClientId, query.getClientId())
.orderByAsc(Menu::getSort));
if(!menuList.isEmpty()){
// 获取角色菜单列表
QueryWrapper<RoleMenu> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("role_id", roleId);
queryWrapper.select("menu_id");
List<RoleMenu> roleMenus = roleMenuMapper.selectList(queryWrapper);
List<Integer> menuIds = roleMenus.stream().map(p -> p.getMenuId()).collect(Collectors.toList());
menuList.forEach(item->{
if (menuIds.contains(item.getId())) {
item.setChecked(true);
item.setOpen(true);
}
});
}
List<MenuVo> collect = menuList.stream().map(t -> {
MenuVo vo = new MenuVo();
BeanUtils.copyProperties(t, vo);
vo.setIdentificationId(t.getId().toString());
return vo;
}).collect(Collectors.toList());

dto.setOpMenusList(collect);
//根基小程序或者pc标识
List<OpPermissions> permissions = opPermissionsMapper.selectList(Wrappers.<OpPermissions>lambdaQuery()
.eq(OpPermissions::getMark, 1)
.eq(StringUtils.isNotEmpty(query.getClientId()), OpPermissions::getClientId, query.getClientId()));
if(!permissions.isEmpty()){
//获取角色菜单列表
QueryWrapper<OpRolePermission> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("role_id", roleId);
queryWrapper.select("permission_id");
List<OpRolePermission> roleMenuList = opRolePermissionMapper.selectList(queryWrapper);
List<Integer> permissionIds = roleMenuList.stream().map(p -> p.getPermissionId()).collect(Collectors.toList());
permissions.forEach(item -> {
if (permissionIds.contains(item.getId())) {
item.setChecked(true);
item.setOpen(true);
}
});
}
List<OpPermissionsVo> collect1 = permissions.stream().map(t -> {
OpPermissionsVo vo = new OpPermissionsVo();
BeanUtils.copyProperties(t, vo);
//用"_"进行区分
vo.setIdentificationId(t.getMenuId() + "_" + t.getId());
return vo;
}).collect(Collectors.toList());
dto.setPermissionsList(collect1);
dto.setRoleId(roleId);

return null;
return JsonResult.success(dto);
}

@Override

Loading…
Cancel
Save