Search in sources :

Example 11 with BusinessException

use of com.company.project.common.exception.BusinessException in project springboot-manager by aitangbao.

the class DeptServiceImpl method deleted.

@Override
public void deleted(String id) {
    SysDept sysDept = sysDeptMapper.selectById(id);
    if (null == sysDept) {
        throw new BusinessException(BaseResponseCode.DATA_ERROR);
    }
    List<Object> deptIds = sysDeptMapper.selectObjs(Wrappers.<SysDept>lambdaQuery().select(SysDept::getId).likeRight(SysDept::getRelationCode, sysDept.getRelationCode()));
    List<SysUser> list = sysUserMapper.selectList(Wrappers.<SysUser>lambdaQuery().in(SysUser::getDeptId, deptIds));
    if (!CollectionUtils.isEmpty(list)) {
        throw new BusinessException(BaseResponseCode.NOT_PERMISSION_DELETED_DEPT);
    }
    sysDeptMapper.deleteById(id);
}
Also used : BusinessException(com.company.project.common.exception.BusinessException) SysUser(com.company.project.entity.SysUser) SysDept(com.company.project.entity.SysDept)

Example 12 with BusinessException

use of com.company.project.common.exception.BusinessException 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 13 with BusinessException

use of com.company.project.common.exception.BusinessException 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)

Example 14 with BusinessException

use of com.company.project.common.exception.BusinessException in project springboot-manager by aitangbao.

the class DeptServiceImpl method updateDept.

@Override
@Transactional(rollbackFor = Exception.class)
public void updateDept(SysDept vo) {
    SysDept sysDept = sysDeptMapper.selectById(vo.getId());
    if (null == sysDept) {
        throw new BusinessException(BaseResponseCode.DATA_ERROR);
    }
    sysDeptMapper.updateById(vo);
    // 说明层级发生了变化
    if (!StringUtils.isEmpty(vo.getPid()) && !vo.getPid().equals(sysDept.getPid())) {
        SysDept parent = sysDeptMapper.selectById(vo.getPid());
        if (!"0".equals(vo.getPid()) && null == parent) {
            throw new BusinessException(BaseResponseCode.DATA_ERROR);
        }
        SysDept oldParent = sysDeptMapper.selectById(sysDept.getPid());
        String oldRelationCode;
        String newRelationCode;
        // 根目录降到其他目录
        if ("0".equals(sysDept.getPid())) {
            oldRelationCode = sysDept.getDeptNo();
            newRelationCode = parent.getRelationCode() + sysDept.getDeptNo();
        } else if ("0".equals(vo.getPid())) {
            // 其他目录升级到跟目录
            oldRelationCode = sysDept.getRelationCode();
            newRelationCode = sysDept.getDeptNo();
        } else {
            oldRelationCode = oldParent.getRelationCode();
            newRelationCode = parent.getRelationCode();
        }
        LambdaQueryWrapper<SysDept> wrapper = Wrappers.lambdaQuery();
        wrapper.likeLeft(SysDept::getDeptNo, sysDept.getDeptNo());
        List<SysDept> list = sysDeptMapper.selectList(wrapper);
        list.parallelStream().forEach(entity -> {
            String relationCode = entity.getRelationCode().replace(oldRelationCode, newRelationCode);
            entity.setRelationCode(relationCode);
            sysDeptMapper.updateById(entity);
        });
    }
}
Also used : BusinessException(com.company.project.common.exception.BusinessException) SysDept(com.company.project.entity.SysDept) Transactional(org.springframework.transaction.annotation.Transactional)

Example 15 with BusinessException

use of com.company.project.common.exception.BusinessException in project springboot-manager by aitangbao.

the class DeptServiceImpl method deptTreeList.

@Override
public List<DeptRespNodeVO> deptTreeList(String deptId, Boolean disabled) {
    List<SysDept> list;
    if (StringUtils.isEmpty(deptId)) {
        list = sysDeptMapper.selectList(Wrappers.emptyWrapper());
    } else {
        SysDept sysDept = sysDeptMapper.selectById(deptId);
        if (sysDept == null) {
            throw new BusinessException(BaseResponseCode.DATA_ERROR);
        }
        LambdaQueryWrapper<SysDept> queryWrapper = Wrappers.<SysDept>lambdaQuery().likeRight(SysDept::getRelationCode, sysDept.getRelationCode());
        List<Object> childIds = sysDeptMapper.selectObjs(queryWrapper);
        list = sysDeptMapper.selectList(Wrappers.<SysDept>lambdaQuery().notIn(SysDept::getId, childIds));
    }
    // 默认加一个顶级方便新增顶级部门
    DeptRespNodeVO respNodeVO = new DeptRespNodeVO();
    respNodeVO.setTitle("默认顶级部门");
    respNodeVO.setId("0");
    respNodeVO.setSpread(true);
    respNodeVO.setDisabled(disabled);
    respNodeVO.setChildren(getTree(list));
    List<DeptRespNodeVO> result = new ArrayList<>();
    result.add(respNodeVO);
    return result;
}
Also used : DeptRespNodeVO(com.company.project.vo.resp.DeptRespNodeVO) BusinessException(com.company.project.common.exception.BusinessException) SysDept(com.company.project.entity.SysDept) ArrayList(java.util.ArrayList)

Aggregations

BusinessException (com.company.project.common.exception.BusinessException)24 SysUser (com.company.project.entity.SysUser)7 SysDept (com.company.project.entity.SysDept)5 SysPermission (com.company.project.entity.SysPermission)3 SysRolePermission (com.company.project.entity.SysRolePermission)3 Transactional (org.springframework.transaction.annotation.Transactional)3 SysRole (com.company.project.entity.SysRole)2 DeptRespNodeVO (com.company.project.vo.resp.DeptRespNodeVO)2 IOException (java.io.IOException)2 JSONObject (com.alibaba.fastjson.JSONObject)1 LogAnnotation (com.company.project.common.aop.annotation.LogAnnotation)1 ColumnEntity (com.company.project.entity.ColumnEntity)1 SysDictDetailEntity (com.company.project.entity.SysDictDetailEntity)1 SysDictEntity (com.company.project.entity.SysDictEntity)1 SysFilesEntity (com.company.project.entity.SysFilesEntity)1 SysJobEntity (com.company.project.entity.SysJobEntity)1 SysRoleDeptEntity (com.company.project.entity.SysRoleDeptEntity)1 TableEntity (com.company.project.entity.TableEntity)1 RolePermissionOperationReqVO (com.company.project.vo.req.RolePermissionOperationReqVO)1 UserRoleOperationReqVO (com.company.project.vo.req.UserRoleOperationReqVO)1