| 
						
						
						
					 | 
					@ -1,13 +1,12 @@ | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					package com.epmet.redis; | 
					 | 
					 | 
					package com.epmet.redis; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import com.alibaba.fastjson.JSON; | 
					 | 
					 | 
					import com.alibaba.fastjson.JSON; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import com.epmet.commons.tools.constant.NumConstant; | 
					 | 
					 | 
					import com.epmet.commons.tools.constant.NumConstant; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					import com.epmet.commons.tools.redis.RedisKeys; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import com.epmet.commons.tools.redis.RedisUtils; | 
					 | 
					 | 
					import com.epmet.commons.tools.redis.RedisUtils; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import com.epmet.commons.tools.utils.ConvertUtils; | 
					 | 
					 | 
					import com.epmet.commons.tools.utils.ConvertUtils; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import com.epmet.constant.BadgeConstant; | 
					 | 
					 | 
					import com.epmet.constant.BadgeConstant; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import com.epmet.constant.UserRedisKeys; | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import com.epmet.dao.BadgeDao; | 
					 | 
					 | 
					import com.epmet.dao.BadgeDao; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import com.epmet.dto.form.UserBadgeUnitFormDTO; | 
					 | 
					 | 
					import com.epmet.dto.form.UserBadgeUnitFormDTO; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import com.epmet.dto.result.UserBadgeInfoResultDTO; | 
					 | 
					 | 
					import com.epmet.dto.result.UserBadgeInfoResultDTO; | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
					@ -110,7 +109,7 @@ public class UserBadgeRedis { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					     */ | 
					 | 
					 | 
					     */ | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    public List<UserBadgeUnitFormDTO> obtainUserBadge2List(String userId,String customerId) { | 
					 | 
					 | 
					    public List<UserBadgeUnitFormDTO> obtainUserBadge2List(String userId,String customerId) { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        List<UserBadgeUnitFormDTO> cache = | 
					 | 
					 | 
					        List<UserBadgeUnitFormDTO> cache = | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					        redisUtils.lrange(UserRedisKeys.getResiUserBadgeKey(customerId,userId), NumConstant.ZERO, NumConstant.ONE_NEG, UserBadgeUnitFormDTO.class); | 
					 | 
					 | 
					                redisUtils.lrange(RedisKeys.getResiUserBadgeKey(customerId, userId), NumConstant.ZERO, NumConstant.ONE_NEG, UserBadgeUnitFormDTO.class); | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					        if(!CollectionUtils.isEmpty(cache)) return cache; | 
					 | 
					 | 
					        if(!CollectionUtils.isEmpty(cache)) return cache; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        //补偿
 | 
					 | 
					 | 
					        //补偿
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        cache = badgeService.getUserSortedBadge(userId,customerId); | 
					 | 
					 | 
					        cache = badgeService.getUserSortedBadge(userId,customerId); | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					@ -118,7 +117,7 @@ public class UserBadgeRedis { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        final List<UserBadgeUnitFormDTO> sortedBadges = cache; | 
					 | 
					 | 
					        final List<UserBadgeUnitFormDTO> sortedBadges = cache; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        redisTemplate.executePipelined((RedisCallback<List<UserBadgeUnitFormDTO>>) connection ->{ | 
					 | 
					 | 
					        redisTemplate.executePipelined((RedisCallback<List<UserBadgeUnitFormDTO>>) connection ->{ | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					            sortedBadges.forEach(badge -> { | 
					 | 
					 | 
					            sortedBadges.forEach(badge -> { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					                connection.listCommands().rPush(UserRedisKeys.getResiUserBadgeKey(customerId, userId).getBytes(), | 
					 | 
					 | 
					                connection.listCommands().rPush(RedisKeys.getResiUserBadgeKey(customerId, userId).getBytes(), | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					                        redisTemplate.getValueSerializer().serialize(badge)); | 
					 | 
					 | 
					                        redisTemplate.getValueSerializer().serialize(badge)); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					            }); | 
					 | 
					 | 
					            }); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					            return null; | 
					 | 
					 | 
					            return null; | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					@ -142,7 +141,7 @@ public class UserBadgeRedis { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        List<String> cacheBlank = new LinkedList<>(); | 
					 | 
					 | 
					        List<String> cacheBlank = new LinkedList<>(); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        userIds.forEach(userId -> { | 
					 | 
					 | 
					        userIds.forEach(userId -> { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					            List<UserBadgeUnitFormDTO> badges = | 
					 | 
					 | 
					            List<UserBadgeUnitFormDTO> badges = | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					            redisUtils.lrange(UserRedisKeys.getResiUserBadgeKey(customerId,userId), NumConstant.ZERO, NumConstant.ONE_NEG, UserBadgeUnitFormDTO.class); | 
					 | 
					 | 
					                    redisUtils.lrange(RedisKeys.getResiUserBadgeKey(customerId, userId), NumConstant.ZERO, NumConstant.ONE_NEG, UserBadgeUnitFormDTO.class); | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					            if(CollectionUtils.isEmpty(badges)){cacheBlank.add(userId);}else{result.put(userId,badges);} | 
					 | 
					 | 
					            if(CollectionUtils.isEmpty(badges)){cacheBlank.add(userId);}else{result.put(userId,badges);} | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        }); | 
					 | 
					 | 
					        }); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        if(!CollectionUtils.isEmpty(cacheBlank)){ | 
					 | 
					 | 
					        if(!CollectionUtils.isEmpty(cacheBlank)){ | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					@ -158,7 +157,7 @@ public class UserBadgeRedis { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                    redisTemplate.executePipelined((RedisCallback<List<UserBadgeUnitFormDTO>>) connection ->{ | 
					 | 
					 | 
					                    redisTemplate.executePipelined((RedisCallback<List<UserBadgeUnitFormDTO>>) connection ->{ | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                        covert.forEach(badge -> { | 
					 | 
					 | 
					                        covert.forEach(badge -> { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					                            connection.listCommands().rPush(UserRedisKeys.getResiUserBadgeKey(customerId, k).getBytes(), | 
					 | 
					 | 
					                            connection.listCommands().rPush(RedisKeys.getResiUserBadgeKey(customerId, k).getBytes(), | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					                                    redisTemplate.getValueSerializer().serialize(badge)); | 
					 | 
					 | 
					                                    redisTemplate.getValueSerializer().serialize(badge)); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                        }); | 
					 | 
					 | 
					                        }); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                        return null; | 
					 | 
					 | 
					                        return null; | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					@ -179,14 +178,14 @@ public class UserBadgeRedis { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					     */ | 
					 | 
					 | 
					     */ | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    public long pushOrRemoveUserBadge4List(String userId, String badgeId, String customerId) { | 
					 | 
					 | 
					    public long pushOrRemoveUserBadge4List(String userId, String badgeId, String customerId) { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        if(StringUtils.isNotBlank(userId)) return illumeOrExtinguishStronglyConsistent(userId,customerId); | 
					 | 
					 | 
					        if(StringUtils.isNotBlank(userId)) return illumeOrExtinguishStronglyConsistent(userId,customerId); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					        List<UserBadgeUnitFormDTO> orient = redisUtils.lrange(UserRedisKeys.getResiUserBadgeKey(customerId,userId), NumConstant.ZERO, NumConstant.ONE_NEG, UserBadgeUnitFormDTO.class); | 
					 | 
					 | 
					        List<UserBadgeUnitFormDTO> orient = redisUtils.lrange(RedisKeys.getResiUserBadgeKey(customerId, userId), NumConstant.ZERO, NumConstant.ONE_NEG, UserBadgeUnitFormDTO.class); | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					        UserBadgeUnitFormDTO unit = null; | 
					 | 
					 | 
					        UserBadgeUnitFormDTO unit = null; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        if (!CollectionUtils.isEmpty(orient)) { | 
					 | 
					 | 
					        if (!CollectionUtils.isEmpty(orient)) { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					            Optional<UserBadgeUnitFormDTO> opt = orient.stream().filter(badge -> StringUtils.equals(badgeId, badge.getBadgeId())).findFirst(); | 
					 | 
					 | 
					            Optional<UserBadgeUnitFormDTO> opt = orient.stream().filter(badge -> StringUtils.equals(badgeId, badge.getBadgeId())).findFirst(); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					            if (opt.isPresent()) { | 
					 | 
					 | 
					            if (opt.isPresent()) { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                unit = opt.get(); | 
					 | 
					 | 
					                unit = opt.get(); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					                return redisUtils.lrem(UserRedisKeys.getResiUserBadgeKey(customerId, userId), NumConstant.ONE, unit); | 
					 | 
					 | 
					                return redisUtils.lrem(RedisKeys.getResiUserBadgeKey(customerId, userId), NumConstant.ONE, unit); | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					            } | 
					 | 
					 | 
					            } | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        } | 
					 | 
					 | 
					        } | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					@ -207,7 +206,7 @@ public class UserBadgeRedis { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                if (poolOpt.isPresent()) unit = ConvertUtils.sourceToTarget(poolOpt.get(), UserBadgeUnitFormDTO.class); | 
					 | 
					 | 
					                if (poolOpt.isPresent()) unit = ConvertUtils.sourceToTarget(poolOpt.get(), UserBadgeUnitFormDTO.class); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                else return NumConstant.ZERO; | 
					 | 
					 | 
					                else return NumConstant.ZERO; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					            } | 
					 | 
					 | 
					            } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					            redisUtils.leftPush(UserRedisKeys.getResiUserBadgeKey(customerId, userId), unit,-1); | 
					 | 
					 | 
					        redisUtils.leftPush(RedisKeys.getResiUserBadgeKey(customerId, userId), unit, -1); | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					            return NumConstant.ONE; | 
					 | 
					 | 
					            return NumConstant.ONE; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        } | 
					 | 
					 | 
					        } | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					@ -220,11 +219,11 @@ public class UserBadgeRedis { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    */ | 
					 | 
					 | 
					    */ | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    public long illumeOrExtinguishStronglyConsistent(String userId, String customerId){ | 
					 | 
					 | 
					    public long illumeOrExtinguishStronglyConsistent(String userId, String customerId){ | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        List<UserBadgeUnitFormDTO> db = badgeService.getUserSortedBadge(userId,customerId); | 
					 | 
					 | 
					        List<UserBadgeUnitFormDTO> db = badgeService.getUserSortedBadge(userId,customerId); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					        redisUtils.delete(UserRedisKeys.getResiUserBadgeKey(customerId,userId)); | 
					 | 
					 | 
					        redisUtils.delete(RedisKeys.getResiUserBadgeKey(customerId, userId)); | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					        if(CollectionUtils.isNotEmpty(db)) { | 
					 | 
					 | 
					        if(CollectionUtils.isNotEmpty(db)) { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					            redisTemplate.executePipelined((RedisCallback<List<UserBadgeUnitFormDTO>>) connection -> { | 
					 | 
					 | 
					            redisTemplate.executePipelined((RedisCallback<List<UserBadgeUnitFormDTO>>) connection -> { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                db.forEach(badge -> { | 
					 | 
					 | 
					                db.forEach(badge -> { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					                    connection.listCommands().rPush(UserRedisKeys.getResiUserBadgeKey(customerId, userId).getBytes(), | 
					 | 
					 | 
					                    connection.listCommands().rPush(RedisKeys.getResiUserBadgeKey(customerId, userId).getBytes(), | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					                            redisTemplate.getValueSerializer().serialize(badge)); | 
					 | 
					 | 
					                            redisTemplate.getValueSerializer().serialize(badge)); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                }); | 
					 | 
					 | 
					                }); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                return null; | 
					 | 
					 | 
					                return null; | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					@ -241,7 +240,7 @@ public class UserBadgeRedis { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					         * @date 2020.11.09 10:02 | 
					 | 
					 | 
					         * @date 2020.11.09 10:02 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        */ | 
					 | 
					 | 
					        */ | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        public void batchClearUserBadgeCache(String customerId){ | 
					 | 
					 | 
					        public void batchClearUserBadgeCache(String customerId){ | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					            Set<String> key = redisUtils.keys(UserRedisKeys.getResiUserBadgeKey(customerId, null)); | 
					 | 
					 | 
					            Set<String> key = redisUtils.keys(RedisKeys.getResiUserBadgeKey(customerId, null)); | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					            if(CollectionUtils.isEmpty(key)) return; | 
					 | 
					 | 
					            if(CollectionUtils.isEmpty(key)) return; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					            final Set<String> keys = key; | 
					 | 
					 | 
					            final Set<String> keys = key; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					            redisTemplate.executePipelined((RedisCallback<String>) connection ->{ | 
					 | 
					 | 
					            redisTemplate.executePipelined((RedisCallback<String>) connection ->{ | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					@ -257,7 +256,7 @@ public class UserBadgeRedis { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                @Override | 
					 | 
					 | 
					                @Override | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                public List<String> doInRedis(RedisConnection connection) throws DataAccessException { | 
					 | 
					 | 
					                public List<String> doInRedis(RedisConnection connection) throws DataAccessException { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                    connection.openPipeline(); | 
					 | 
					 | 
					                    connection.openPipeline(); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					                    Set<byte[]> keys = connection.keys(redisTemplate.getKeySerializer().serialize(UserRedisKeys.getResiUserBadgeKey(customerId, null))); | 
					 | 
					 | 
					                    Set<byte[]> keys = connection.keys(redisTemplate.getKeySerializer().serialize(RedisKeys.getResiUserBadgeKey(customerId, null))); | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					                    return null; | 
					 | 
					 | 
					                    return null; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                } | 
					 | 
					 | 
					                } | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					            },redisTemplate.getKeySerializer()); | 
					 | 
					 | 
					            },redisTemplate.getKeySerializer()); | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
					
  |