feat: (feature/REQ-2595) 菜单管理编辑角色权限增加角色权限标签
This commit is contained in:
parent
714022be90
commit
69da738ffb
@ -37,12 +37,20 @@ public class FeatureRoleRelationReq {
|
|||||||
private Integer featureType;
|
private Integer featureType;
|
||||||
|
|
||||||
/** 应用的角色Id列表 **/
|
/** 应用的角色Id列表 **/
|
||||||
private List<Long> roleIds;
|
private Set<Role> roles;
|
||||||
|
|
||||||
/** 授权类型 0-全部角色 1-指定角色 **/
|
/** 授权类型 0-全部角色 1-指定角色 **/
|
||||||
private Integer authType;
|
private Integer authType;
|
||||||
|
|
||||||
private String terminal;
|
private String terminal;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public static class Role {
|
||||||
|
private Long roleId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 权限标签:默认为JOINED
|
* 权限标签:默认为JOINED
|
||||||
|
|||||||
@ -1596,7 +1596,7 @@ public class RoleServiceImpl extends ServiceImpl<SaasRoleMapper, SaasRole>
|
|||||||
|
|
||||||
for (FeatureRoleRelationReq.RelationRoleSettings item : req) {
|
for (FeatureRoleRelationReq.RelationRoleSettings item : req) {
|
||||||
saasFeatureResourceService.updateFeatureAuthType(item.getFeatureId(), item.getAuthType());
|
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()));
|
saasPgroupPermissionRelationDao.removeByPermissionPointIds(Collections.singletonList(item.getFeatureId()));
|
||||||
// 记录操作日志
|
// 记录操作日志
|
||||||
try {
|
try {
|
||||||
@ -1608,28 +1608,38 @@ public class RoleServiceImpl extends ServiceImpl<SaasRoleMapper, SaasRole>
|
|||||||
List<Long> existGroupIds = saasPgroupPermissionRelationDao.queryByFeatureIds(Collections.singletonList(item.getFeatureId()))
|
List<Long> existGroupIds = saasPgroupPermissionRelationDao.queryByFeatureIds(Collections.singletonList(item.getFeatureId()))
|
||||||
.stream().map(SaasPgroupPermissionRelation::getGroupId).collect(Collectors.toList());
|
.stream().map(SaasPgroupPermissionRelation::getGroupId).collect(Collectors.toList());
|
||||||
|
|
||||||
List<Long> groupIds = saasPgroupRoleRelationDao.findByRoleIds(item.getRoleIds())
|
List<Long> roleIds = item.getRoles().stream()
|
||||||
.stream().map(SaasPgroupRoleRelation::getGroupId).collect(Collectors.toList());
|
.map(FeatureRoleRelationReq.Role::getRoleId)
|
||||||
List<Long> insertGroupIds = groupIds.stream().filter(role -> !existGroupIds.contains(role)).collect(Collectors.toList());
|
.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<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 {
|
try {
|
||||||
saveOperateLog(item.getFeatureId(), operatorId, item.getRoleIds(), req);
|
saveOperateLog(item.getFeatureId(), operatorId, roleIds, req);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.warn("save operate log error", e);
|
log.warn("save operate log error", e);
|
||||||
}
|
}
|
||||||
// 新增的
|
// 新增的
|
||||||
if (CollectionUtils.isNotEmpty(insertGroupIds)) {
|
if (CollectionUtils.isNotEmpty(insert)) {
|
||||||
List<SaasPgroupPermissionRelation> insertRelation = new ArrayList<>();
|
List<SaasPgroupPermissionRelation> insertRelation = new ArrayList<>();
|
||||||
insertGroupIds.forEach(groupId -> {
|
insert.forEach(group -> {
|
||||||
|
FeatureRoleRelationReq.Role role = roles.get(group.getRoleId());
|
||||||
|
|
||||||
SaasPgroupPermissionRelation relation = new SaasPgroupPermissionRelation();
|
SaasPgroupPermissionRelation relation = new SaasPgroupPermissionRelation();
|
||||||
relation.setFeatureId(item.getFeatureId());
|
relation.setFeatureId(item.getFeatureId());
|
||||||
relation.setGroupId(groupId);
|
relation.setGroupId(group.getGroupId());
|
||||||
relation.setCreateBy(operatorId);
|
relation.setCreateBy(operatorId);
|
||||||
relation.setFeatureType(item.getFeatureType());
|
relation.setFeatureType(item.getFeatureType());
|
||||||
relation.setType(NEW_FEATURE);
|
relation.setType(NEW_FEATURE);
|
||||||
relation.setTerminal(item.getTerminal());
|
relation.setTerminal(item.getTerminal());
|
||||||
relation.setTags(Optional.ofNullable(item.getTags())
|
relation.setTags(Optional.ofNullable(role.getTags())
|
||||||
.orElseGet(() -> Sets.newHashSet(RolePermissionTagEnum.JOINED)));
|
.orElseGet(() -> Sets.newHashSet(RolePermissionTagEnum.JOINED)));
|
||||||
insertRelation.add(relation);
|
insertRelation.add(relation);
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user