Search in sources :

Example 16 with BusinessException

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

the class PermissionServiceImpl method deleted.

/**
 * 删除菜单权限
 * 判断是否 有角色关联
 * 判断是否有子集
 */
@Transactional(rollbackFor = Exception.class)
@Override
public void deleted(String permissionId) {
    // 获取关联userId
    List<String> userIds = getUserIdsById(permissionId);
    SysPermission sysPermission = sysPermissionMapper.selectById(permissionId);
    if (null == sysPermission) {
        log.error("传入 的 id:{}不合法", permissionId);
        throw new BusinessException(BaseResponseCode.DATA_ERROR);
    }
    // 获取下一级
    List<SysPermission> childs = sysPermissionMapper.selectList(Wrappers.<SysPermission>lambdaQuery().eq(SysPermission::getPid, permissionId));
    if (!CollectionUtils.isEmpty(childs)) {
        throw new BusinessException(BaseResponseCode.ROLE_PERMISSION_RELATION);
    }
    sysPermissionMapper.deleteById(permissionId);
    // 删除和角色关联
    rolePermissionService.remove(Wrappers.<SysRolePermission>lambdaQuery().eq(SysRolePermission::getPermissionId, permissionId));
    if (!CollectionUtils.isEmpty(userIds)) {
        // 刷新权限
        userIds.parallelStream().forEach(httpSessionService::refreshUerId);
    }
}
Also used : SysRolePermission(com.company.project.entity.SysRolePermission) BusinessException(com.company.project.common.exception.BusinessException) SysPermission(com.company.project.entity.SysPermission) Transactional(org.springframework.transaction.annotation.Transactional)

Example 17 with BusinessException

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

the class RoleServiceImpl method detailInfo.

@Override
public SysRole detailInfo(String id) {
    SysRole sysRole = sysRoleMapper.selectById(id);
    if (sysRole == null) {
        log.error("传入 的 id:{}不合法", id);
        throw new BusinessException(BaseResponseCode.DATA_ERROR);
    }
    List<PermissionRespNode> permissionRespNodes = permissionService.selectAllByTree();
    LambdaQueryWrapper<SysRolePermission> queryWrapper = Wrappers.<SysRolePermission>lambdaQuery().select(SysRolePermission::getPermissionId).eq(SysRolePermission::getRoleId, sysRole.getId());
    Set<Object> checkList = new HashSet<>(rolePermissionService.listObjs(queryWrapper));
    setChecked(permissionRespNodes, checkList);
    sysRole.setPermissionRespNodes(permissionRespNodes);
    LambdaQueryWrapper<SysRoleDeptEntity> queryWrapperDept = Wrappers.<SysRoleDeptEntity>lambdaQuery().select(SysRoleDeptEntity::getDeptId).eq(SysRoleDeptEntity::getRoleId, sysRole.getId());
    List<DeptRespNodeVO> deptRespNodes = deptService.deptTreeList(null, true);
    Set<Object> checkDeptList = new HashSet<>(sysRoleDeptService.listObjs(queryWrapperDept));
    setCheckedDept(deptRespNodes, checkDeptList);
    sysRole.setDeptRespNodes(deptRespNodes);
    return sysRole;
}
Also used : SysRolePermission(com.company.project.entity.SysRolePermission) PermissionRespNode(com.company.project.vo.resp.PermissionRespNode) DeptRespNodeVO(com.company.project.vo.resp.DeptRespNodeVO) BusinessException(com.company.project.common.exception.BusinessException) SysRole(com.company.project.entity.SysRole) SysRoleDeptEntity(com.company.project.entity.SysRoleDeptEntity) HashSet(java.util.HashSet)

Example 18 with BusinessException

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

the class RoleServiceImpl method updateRole.

@Transactional(rollbackFor = Exception.class)
@Override
public void updateRole(SysRole vo) {
    SysRole sysRole = sysRoleMapper.selectById(vo.getId());
    if (null == sysRole) {
        log.error("传入 的 id:{}不合法", vo.getId());
        throw new BusinessException(BaseResponseCode.DATA_ERROR);
    }
    sysRoleMapper.updateById(vo);
    // 删除角色权限关联
    rolePermissionService.remove(Wrappers.<SysRolePermission>lambdaQuery().eq(SysRolePermission::getRoleId, sysRole.getId()));
    if (!CollectionUtils.isEmpty(vo.getPermissions())) {
        RolePermissionOperationReqVO reqVO = new RolePermissionOperationReqVO();
        reqVO.setRoleId(sysRole.getId());
        reqVO.setPermissionIds(vo.getPermissions());
        rolePermissionService.addRolePermission(reqVO);
        // 刷新权限
        httpSessionService.refreshRolePermission(sysRole.getId());
    }
}
Also used : SysRolePermission(com.company.project.entity.SysRolePermission) BusinessException(com.company.project.common.exception.BusinessException) SysRole(com.company.project.entity.SysRole) RolePermissionOperationReqVO(com.company.project.vo.req.RolePermissionOperationReqVO) Transactional(org.springframework.transaction.annotation.Transactional)

Example 19 with BusinessException

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

the class SysFilesServiceImpl method saveFile.

@Override
public DataResult saveFile(MultipartFile file) {
    // 存储文件夹
    String createTime = DateUtils.format(new Date(), DateUtils.DATEPATTERN);
    String newPath = fileUploadProperties.getPath() + createTime + File.separator;
    File uploadDirectory = new File(newPath);
    if (uploadDirectory.exists()) {
        if (!uploadDirectory.isDirectory()) {
            uploadDirectory.delete();
        }
    } else {
        uploadDirectory.mkdir();
    }
    try {
        String fileName = file.getOriginalFilename();
        // id与filename保持一直,删除文件
        String fileNameNew = UUID.randomUUID().toString().replace("-", "") + getFileType(fileName);
        String newFilePathName = newPath + fileNameNew;
        String url = fileUploadProperties.getUrl() + "/" + createTime + "/" + fileNameNew;
        // 创建输出文件对象
        File outFile = new File(newFilePathName);
        // 拷贝文件到输出文件对象
        FileUtils.copyInputStreamToFile(file.getInputStream(), outFile);
        // 保存文件记录
        SysFilesEntity sysFilesEntity = new SysFilesEntity();
        sysFilesEntity.setFileName(fileName);
        sysFilesEntity.setFilePath(newFilePathName);
        sysFilesEntity.setUrl(url);
        this.save(sysFilesEntity);
        Map<String, String> resultMap = new HashMap<>();
        resultMap.put("src", url);
        return DataResult.success(resultMap);
    } catch (Exception e) {
        throw new BusinessException("上传文件失败");
    }
}
Also used : BusinessException(com.company.project.common.exception.BusinessException) File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile) SysFilesEntity(com.company.project.entity.SysFilesEntity) BusinessException(com.company.project.common.exception.BusinessException)

Example 20 with BusinessException

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

the class SysJobServiceImpl method updateJobById.

@Override
public void updateJobById(SysJobEntity sysJob) {
    SysJobEntity sysJobEntity = this.getById(sysJob.getId());
    if (sysJobEntity == null) {
        throw new BusinessException("获取定时任务异常");
    }
    sysJob.setStatus(sysJobEntity.getStatus());
    ScheduleUtils.updateScheduleJob(scheduler, sysJob);
    this.updateById(sysJob);
}
Also used : BusinessException(com.company.project.common.exception.BusinessException) SysJobEntity(com.company.project.entity.SysJobEntity)

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