feat:(REQ-2699) 修改角色权限时,增加roleId,方便快速准确更新角色权限
This commit is contained in:
parent
e3a970dc32
commit
a2dede09af
@ -52,9 +52,6 @@ public class FeatureResourceTreeSaveReq extends BaseFeatureResourceDO {
|
||||
/** 页面组件对象 **/
|
||||
private List<FeatureComponentSaveReq> componentSaveReqList;
|
||||
|
||||
/** 页面及组件权限对象 **/
|
||||
private List<RolePermissionSaveReq> permissions;
|
||||
|
||||
@NotNull(message = "操作人ID不能为空")
|
||||
private Long operatorId;
|
||||
|
||||
|
||||
@ -26,6 +26,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
@ -80,7 +81,9 @@ public class CacheRolePermissionHandler implements InitializingBean {
|
||||
// }
|
||||
|
||||
RoleService.ListSaasRoleParam listSaasRoleParam = RoleService.ListSaasRoleParam.builder()
|
||||
// .roleIds(Lists.newArrayList(payload.getRoleIds()))
|
||||
.roleIds(Optional.ofNullable(payload.getRoleIds())
|
||||
.map(Lists::newArrayList)
|
||||
.orElse(null))
|
||||
.needPermissionRelation(true)
|
||||
.build();
|
||||
List<SaasRoleRes> roles = roleService.list(listSaasRoleParam);
|
||||
|
||||
@ -24,6 +24,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -68,12 +69,16 @@ public class CacheRoleSaasFeatureResourceHandler implements InitializingBean {
|
||||
log.info("begin cached role saasFeatureResource handler rocketmq event: {}", event);
|
||||
RolePermissionCreatedPayload payload = event.normalizedData(RolePermissionCreatedPayload.class);
|
||||
|
||||
if (CollectionUtils.isEmpty(payload.getRoleIds())) {
|
||||
return;
|
||||
}
|
||||
// 影响角色权限入口的代码没法简单重构,导致发送的roleIds可能不准确,所以一旦有角色权限的更新事件后,全量更新角色权限,角色权限数量不多
|
||||
// 后续收口了代码就准确根据角色去更新缓存
|
||||
// if (CollectionUtils.isEmpty(payload.getRoleIds())) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
RoleService.ListSaasRoleParam listSaasRoleParam = RoleService.ListSaasRoleParam.builder()
|
||||
.roleIds(Lists.newArrayList(payload.getRoleIds()))
|
||||
.roleIds(Optional.ofNullable(payload.getRoleIds())
|
||||
.map(Lists::newArrayList)
|
||||
.orElse(null))
|
||||
.needPermissionRelation(true)
|
||||
.type(NEW_FEATURE)
|
||||
.build();
|
||||
|
||||
@ -353,13 +353,11 @@ public class FeatureResourceSyncServiceImpl implements FeatureResourceSyncServic
|
||||
logResourceBindRoleDO.setRoleCodes(saasRoles.stream().filter(e -> existRoleIds.contains(e.getId())).map(SaasRole::getRoleCode).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
// 同步这里不要求效率,没有角色id,全部刷新,也不容易找这个
|
||||
Event event = Event.builder()
|
||||
.targetType(ROLE_PERMISSION_TARGET_TYPE)
|
||||
.eventCode(ROLE_PERMISSION_CREATED.getEventCode())
|
||||
.data(RolePermissionCreatedPayload.builder()
|
||||
.roleIds(saasRoles.stream()
|
||||
.map(SaasRole::getId)
|
||||
.collect(Collectors.toSet()))
|
||||
.build())
|
||||
.build();
|
||||
mqProducer.send(event);
|
||||
|
||||
@ -1338,9 +1338,43 @@ public class RoleServiceImpl extends ServiceImpl<SaasRoleMapper, SaasRole>
|
||||
return saasRoleGroupRes;
|
||||
}
|
||||
|
||||
private Set<Long> resolveUpsertRoleIds(List<FeatureRoleRelationReq.RelationRoleSettings> req) {
|
||||
if (CollectionUtils.isEmpty(req)) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
Set<Long> newRoleIds = req.stream()
|
||||
.map(FeatureRoleRelationReq.RelationRoleSettings::getRoleIds)
|
||||
.flatMap(Collection::stream)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
List<Long> featureIds = req.stream()
|
||||
.map(FeatureRoleRelationReq.RelationRoleSettings::getFeatureId)
|
||||
.collect(Collectors.toList());
|
||||
PagePgroupPermissionRelationReq pagePgroupPermissionRelationReq = PagePgroupPermissionRelationReq.builder()
|
||||
.featureIds(featureIds)
|
||||
.build();
|
||||
List<Long> groupIds = saasPgroupPermissionRelationService.list(pagePgroupPermissionRelationReq).stream()
|
||||
.map(SaasPgroupPermissionRelation::getGroupId)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (CollectionUtils.isEmpty(groupIds)) {
|
||||
return newRoleIds;
|
||||
}
|
||||
|
||||
Set<Long> oldRoleIds = saasPgroupRoleRelationDao.listByGroupIds(groupIds).stream()
|
||||
.map(SaasPgroupRoleRelation::getRoleId)
|
||||
.collect(Collectors.toSet());
|
||||
newRoleIds.addAll(oldRoleIds);
|
||||
return newRoleIds;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void saveOrUpdateFeatureRoleRelation(List<FeatureRoleRelationReq.RelationRoleSettings> req, Long operatorId) {
|
||||
// 查询权限点的历史角色,发送mq
|
||||
Set<Long> allRoleIds = resolveUpsertRoleIds(req);
|
||||
|
||||
for (FeatureRoleRelationReq.RelationRoleSettings item : req) {
|
||||
saasFeatureResourceService.updateFeatureAuthType(item.getFeatureId(), item.getAuthType());
|
||||
if (CollectionUtil.isEmpty(item.getRoleIds()) || item.getAuthType() == 0) {
|
||||
@ -1417,6 +1451,7 @@ public class RoleServiceImpl extends ServiceImpl<SaasRoleMapper, SaasRole>
|
||||
.targetType("saasFeatureResourceId")
|
||||
.eventCode(ROLE_PERMISSION_CREATED.getEventCode())
|
||||
.data(RolePermissionCreatedPayload.builder()
|
||||
.roleIds(allRoleIds)
|
||||
.build())
|
||||
.build());
|
||||
}
|
||||
|
||||
@ -314,14 +314,6 @@ public class SaasFeatureResourceServiceImpl extends ServiceImpl<SaasFeatureResou
|
||||
.build())
|
||||
.build();
|
||||
mqProducer.send(event);
|
||||
|
||||
// 待收口后,这个事件需要放在角色权限的upsert方法里
|
||||
mqProducer.send(Event.builder()
|
||||
.targetType("saasFeatureResourceId")
|
||||
.eventCode(ROLE_PERMISSION_CREATED.getEventCode())
|
||||
.data(RolePermissionCreatedPayload.builder()
|
||||
.build())
|
||||
.build());
|
||||
return baseResource.getId();
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user