feat:(hotfix/20240906) 只缓存普通角色以及缓存有效期改成1天
This commit is contained in:
parent
a033919e17
commit
10045a5588
@ -5,6 +5,7 @@ import lombok.AllArgsConstructor;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@ -56,4 +57,10 @@ public enum RoleTypeEnum {
|
|||||||
return Objects.equals(this.value, value);
|
return Objects.equals(this.value, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<String> listAdmin() {
|
||||||
|
return Arrays.stream(values())
|
||||||
|
.filter(RoleTypeEnum::isAdminRole)
|
||||||
|
.map(RoleTypeEnum::getValue)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package cn.axzo.tyr.server.event.inner;
|
|||||||
|
|
||||||
import cn.axzo.framework.rocketmq.Event;
|
import cn.axzo.framework.rocketmq.Event;
|
||||||
import cn.axzo.framework.rocketmq.EventConsumer;
|
import cn.axzo.framework.rocketmq.EventConsumer;
|
||||||
|
import cn.axzo.tyr.client.common.enums.RoleTypeEnum;
|
||||||
import cn.axzo.tyr.client.model.res.SaasRoleRes;
|
import cn.axzo.tyr.client.model.res.SaasRoleRes;
|
||||||
import cn.axzo.tyr.server.event.payload.PageElementFeatureResourceUpsertPayload;
|
import cn.axzo.tyr.server.event.payload.PageElementFeatureResourceUpsertPayload;
|
||||||
import cn.axzo.tyr.server.event.payload.RolePermissionCreatedPayload;
|
import cn.axzo.tyr.server.event.payload.RolePermissionCreatedPayload;
|
||||||
@ -47,6 +48,7 @@ public class CacheRolePermissionHandler implements InitializingBean {
|
|||||||
.roleIds(Optional.ofNullable(payload.getRoleIds())
|
.roleIds(Optional.ofNullable(payload.getRoleIds())
|
||||||
.map(Lists::newArrayList)
|
.map(Lists::newArrayList)
|
||||||
.orElse(null))
|
.orElse(null))
|
||||||
|
.roleTypesNotIn(RoleTypeEnum.listAdmin())
|
||||||
.build();
|
.build();
|
||||||
Set<Long> roleIds = roleService.list(listSaasRoleParam).stream()
|
Set<Long> roleIds = roleService.list(listSaasRoleParam).stream()
|
||||||
.map(SaasRoleRes::getId)
|
.map(SaasRoleRes::getId)
|
||||||
@ -70,7 +72,9 @@ public class CacheRolePermissionHandler implements InitializingBean {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
RoleService.ListSaasRoleParam listSaasRoleParam = RoleService.ListSaasRoleParam.builder().build();
|
RoleService.ListSaasRoleParam listSaasRoleParam = RoleService.ListSaasRoleParam.builder()
|
||||||
|
.roleTypesNotIn(RoleTypeEnum.listAdmin())
|
||||||
|
.build();
|
||||||
Set<Long> roleIds = roleService.list(listSaasRoleParam).stream()
|
Set<Long> roleIds = roleService.list(listSaasRoleParam).stream()
|
||||||
.map(SaasRoleRes::getId)
|
.map(SaasRoleRes::getId)
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package cn.axzo.tyr.server.event.inner;
|
|||||||
|
|
||||||
import cn.axzo.framework.rocketmq.Event;
|
import cn.axzo.framework.rocketmq.Event;
|
||||||
import cn.axzo.framework.rocketmq.EventConsumer;
|
import cn.axzo.framework.rocketmq.EventConsumer;
|
||||||
|
import cn.axzo.tyr.client.common.enums.RoleTypeEnum;
|
||||||
import cn.axzo.tyr.client.model.res.SaasRoleRes;
|
import cn.axzo.tyr.client.model.res.SaasRoleRes;
|
||||||
import cn.axzo.tyr.server.event.payload.PageElementFeatureResourceUpsertPayload;
|
import cn.axzo.tyr.server.event.payload.PageElementFeatureResourceUpsertPayload;
|
||||||
import cn.axzo.tyr.server.event.payload.RolePermissionCreatedPayload;
|
import cn.axzo.tyr.server.event.payload.RolePermissionCreatedPayload;
|
||||||
@ -48,6 +49,7 @@ public class CacheRoleSaasFeatureResourceHandler implements InitializingBean {
|
|||||||
.roleIds(Optional.ofNullable(payload.getRoleIds())
|
.roleIds(Optional.ofNullable(payload.getRoleIds())
|
||||||
.map(Lists::newArrayList)
|
.map(Lists::newArrayList)
|
||||||
.orElse(null))
|
.orElse(null))
|
||||||
|
.roleTypesNotIn(RoleTypeEnum.listAdmin())
|
||||||
.build();
|
.build();
|
||||||
Set<Long> roleIds = roleService.list(listSaasRoleParam).stream()
|
Set<Long> roleIds = roleService.list(listSaasRoleParam).stream()
|
||||||
.map(SaasRoleRes::getId)
|
.map(SaasRoleRes::getId)
|
||||||
@ -72,6 +74,7 @@ public class CacheRoleSaasFeatureResourceHandler implements InitializingBean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
RoleService.ListSaasRoleParam listSaasRoleParam = RoleService.ListSaasRoleParam.builder()
|
RoleService.ListSaasRoleParam listSaasRoleParam = RoleService.ListSaasRoleParam.builder()
|
||||||
|
.roleTypesNotIn(RoleTypeEnum.listAdmin())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
Set<Long> roleIds = roleService.list(listSaasRoleParam).stream()
|
Set<Long> roleIds = roleService.list(listSaasRoleParam).stream()
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package cn.axzo.tyr.server.job;
|
package cn.axzo.tyr.server.job;
|
||||||
|
|
||||||
|
import cn.axzo.tyr.client.common.enums.RoleTypeEnum;
|
||||||
import cn.axzo.tyr.client.model.res.SaasRoleRes;
|
import cn.axzo.tyr.client.model.res.SaasRoleRes;
|
||||||
import cn.axzo.tyr.server.service.RoleSaasFeatureResourceCacheService;
|
import cn.axzo.tyr.server.service.RoleSaasFeatureResourceCacheService;
|
||||||
import cn.axzo.tyr.server.service.RoleService;
|
import cn.axzo.tyr.server.service.RoleService;
|
||||||
@ -33,6 +34,7 @@ public class CacheRoleFeatureResourceJob extends IJobHandler {
|
|||||||
RoleService.ListSaasRoleParam listSaasRoleParam = Optional.ofNullable(s)
|
RoleService.ListSaasRoleParam listSaasRoleParam = Optional.ofNullable(s)
|
||||||
.map(e -> JSONObject.parseObject(e, RoleService.ListSaasRoleParam.class))
|
.map(e -> JSONObject.parseObject(e, RoleService.ListSaasRoleParam.class))
|
||||||
.orElseGet(() -> RoleService.ListSaasRoleParam.builder().build());
|
.orElseGet(() -> RoleService.ListSaasRoleParam.builder().build());
|
||||||
|
listSaasRoleParam.setRoleTypesNotIn(RoleTypeEnum.listAdmin());
|
||||||
|
|
||||||
Set<Long> roleIds = roleService.list(listSaasRoleParam).stream()
|
Set<Long> roleIds = roleService.list(listSaasRoleParam).stream()
|
||||||
.map(SaasRoleRes::getId)
|
.map(SaasRoleRes::getId)
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package cn.axzo.tyr.server.job;
|
package cn.axzo.tyr.server.job;
|
||||||
|
|
||||||
|
import cn.axzo.tyr.client.common.enums.RoleTypeEnum;
|
||||||
import cn.axzo.tyr.client.model.res.SaasRoleRes;
|
import cn.axzo.tyr.client.model.res.SaasRoleRes;
|
||||||
import cn.axzo.tyr.server.service.RolePermissionCacheService;
|
import cn.axzo.tyr.server.service.RolePermissionCacheService;
|
||||||
import cn.axzo.tyr.server.service.RoleService;
|
import cn.axzo.tyr.server.service.RoleService;
|
||||||
@ -35,6 +36,8 @@ public class CacheRolePermissionJob extends IJobHandler {
|
|||||||
.map(e -> JSONObject.parseObject(e, RoleService.ListSaasRoleParam.class))
|
.map(e -> JSONObject.parseObject(e, RoleService.ListSaasRoleParam.class))
|
||||||
.orElseGet(() -> RoleService.ListSaasRoleParam.builder().build());
|
.orElseGet(() -> RoleService.ListSaasRoleParam.builder().build());
|
||||||
|
|
||||||
|
listSaasRoleParam.setRoleTypesNotIn(RoleTypeEnum.listAdmin());
|
||||||
|
|
||||||
Set<Long> roleIds = roleService.list(listSaasRoleParam).stream()
|
Set<Long> roleIds = roleService.list(listSaasRoleParam).stream()
|
||||||
.map(SaasRoleRes::getId)
|
.map(SaasRoleRes::getId)
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
|
|||||||
@ -136,6 +136,9 @@ public interface RoleService extends IService<SaasRole> {
|
|||||||
@CriteriaField(field = "roleType", operator = Operator.IN)
|
@CriteriaField(field = "roleType", operator = Operator.IN)
|
||||||
private List<String> roleTypes;
|
private List<String> roleTypes;
|
||||||
|
|
||||||
|
@CriteriaField(field = "roleType", operator = Operator.NOT_IN)
|
||||||
|
private List<String> roleTypesNotIn;
|
||||||
|
|
||||||
@CriteriaField(field = "id", operator = Operator.NE)
|
@CriteriaField(field = "id", operator = Operator.NE)
|
||||||
private Long idNE;
|
private Long idNE;
|
||||||
|
|
||||||
|
|||||||
@ -19,7 +19,6 @@ import com.google.common.collect.Maps;
|
|||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
@ -51,12 +50,8 @@ public class ProductPermissionCacheServiceImpl implements ProductPermissionCache
|
|||||||
@Autowired
|
@Autowired
|
||||||
private SaasFeatureDao saasFeatureDao;
|
private SaasFeatureDao saasFeatureDao;
|
||||||
|
|
||||||
/** 产品权限缓存过期时间 **/
|
|
||||||
@Value("${product.permission.expire.minutes:14}")
|
|
||||||
private Long expireInMinutes;
|
|
||||||
|
|
||||||
private LoadingCache<Long, Optional<List<PermissionDTO>>> productPermissionCache = CacheBuilder.newBuilder()
|
private LoadingCache<Long, Optional<List<PermissionDTO>>> productPermissionCache = CacheBuilder.newBuilder()
|
||||||
.expireAfterWrite(14, TimeUnit.MINUTES)
|
.expireAfterWrite(1, TimeUnit.DAYS)
|
||||||
.maximumSize(5000)
|
.maximumSize(5000)
|
||||||
.build(new CacheLoader<Long, Optional<List<PermissionDTO>>>() {
|
.build(new CacheLoader<Long, Optional<List<PermissionDTO>>>() {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -19,7 +19,6 @@ import com.google.common.collect.Sets;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
@ -48,9 +47,6 @@ public class ProductSaasFeatureResourceCacheServiceImpl implements ProductSaasFe
|
|||||||
@Autowired
|
@Autowired
|
||||||
private SaasFeatureResourceService saasFeatureResourceService;
|
private SaasFeatureResourceService saasFeatureResourceService;
|
||||||
|
|
||||||
@Value("${product.feature.resouce.expire.minutes:14}")
|
|
||||||
private Long expireInMinutes;
|
|
||||||
|
|
||||||
public static final Set<Integer> FEATURE_RESOURCE_TYPES = Sets.newHashSet(FeatureResourceType.MENU.getCode(),
|
public static final Set<Integer> FEATURE_RESOURCE_TYPES = Sets.newHashSet(FeatureResourceType.MENU.getCode(),
|
||||||
FeatureResourceType.PAGE.getCode(),
|
FeatureResourceType.PAGE.getCode(),
|
||||||
FeatureResourceType.MENU_PARTITION_GROUP.getCode(),
|
FeatureResourceType.MENU_PARTITION_GROUP.getCode(),
|
||||||
@ -58,7 +54,7 @@ public class ProductSaasFeatureResourceCacheServiceImpl implements ProductSaasFe
|
|||||||
FeatureResourceType.APP_ENTRY.getCode());
|
FeatureResourceType.APP_ENTRY.getCode());
|
||||||
|
|
||||||
private LoadingCache<Long, Optional<List<FeatureResourceDTO>>> productFeatureResourceCache = CacheBuilder.newBuilder()
|
private LoadingCache<Long, Optional<List<FeatureResourceDTO>>> productFeatureResourceCache = CacheBuilder.newBuilder()
|
||||||
.expireAfterWrite(14, TimeUnit.MINUTES)
|
.expireAfterWrite(1, TimeUnit.DAYS)
|
||||||
.maximumSize(5000)
|
.maximumSize(5000)
|
||||||
.build(new CacheLoader<Long, Optional<List<FeatureResourceDTO>>>() {
|
.build(new CacheLoader<Long, Optional<List<FeatureResourceDTO>>>() {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -18,7 +18,6 @@ import com.google.common.collect.Lists;
|
|||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
@ -50,12 +49,8 @@ public class RolePermissionCacheServiceImpl implements RolePermissionCacheServic
|
|||||||
@Autowired
|
@Autowired
|
||||||
private SaasFeatureDao saasFeatureDao;
|
private SaasFeatureDao saasFeatureDao;
|
||||||
|
|
||||||
/** 角色权限缓存过期时间 **/
|
|
||||||
@Value("${role.permission.expire.minutes:14}")
|
|
||||||
private static Long expireInMinutes;
|
|
||||||
|
|
||||||
private LoadingCache<Long, Optional<List<PermissionDTO>>> rolePermissionCache = CacheBuilder.newBuilder()
|
private LoadingCache<Long, Optional<List<PermissionDTO>>> rolePermissionCache = CacheBuilder.newBuilder()
|
||||||
.expireAfterWrite(14, TimeUnit.MINUTES)
|
.expireAfterWrite(1, TimeUnit.DAYS)
|
||||||
.maximumSize(5000)
|
.maximumSize(5000)
|
||||||
.build(new CacheLoader<Long, Optional<List<PermissionDTO>>>() {
|
.build(new CacheLoader<Long, Optional<List<PermissionDTO>>>() {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -18,7 +18,6 @@ import com.google.common.collect.Maps;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
@ -47,12 +46,9 @@ public class RoleSaasFeatureResourceCacheServiceImpl implements RoleSaasFeatureR
|
|||||||
@Autowired
|
@Autowired
|
||||||
private SaasFeatureResourceService saasFeatureResourceService;
|
private SaasFeatureResourceService saasFeatureResourceService;
|
||||||
|
|
||||||
/** 角色菜单缓存过期时间 **/
|
|
||||||
@Value("${role.feature.resource.expire.minutes:14}")
|
|
||||||
private Long expireInMinutes;
|
|
||||||
|
|
||||||
private LoadingCache<Long, Optional<List<SaasFeatureResourceDTO>>> roleFeatureResourceCache = CacheBuilder.newBuilder()
|
private LoadingCache<Long, Optional<List<SaasFeatureResourceDTO>>> roleFeatureResourceCache = CacheBuilder.newBuilder()
|
||||||
.expireAfterWrite(14, TimeUnit.MINUTES)
|
.expireAfterWrite(1, TimeUnit.DAYS)
|
||||||
.maximumSize(5000)
|
.maximumSize(5000)
|
||||||
.build(new CacheLoader<Long, Optional<List<SaasFeatureResourceDTO>>>() {
|
.build(new CacheLoader<Long, Optional<List<SaasFeatureResourceDTO>>>() {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -65,7 +65,6 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
import org.apache.commons.lang3.BooleanUtils;
|
import org.apache.commons.lang3.BooleanUtils;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.cache.annotation.CacheEvict;
|
import org.springframework.cache.annotation.CacheEvict;
|
||||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@ -114,15 +113,10 @@ public class SaasFeatureResourceServiceImpl extends ServiceImpl<SaasFeatureResou
|
|||||||
private final MqProducer mqProducer;
|
private final MqProducer mqProducer;
|
||||||
private final SaasFeatureDao saasFeatureDao;
|
private final SaasFeatureDao saasFeatureDao;
|
||||||
|
|
||||||
|
|
||||||
/** 菜单树过期时间 **/
|
|
||||||
@Value("${saas.feature.resource.expire.minutes:14}")
|
|
||||||
private Long expireInMinutes;
|
|
||||||
|
|
||||||
private static final String TARGET_TYPE = "saasFeatureResourceId";
|
private static final String TARGET_TYPE = "saasFeatureResourceId";
|
||||||
|
|
||||||
private LoadingCache<String, Optional<List<SaasFeatureResourceCache>>> featureResourceCache = CacheBuilder.newBuilder()
|
private LoadingCache<String, Optional<List<SaasFeatureResourceCache>>> featureResourceCache = CacheBuilder.newBuilder()
|
||||||
.expireAfterWrite(14, TimeUnit.MINUTES)
|
.expireAfterWrite(1, TimeUnit.DAYS)
|
||||||
.maximumSize(5000)
|
.maximumSize(5000)
|
||||||
.build(new CacheLoader<String, Optional<List<SaasFeatureResourceCache>>>() {
|
.build(new CacheLoader<String, Optional<List<SaasFeatureResourceCache>>>() {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user