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);
}
}
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;
}
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());
}
}
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("上传文件失败");
}
}
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);
}
Aggregations