feat: (feature/REQ-2595) 角色权限缓存增加tags,

This commit is contained in:
lilong 2024-10-22 18:54:11 +08:00
parent 3e80c801c9
commit 1494412969
6 changed files with 37 additions and 8 deletions

View File

@ -5,6 +5,8 @@ import lombok.Builder;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import java.util.Set;
@Data @Data
@Builder @Builder
@NoArgsConstructor @NoArgsConstructor
@ -25,4 +27,11 @@ public class SaasPermissionRelationRes {
* 菜单资源树节点类型 * 菜单资源树节点类型
*/ */
private Integer featureType; private Integer featureType;
/**
* 权限点标签
* 在职:JOINED
* 离场:LEAVE
*/
private Set<String> tags;
} }

View File

@ -38,12 +38,6 @@ public class CacheRolePermissionHandler implements InitializingBean {
log.info("begin cached role permission handler rocketmq event: {}", event); log.info("begin cached role permission handler rocketmq event: {}", event);
RolePermissionCreatedPayload payload = event.normalizedData(RolePermissionCreatedPayload.class); RolePermissionCreatedPayload payload = event.normalizedData(RolePermissionCreatedPayload.class);
// 影响角色权限入口的代码没法简单重构导致发送的roleIds可能不准确所以一旦有角色权限的更新事件后全量更新角色权限角色权限数量不多
// 后续收口了代码就准确根据角色去更新缓存
// if (CollectionUtils.isEmpty(payload.getRoleIds())) {
// return;
// }
RoleService.ListSaasRoleParam listSaasRoleParam = RoleService.ListSaasRoleParam.builder() RoleService.ListSaasRoleParam listSaasRoleParam = RoleService.ListSaasRoleParam.builder()
.roleIds(Optional.ofNullable(payload.getRoleIds()) .roleIds(Optional.ofNullable(payload.getRoleIds())
.map(Lists::newArrayList) .map(Lists::newArrayList)

View File

@ -1,7 +1,6 @@
package cn.axzo.tyr.server.repository.entity; package cn.axzo.tyr.server.repository.entity;
import cn.axzo.pokonyan.config.mybatisplus.BaseEntity; import cn.axzo.pokonyan.config.mybatisplus.BaseEntity;
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler; import com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler;
@ -12,6 +11,7 @@ import lombok.ToString;
import java.io.Serializable; import java.io.Serializable;
import java.util.Objects; import java.util.Objects;
import java.util.Set;
/** /**
* 权限集功能中间表(SaasPgroupPermissionRelation)表实体类 * 权限集功能中间表(SaasPgroupPermissionRelation)表实体类
@ -23,7 +23,7 @@ import java.util.Objects;
@Setter @Setter
@ToString @ToString
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@TableName("saas_pgroup_permission_relation") @TableName(value = "saas_pgroup_permission_relation", autoResultMap = true)
public class SaasPgroupPermissionRelation extends BaseEntity<SaasPgroupPermissionRelation> { public class SaasPgroupPermissionRelation extends BaseEntity<SaasPgroupPermissionRelation> {
public static final Integer OLD_FEATURE = 0; public static final Integer OLD_FEATURE = 0;
@ -70,6 +70,12 @@ public class SaasPgroupPermissionRelation extends BaseEntity<SaasPgroupPermissio
*/ */
private String terminal; private String terminal;
/**
* 标签
*/
@TableField(value = "tags", typeHandler = FastjsonTypeHandler.class)
private Set<String> tags;
/** /**
* 获取主键值 * 获取主键值
* *

View File

@ -70,5 +70,12 @@ public interface RolePermissionCacheService {
private String terminal; private String terminal;
private Integer featureType; private Integer featureType;
/**
* 权限点标签
* 在职:JOINED
* 离场:LEAVE
*/
private Set<String> tags;
} }
} }

View File

@ -182,6 +182,7 @@ public class RolePermissionCacheServiceImpl implements RolePermissionCacheServic
.featureCode(saasFeature.getFeatureCode()) .featureCode(saasFeature.getFeatureCode())
.featureType(saasFeature.getFeatureType()) .featureType(saasFeature.getFeatureType())
.terminal(saasFeature.getTerminal()) .terminal(saasFeature.getTerminal())
.tags(permissionRelation.getTags())
.build()); .build());
List<RolePermissionCacheService.PermissionDTO> parentPermissions = saasFeature.splitPath().stream() List<RolePermissionCacheService.PermissionDTO> parentPermissions = saasFeature.splitPath().stream()
@ -192,6 +193,7 @@ public class RolePermissionCacheServiceImpl implements RolePermissionCacheServic
.featureCode(f.getFeatureCode()) .featureCode(f.getFeatureCode())
.featureType(f.getFeatureType()) .featureType(f.getFeatureType())
.terminal(f.getTerminal()) .terminal(f.getTerminal())
.tags(permissionRelation.getTags())
.build()) .build())
.collect(Collectors.toList()); .collect(Collectors.toList());
@ -216,6 +218,7 @@ public class RolePermissionCacheServiceImpl implements RolePermissionCacheServic
.featureCode(pageElement.getCode()) .featureCode(pageElement.getCode())
.featureType(featureResource.getFeatureType()) .featureType(featureResource.getFeatureType())
.terminal(featureResource.getTerminal()) .terminal(featureResource.getTerminal())
.tags(permissionRelation.getTags())
.build()) .build())
.collect(Collectors.toList()); .collect(Collectors.toList());
@ -234,6 +237,7 @@ public class RolePermissionCacheServiceImpl implements RolePermissionCacheServic
.featureCode(pageElement.getCode()) .featureCode(pageElement.getCode())
.featureType(f.getFeatureType()) .featureType(f.getFeatureType())
.terminal(f.getTerminal()) .terminal(f.getTerminal())
.tags(permissionRelation.getTags())
.build()) .build())
.collect(Collectors.toList()); .collect(Collectors.toList());
}) })

View File

@ -1741,6 +1741,7 @@ public class RoleServiceImpl extends ServiceImpl<SaasRoleMapper, SaasRole>
.featureId(e.getFeatureId()) .featureId(e.getFeatureId())
.type(e.getType()) .type(e.getType())
.featureType(e.getFeatureType()) .featureType(e.getFeatureType())
.tags(e.getTags())
.build(), .build(),
Collectors.toList()))); Collectors.toList())));
} }
@ -1851,6 +1852,13 @@ public class RoleServiceImpl extends ServiceImpl<SaasRoleMapper, SaasRole>
*/ */
private Integer featureType; private Integer featureType;
/**
* 权限点标签
* 在职:JOINED
* 离场:LEAVE
*/
private Set<String> tags;
public static SaasPermissionRelationWrapper from(SaasPgroupRoleRelation saasPgroupRoleRelation, public static SaasPermissionRelationWrapper from(SaasPgroupRoleRelation saasPgroupRoleRelation,
SaasPgroupPermissionRelation permissionRelation) { SaasPgroupPermissionRelation permissionRelation) {
if (permissionRelation == null) { if (permissionRelation == null) {
@ -1861,6 +1869,7 @@ public class RoleServiceImpl extends ServiceImpl<SaasRoleMapper, SaasRole>
.featureId(permissionRelation.getFeatureId()) .featureId(permissionRelation.getFeatureId())
.type(permissionRelation.getType()) .type(permissionRelation.getType())
.featureType(permissionRelation.getFeatureType()) .featureType(permissionRelation.getFeatureType())
.tags(permissionRelation.getTags())
.build(); .build();
} }
} }