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;
}
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;
}
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;
}
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();
}
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:
}
}
Aggregations