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