Search in sources :

Example 1 with SysMenuRouterVO

use of com.hccake.ballcat.system.model.vo.SysMenuRouterVO in project ballcat by ballcat-projects.

the class SysMenuController method getUserPermission.

/**
 * 返回当前用户的路由集合
 * @return 当前用户的路由
 */
@GetMapping("/router")
@Operation(summary = "动态路由", description = "动态路由")
public R<List<SysMenuRouterVO>> getUserPermission() {
    // 获取角色Code
    User user = SecurityUtils.getUser();
    Map<String, Object> attributes = user.getAttributes();
    Object rolesObject = attributes.get(UserAttributeNameConstants.ROLE_CODES);
    if (!(rolesObject instanceof Collection)) {
        return R.ok(new ArrayList<>());
    }
    @SuppressWarnings("unchecked") Collection<String> roleCodes = (Collection<String>) rolesObject;
    if (CollectionUtil.isEmpty(roleCodes)) {
        return R.ok(new ArrayList<>());
    }
    // 获取符合条件的权限
    Set<SysMenu> all = new HashSet<>();
    roleCodes.forEach(roleCode -> all.addAll(sysMenuService.listByRoleCode(roleCode)));
    // 筛选出菜单
    List<SysMenuRouterVO> menuVOList = all.stream().filter(menuVo -> SysMenuType.BUTTON.getValue() != menuVo.getType()).sorted(Comparator.comparingInt(SysMenu::getSort)).map(SysMenuConverter.INSTANCE::poToRouterVo).collect(Collectors.toList());
    return R.ok(menuVOList);
}
Also used : SysMenuUpdateDTO(com.hccake.ballcat.system.model.dto.SysMenuUpdateDTO) PathVariable(org.springframework.web.bind.annotation.PathVariable) SysMenuConverter(com.hccake.ballcat.system.converter.SysMenuConverter) SysMenuRouterVO(com.hccake.ballcat.system.model.vo.SysMenuRouterVO) SysMenuService(com.hccake.ballcat.system.service.SysMenuService) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequiredArgsConstructor(lombok.RequiredArgsConstructor) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ArrayList(java.util.ArrayList) RequestBody(org.springframework.web.bind.annotation.RequestBody) Valid(javax.validation.Valid) HashSet(java.util.HashSet) R(com.hccake.ballcat.common.model.result.R) UserAttributeNameConstants(com.hccake.ballcat.common.security.constant.UserAttributeNameConstants) Operation(io.swagger.v3.oas.annotations.Operation) PutMapping(org.springframework.web.bind.annotation.PutMapping) Map(java.util.Map) UpdateOperationLogging(com.hccake.ballcat.common.log.operation.annotation.UpdateOperationLogging) GetMapping(org.springframework.web.bind.annotation.GetMapping) SysMenuQO(com.hccake.ballcat.system.model.qo.SysMenuQO) SysMenu(com.hccake.ballcat.system.model.entity.SysMenu) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) PostMapping(org.springframework.web.bind.annotation.PostMapping) SecurityUtils(com.hccake.ballcat.common.security.util.SecurityUtils) SysMenuType(com.hccake.ballcat.system.enums.SysMenuType) CollectionUtil(cn.hutool.core.collection.CollectionUtil) BaseResultCode(com.hccake.ballcat.common.model.result.BaseResultCode) Collection(java.util.Collection) Set(java.util.Set) RestController(org.springframework.web.bind.annotation.RestController) Collectors(java.util.stream.Collectors) User(com.hccake.ballcat.common.security.userdetails.User) CreateOperationLogging(com.hccake.ballcat.common.log.operation.annotation.CreateOperationLogging) List(java.util.List) SysMenuPageVO(com.hccake.ballcat.system.model.vo.SysMenuPageVO) SysMenuCreateDTO(com.hccake.ballcat.system.model.dto.SysMenuCreateDTO) Tag(io.swagger.v3.oas.annotations.tags.Tag) SysMenuGrantVO(com.hccake.ballcat.system.model.vo.SysMenuGrantVO) Comparator(java.util.Comparator) DeleteOperationLogging(com.hccake.ballcat.common.log.operation.annotation.DeleteOperationLogging) User(com.hccake.ballcat.common.security.userdetails.User) SysMenuConverter(com.hccake.ballcat.system.converter.SysMenuConverter) SysMenuRouterVO(com.hccake.ballcat.system.model.vo.SysMenuRouterVO) SysMenu(com.hccake.ballcat.system.model.entity.SysMenu) Collection(java.util.Collection) HashSet(java.util.HashSet) GetMapping(org.springframework.web.bind.annotation.GetMapping) Operation(io.swagger.v3.oas.annotations.Operation)

Aggregations

CollectionUtil (cn.hutool.core.collection.CollectionUtil)1 CreateOperationLogging (com.hccake.ballcat.common.log.operation.annotation.CreateOperationLogging)1 DeleteOperationLogging (com.hccake.ballcat.common.log.operation.annotation.DeleteOperationLogging)1 UpdateOperationLogging (com.hccake.ballcat.common.log.operation.annotation.UpdateOperationLogging)1 BaseResultCode (com.hccake.ballcat.common.model.result.BaseResultCode)1 R (com.hccake.ballcat.common.model.result.R)1 UserAttributeNameConstants (com.hccake.ballcat.common.security.constant.UserAttributeNameConstants)1 User (com.hccake.ballcat.common.security.userdetails.User)1 SecurityUtils (com.hccake.ballcat.common.security.util.SecurityUtils)1 SysMenuConverter (com.hccake.ballcat.system.converter.SysMenuConverter)1 SysMenuType (com.hccake.ballcat.system.enums.SysMenuType)1 SysMenuCreateDTO (com.hccake.ballcat.system.model.dto.SysMenuCreateDTO)1 SysMenuUpdateDTO (com.hccake.ballcat.system.model.dto.SysMenuUpdateDTO)1 SysMenu (com.hccake.ballcat.system.model.entity.SysMenu)1 SysMenuQO (com.hccake.ballcat.system.model.qo.SysMenuQO)1 SysMenuGrantVO (com.hccake.ballcat.system.model.vo.SysMenuGrantVO)1 SysMenuPageVO (com.hccake.ballcat.system.model.vo.SysMenuPageVO)1 SysMenuRouterVO (com.hccake.ballcat.system.model.vo.SysMenuRouterVO)1 SysMenuService (com.hccake.ballcat.system.service.SysMenuService)1 Operation (io.swagger.v3.oas.annotations.Operation)1