feat: (feature/REQ-2595) 修改角色权限时,增加更新操作

This commit is contained in:
lilong 2024-10-31 17:14:22 +08:00
parent eab3cb770c
commit 9c34e9cd89
3 changed files with 58 additions and 14 deletions

View File

@ -130,8 +130,14 @@ public class PermissionQueryServiceImpl implements PermissionQueryService {
}
List<Long> featureIds = permissions.stream()
.map(PermissionDO::getFeatureIds)
.filter(Objects::nonNull)
.flatMap(Set::stream)
.collect(Collectors.toList());
if (CollectionUtils.isEmpty(featureIds)) {
return Collections.emptyList();
}
//反查资源信息-仅页面
List<SaasFeatureResource> resourceList = featureResourceService.listNavByIds(featureIds, FeatureResourceType.pageTypes());
//查所有上级菜单

View File

@ -1622,6 +1622,11 @@ public class RoleServiceImpl extends ServiceImpl<SaasRoleMapper, SaasRole>
.collect(Collectors.toList());
Map<Long, FeatureRoleRelationReq.Role> roles = item.getRoles().stream()
.collect(Collectors.toMap(FeatureRoleRelationReq.Role::getRoleId, Function.identity(), (f, s) -> f));
List<SaasPgroupRoleRelation> update = saasPgroupRoleRelations.stream()
.filter(e -> existGroupIds.contains(e.getGroupId()))
.collect(Collectors.toList());
// 记录操作日志
try {
saveOperateLog(item.getFeatureId(), operatorId, roleIds, req);
@ -1630,24 +1635,45 @@ public class RoleServiceImpl extends ServiceImpl<SaasRoleMapper, SaasRole>
}
// 新增的
if (CollectionUtils.isNotEmpty(insert)) {
List<SaasPgroupPermissionRelation> insertRelation = new ArrayList<>();
insert.forEach(group -> {
FeatureRoleRelationReq.Role role = roles.get(group.getRoleId());
Set<SaasPgroupPermissionRelation> insertRelation = update.stream()
.map(group -> {
FeatureRoleRelationReq.Role role = roles.get(group.getRoleId());
SaasPgroupPermissionRelation relation = new SaasPgroupPermissionRelation();
relation.setFeatureId(item.getFeatureId());
relation.setGroupId(group.getGroupId());
relation.setCreateBy(operatorId);
relation.setFeatureType(item.getFeatureType());
relation.setType(NEW_FEATURE);
relation.setTerminal(item.getTerminal());
relation.setTags(Optional.ofNullable(role.getTags())
.orElseGet(() -> Sets.newHashSet(RolePermissionTagEnum.JOINED)));
insertRelation.add(relation);
});
SaasPgroupPermissionRelation relation = new SaasPgroupPermissionRelation();
relation.setFeatureId(item.getFeatureId());
relation.setGroupId(group.getGroupId());
relation.setCreateBy(operatorId);
relation.setFeatureType(item.getFeatureType());
relation.setType(NEW_FEATURE);
relation.setTerminal(item.getTerminal());
relation.setTags(Optional.ofNullable(role.getTags())
.orElseGet(() -> Sets.newHashSet(RolePermissionTagEnum.JOINED)));
return relation;
})
.collect(Collectors.toSet());
saasPgroupPermissionRelationDao.saveBatch(insertRelation);
}
// 都一起更新以后可能会新增其他字段需要更新让代码简单也能看到更新时间
if (CollectionUtils.isNotEmpty(update)) {
Set<SaasPgroupPermissionRelation> updateRelation = update.stream()
.map(e -> {
FeatureRoleRelationReq.Role role = roles.get(e.getRoleId());
SaasPgroupPermissionRelation relation = new SaasPgroupPermissionRelation();
relation.setFeatureId(item.getFeatureId());
relation.setGroupId(e.getGroupId());
relation.setCreateBy(operatorId);
relation.setFeatureType(item.getFeatureType());
relation.setType(NEW_FEATURE);
relation.setTerminal(item.getTerminal());
relation.setTags(Optional.ofNullable(role.getTags())
.orElseGet(() -> Sets.newHashSet(RolePermissionTagEnum.JOINED)));
return relation;
})
.collect(Collectors.toSet());
saasPgroupPermissionRelationDao.saveBatch(updateRelation);
}
// 删除的
if (CollectionUtils.isNotEmpty(deleteGroupIds)) {
saasPgroupPermissionRelationDao.removeByFeatureIdAndGroupIds(item.getFeatureId(), deleteGroupIds, operatorId);

View File

@ -27,6 +27,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
@ -71,6 +72,17 @@ public class SaasPgroupPermissionRelationServiceImpl
if (CollectionUtils.isNotEmpty(deleteList)) {
saasPgroupPermissionRelationDao.removeByIds(deleteList.stream().map(SaasPgroupPermissionRelation::getId).sorted().collect(Collectors.toList()));
}
Set<String> existFeatureIdGroupIds = exists.stream()
.map(e -> e.getFeatureId() + "_" + e.getGroupId())
.collect(Collectors.toSet());
List<SaasPgroupPermissionRelation> updates = relations.stream()
.filter(e -> existFeatureIdGroupIds.contains(e.getFeatureId() + "_" + e.getGroupId()))
.collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(updates)) {
saasPgroupPermissionRelationDao.saveBatch(updates);
}
}
@Override