diff --git a/tyr-api/src/main/java/cn/axzo/tyr/client/model/req/FeatureRoleRelationReq.java b/tyr-api/src/main/java/cn/axzo/tyr/client/model/req/FeatureRoleRelationReq.java index a51444a0..3f5f0d29 100644 --- a/tyr-api/src/main/java/cn/axzo/tyr/client/model/req/FeatureRoleRelationReq.java +++ b/tyr-api/src/main/java/cn/axzo/tyr/client/model/req/FeatureRoleRelationReq.java @@ -37,12 +37,20 @@ public class FeatureRoleRelationReq { private Integer featureType; /** 应用的角色Id列表 **/ - private List roleIds; + private Set roles; /** 授权类型 0-全部角色 1-指定角色 **/ private Integer authType; private String terminal; + } + + @Data + @Builder + @NoArgsConstructor + @AllArgsConstructor + public static class Role { + private Long roleId; /** * 权限标签:默认为JOINED diff --git a/tyr-server/src/main/java/cn/axzo/tyr/server/service/impl/RoleServiceImpl.java b/tyr-server/src/main/java/cn/axzo/tyr/server/service/impl/RoleServiceImpl.java index 0a90f563..bbbd2b2f 100644 --- a/tyr-server/src/main/java/cn/axzo/tyr/server/service/impl/RoleServiceImpl.java +++ b/tyr-server/src/main/java/cn/axzo/tyr/server/service/impl/RoleServiceImpl.java @@ -1596,7 +1596,7 @@ public class RoleServiceImpl extends ServiceImpl 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 List existGroupIds = saasPgroupPermissionRelationDao.queryByFeatureIds(Collections.singletonList(item.getFeatureId())) .stream().map(SaasPgroupPermissionRelation::getGroupId).collect(Collectors.toList()); - List groupIds = saasPgroupRoleRelationDao.findByRoleIds(item.getRoleIds()) - .stream().map(SaasPgroupRoleRelation::getGroupId).collect(Collectors.toList()); - List insertGroupIds = groupIds.stream().filter(role -> !existGroupIds.contains(role)).collect(Collectors.toList()); + List roleIds = item.getRoles().stream() + .map(FeatureRoleRelationReq.Role::getRoleId) + .collect(Collectors.toList()); + List saasPgroupRoleRelations = saasPgroupRoleRelationDao.findByRoleIds(roleIds); + List groupIds = saasPgroupRoleRelations.stream().map(SaasPgroupRoleRelation::getGroupId).collect(Collectors.toList()); List deleteGroupIds = existGroupIds.stream().filter(role -> !groupIds.contains(role)).collect(Collectors.toList()); + + List insert = saasPgroupRoleRelations.stream() + .filter(e -> !existGroupIds.contains(e.getGroupId())) + .collect(Collectors.toList()); + Map 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 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); });