Search in sources :

Example 1 with SysPermission

use of com.company.project.entity.SysPermission in project springboot-manager by aitangbao.

the class PermissionServiceImpl method getChildAll.

/**
 * 递归遍历所有
 */
private List<PermissionRespNode> getChildAll(String id, List<SysPermission> all) {
    List<PermissionRespNode> list = new ArrayList<>();
    for (SysPermission sysPermission : all) {
        if (sysPermission.getPid().equals(id)) {
            PermissionRespNode permissionRespNode = new PermissionRespNode();
            BeanUtils.copyProperties(sysPermission, permissionRespNode);
            permissionRespNode.setTitle(sysPermission.getName());
            permissionRespNode.setChildren(getChildAll(sysPermission.getId(), all));
            list.add(permissionRespNode);
        }
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) SysPermission(com.company.project.entity.SysPermission) PermissionRespNode(com.company.project.vo.resp.PermissionRespNode)

Example 2 with SysPermission

use of com.company.project.entity.SysPermission in project springboot-manager by aitangbao.

the class PermissionServiceImpl method getChildExcBtn.

/**
 * 只递归获取目录和菜单
 */
private List<PermissionRespNode> getChildExcBtn(String id, List<SysPermission> all) {
    List<PermissionRespNode> list = new ArrayList<>();
    for (SysPermission sysPermission : all) {
        if (sysPermission.getPid().equals(id) && sysPermission.getType() != 3) {
            PermissionRespNode permissionRespNode = new PermissionRespNode();
            BeanUtils.copyProperties(sysPermission, permissionRespNode);
            permissionRespNode.setTitle(sysPermission.getName());
            permissionRespNode.setChildren(getChildExcBtn(sysPermission.getId(), all));
            list.add(permissionRespNode);
        }
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) SysPermission(com.company.project.entity.SysPermission) PermissionRespNode(com.company.project.vo.resp.PermissionRespNode)

Example 3 with SysPermission

use of com.company.project.entity.SysPermission in project springboot-manager by aitangbao.

the class PermissionServiceImpl method getTree.

/**
 * 递归获取菜单树
 */
private List<PermissionRespNode> getTree(List<SysPermission> all, boolean type) {
    List<PermissionRespNode> list = new ArrayList<>();
    if (CollectionUtils.isEmpty(all)) {
        return list;
    }
    for (SysPermission sysPermission : all) {
        if ("0".equals(sysPermission.getPid())) {
            PermissionRespNode permissionRespNode = new PermissionRespNode();
            BeanUtils.copyProperties(sysPermission, permissionRespNode);
            permissionRespNode.setTitle(sysPermission.getName());
            if (type) {
                permissionRespNode.setChildren(getChildExcBtn(sysPermission.getId(), all));
            } else {
                permissionRespNode.setChildren(getChildAll(sysPermission.getId(), all));
            }
            list.add(permissionRespNode);
        }
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) SysPermission(com.company.project.entity.SysPermission) PermissionRespNode(com.company.project.vo.resp.PermissionRespNode)

Example 4 with SysPermission

use of com.company.project.entity.SysPermission in project springboot-manager by aitangbao.

the class PermissionController method updatePermission.

@PutMapping("/permission")
@ApiOperation(value = "更新菜单权限接口")
@LogAnnotation(title = "菜单权限管理", action = "更新菜单权限")
@RequiresPermissions("sys:permission:update")
public DataResult updatePermission(@RequestBody @Valid SysPermission vo) {
    if (StringUtils.isEmpty(vo.getId())) {
        return DataResult.fail("id不能为空");
    }
    SysPermission sysPermission = permissionService.getById(vo.getId());
    if (null == sysPermission) {
        throw new BusinessException(BaseResponseCode.DATA_ERROR);
    }
    // 只有类型变更或者所属菜单变更
    if (sysPermission.getType().equals(vo.getType()) || !sysPermission.getPid().equals(vo.getPid())) {
        verifyFormPid(vo);
    }
    permissionService.updatePermission(vo);
    return DataResult.success();
}
Also used : BusinessException(com.company.project.common.exception.BusinessException) SysPermission(com.company.project.entity.SysPermission) LogAnnotation(com.company.project.common.aop.annotation.LogAnnotation) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) ApiOperation(io.swagger.annotations.ApiOperation)

Example 5 with SysPermission

use of com.company.project.entity.SysPermission in project springboot-manager by aitangbao.

the class PermissionController method verifyFormPid.

/**
 * 操作后的菜单类型是目录的时候 父级必须为目录
 * 操作后的菜单类型是菜单的时候,父类必须为目录类型
 * 操作后的菜单类型是按钮的时候 父类必须为菜单类型
 */
private void verifyFormPid(SysPermission sysPermission) {
    SysPermission parent;
    parent = permissionService.getById(sysPermission.getPid());
    switch(sysPermission.getType()) {
        case 1:
            if (parent != null) {
                if (parent.getType() != 1) {
                    throw new BusinessException(BaseResponseCode.OPERATION_MENU_PERMISSION_CATALOG_ERROR);
                }
            } else if (!"0".equals(sysPermission.getPid())) {
                throw new BusinessException(BaseResponseCode.OPERATION_MENU_PERMISSION_CATALOG_ERROR);
            }
            break;
        case 2:
            if (parent == null || parent.getType() != 1) {
                throw new BusinessException(BaseResponseCode.OPERATION_MENU_PERMISSION_MENU_ERROR);
            }
            if (StringUtils.isEmpty(sysPermission.getUrl())) {
                throw new BusinessException(BaseResponseCode.OPERATION_MENU_PERMISSION_URL_NOT_NULL);
            }
            break;
        case 3:
            if (parent == null || parent.getType() != 2) {
                throw new BusinessException(BaseResponseCode.OPERATION_MENU_PERMISSION_BTN_ERROR);
            }
            if (StringUtils.isEmpty(sysPermission.getPerms())) {
                throw new BusinessException(BaseResponseCode.OPERATION_MENU_PERMISSION_URL_PERMS_NULL);
            }
            if (StringUtils.isEmpty(sysPermission.getUrl())) {
                throw new BusinessException(BaseResponseCode.OPERATION_MENU_PERMISSION_URL_NOT_NULL);
            }
            break;
        default:
    }
}
Also used : BusinessException(com.company.project.common.exception.BusinessException) SysPermission(com.company.project.entity.SysPermission)

Aggregations

SysPermission (com.company.project.entity.SysPermission)8 PermissionRespNode (com.company.project.vo.resp.PermissionRespNode)4 ArrayList (java.util.ArrayList)4 BusinessException (com.company.project.common.exception.BusinessException)3 LogAnnotation (com.company.project.common.aop.annotation.LogAnnotation)1 SysRolePermission (com.company.project.entity.SysRolePermission)1 ApiOperation (io.swagger.annotations.ApiOperation)1 HashSet (java.util.HashSet)1 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)1 Transactional (org.springframework.transaction.annotation.Transactional)1