| | |
| | | if (CollUtil.isEmpty(permissions)) { |
| | | throw exception(CRM_PERMISSION_NOT_EXISTS); |
| | | } |
| | | // 校验:数据权限的模块数据编号是一致的不可能存在两个 |
| | | if (convertSet(permissions, CrmPermissionDO::getBizId).size() > 1) { |
| | | // 校验:数据权限必须属于同一个业务类型、同一条业务数据 |
| | | if (convertSet(permissions, CrmPermissionDO::getBizType).size() > 1 |
| | | || convertSet(permissions, CrmPermissionDO::getBizId).size() > 1) { |
| | | throw exception(CRM_PERMISSION_DELETE_FAIL); |
| | | } |
| | | // 校验操作人是否为负责人 |
| | | CrmPermissionDO permission = permissionMapper.selectByBizAndUserId(permissions.get(0).getBizType(), permissions.get(0).getBizId(), userId); |
| | | if (permission == null) { |
| | | throw exception(CRM_PERMISSION_DELETE_DENIED); |
| | | // 负责人只能通过转移操作变更,不能直接移出团队 |
| | | if (anyMatch(permissions, permission -> CrmPermissionLevelEnum.isOwner(permission.getLevel()))) { |
| | | throw exception(CRM_PERMISSION_DELETE_SELF_PERMISSION_FAIL_EXIST_OWNER); |
| | | } |
| | | if (!CrmPermissionLevelEnum.isOwner(permission.getLevel())) { |
| | | |
| | | Integer bizType = permissions.get(0).getBizType(); |
| | | Long bizId = permissions.get(0).getBizId(); |
| | | CrmPermissionDO operatorPermission = permissionMapper.selectByBizAndUserId(bizType, bizId, userId); |
| | | boolean isOwner = operatorPermission != null |
| | | && CrmPermissionLevelEnum.isOwner(operatorPermission.getLevel()); |
| | | if (!isOwner && !isSubordinateOwner(bizType, bizId, userId)) { |
| | | throw exception(CRM_PERMISSION_DELETE_DENIED); |
| | | } |
| | | |
| | |
| | | permissionMapper.deleteByIds(ids); |
| | | } |
| | | |
| | | /** 当前用户的下属是否为该业务数据的负责人 */ |
| | | private boolean isSubordinateOwner(Integer bizType, Long bizId, Long userId) { |
| | | Set<Long> subordinateUserIds = convertSet(adminUserApi.getUserListBySubordinate(userId), AdminUserRespDTO::getId); |
| | | if (CollUtil.isEmpty(subordinateUserIds)) { |
| | | return false; |
| | | } |
| | | return anyMatch(permissionMapper.selectByBizTypeAndBizId(bizType, bizId), |
| | | permission -> subordinateUserIds.contains(permission.getUserId()) |
| | | && CrmPermissionLevelEnum.isOwner(permission.getLevel())); |
| | | } |
| | | |
| | | @Override |
| | | public void deleteSelfPermission(Long id, Long userId) { |
| | | // 校验数据存在且是自己 |