diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/constant/UserRedisKeys.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/constant/UserRedisKeys.java index 46f5ad1fa2..c21ba28c1f 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/constant/UserRedisKeys.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/constant/UserRedisKeys.java @@ -1,5 +1,7 @@ package com.epmet.constant; +import org.apache.commons.lang3.StringUtils; + /** * @Description * @ClassName UserRedisKeys @@ -32,5 +34,5 @@ public class UserRedisKeys { * @date 2020.11.05 13:34 */ public static String getResiUserBadgeKey(String customerId,String userId){ - return rootPrefix.concat("badge:user:").concat(customerId).concat(":").concat(userId);} + return rootPrefix.concat("badge:user:").concat(customerId).concat(":").concat( StringUtils.isBlank(userId) ? "*" : userId );} } diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/redis/UserBadgeRedis.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/redis/UserBadgeRedis.java index 0b57fcbb9f..f5c22ca54a 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/redis/UserBadgeRedis.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/redis/UserBadgeRedis.java @@ -16,10 +16,13 @@ import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisCallback; +import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Component; import java.util.List; import java.util.Optional; +import java.util.Set; import static com.epmet.commons.tools.redis.RedisUtils.MINUTE_THIRTY_EXPIRE; @@ -37,6 +40,8 @@ public class UserBadgeRedis { private BadgeDao badgeDao; @Autowired private UserBadgeService badgeService; + @Autowired + private RedisTemplate redisTemplate; /** * @Description 获取客户徽章信息 @@ -146,5 +151,25 @@ public class UserBadgeRedis { return NumConstant.ONE; } + + /** + * @Description 批量清除用户徽章信息,用处:在客户取消点亮某个徽章后,批量清除该客户下所有用户的徽章缓存,当需要查取时再次初始化进缓存中 + * @param customerId + * @return void + * @author wangc + * @date 2020.11.09 10:02 + */ + public void batchClearUserBadgeCache(String customerId){ + redisTemplate.executePipelined((RedisCallback) connection ->{ + Set keys = + connection.keys(redisTemplate.getKeySerializer().serialize(UserRedisKeys.getResiUserBadgeKey(customerId, null))); + if(!CollectionUtils.isEmpty(keys)){ + keys.forEach( ser -> {connection.del(ser);}); + } + return null; + }); + + } + }