feat: (feature/REQ-2595) 菜单管理编辑角色权限增加角色权限标签

This commit is contained in:
lilong 2024-10-29 16:01:31 +08:00
parent 714022be90
commit 69da738ffb
2 changed files with 28 additions and 10 deletions

View File

@ -37,12 +37,20 @@ public class FeatureRoleRelationReq {
private Integer featureType;
/** 应用的角色Id列表 **/
private List<Long> roleIds;
private Set<Role> roles;
/** 授权类型 0-全部角色 1-指定角色 **/
private Integer authType;
private String terminal;
}
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public static class Role {
private Long roleId;
/**
* 权限标签默认为JOINED

View File

@ -1596,7 +1596,7 @@ public class RoleServiceImpl extends ServiceImpl<SaasRoleMapper, SaasRole>
for (FeatureRoleRelationReq.RelationRoleSettings item : req) {
saasFeatureResourceService.updateFeatureAuthType(item.getFeatureId(), item.getAuthType());
if (CollectionUtil.isEmpty(item.getRoleIds()) || item.getAuthType() == 0) {
if (CollectionUtil.isEmpty(item.getRoles()) || item.getAuthType() == 0) {
saasPgroupPermissionRelationDao.removeByPermissionPointIds(Collections.singletonList(item.getFeatureId()));
// 记录操作日志
try {
@ -1608,28 +1608,38 @@ public class RoleServiceImpl extends ServiceImpl<SaasRoleMapper, SaasRole>
List<Long> existGroupIds = saasPgroupPermissionRelationDao.queryByFeatureIds(Collections.singletonList(item.getFeatureId()))
.stream().map(SaasPgroupPermissionRelation::getGroupId).collect(Collectors.toList());
List<Long> groupIds = saasPgroupRoleRelationDao.findByRoleIds(item.getRoleIds())
.stream().map(SaasPgroupRoleRelation::getGroupId).collect(Collectors.toList());
List<Long> insertGroupIds = groupIds.stream().filter(role -> !existGroupIds.contains(role)).collect(Collectors.toList());
List<Long> roleIds = item.getRoles().stream()
.map(FeatureRoleRelationReq.Role::getRoleId)
.collect(Collectors.toList());
List<SaasPgroupRoleRelation> saasPgroupRoleRelations = saasPgroupRoleRelationDao.findByRoleIds(roleIds);
List<Long> groupIds = saasPgroupRoleRelations.stream().map(SaasPgroupRoleRelation::getGroupId).collect(Collectors.toList());
List<Long> deleteGroupIds = existGroupIds.stream().filter(role -> !groupIds.contains(role)).collect(Collectors.toList());
List<SaasPgroupRoleRelation> insert = saasPgroupRoleRelations.stream()
.filter(e -> !existGroupIds.contains(e.getGroupId()))
.collect(Collectors.toList());
Map<Long, FeatureRoleRelationReq.Role> roles = item.getRoles().stream()
.collect(Collectors.toMap(FeatureRoleRelationReq.Role::getRoleId, Function.identity(), (f, s) -> f));
// 记录操作日志
try {
saveOperateLog(item.getFeatureId(), operatorId, item.getRoleIds(), req);
saveOperateLog(item.getFeatureId(), operatorId, roleIds, req);
} catch (Exception e) {
log.warn("save operate log error", e);
}
// 新增的
if (CollectionUtils.isNotEmpty(insertGroupIds)) {
if (CollectionUtils.isNotEmpty(insert)) {
List<SaasPgroupPermissionRelation> insertRelation = new ArrayList<>();
insertGroupIds.forEach(groupId -> {
insert.forEach(group -> {
FeatureRoleRelationReq.Role role = roles.get(group.getRoleId());
SaasPgroupPermissionRelation relation = new SaasPgroupPermissionRelation();
relation.setFeatureId(item.getFeatureId());
relation.setGroupId(groupId);
relation.setGroupId(group.getGroupId());
relation.setCreateBy(operatorId);
relation.setFeatureType(item.getFeatureType());
relation.setType(NEW_FEATURE);
relation.setTerminal(item.getTerminal());
relation.setTags(Optional.ofNullable(item.getTags())
relation.setTags(Optional.ofNullable(role.getTags())
.orElseGet(() -> Sets.newHashSet(RolePermissionTagEnum.JOINED)));
insertRelation.add(relation);
});