zhouhao 2 years ago
parent
commit
9a48d78abe

+ 7 - 3
hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/token/redis/RedisUserTokenManager.java

@@ -53,9 +53,13 @@ public class RedisUserTokenManager implements UserTokenManager {
             .buffer(Flux.interval(Duration.ofSeconds(10)), HashSet::new)
             .flatMap(list -> Flux
                     .fromIterable(list)
-                    .flatMap(token -> operations
-                            .expire(getTokenRedisKey(token.getToken()), Duration.ofMillis(token.getMaxInactiveInterval()))
-                            .then())
+                    .flatMap(token -> {
+                        String key = getTokenRedisKey(token.getToken());
+                        return Mono
+                                .zip(userTokenStore.put(key, "lastRequestTime", token.getLastRequestTime()),
+                                     operations.expire(key, Duration.ofMillis(token.getMaxInactiveInterval())))
+                                .then();
+                    })
                     .onErrorResume(err -> Mono.empty()))
             .subscribe();
 

+ 22 - 3
hsweb-core/src/main/java/org/hswebframework/web/bean/FastBeanCopier.java

@@ -21,6 +21,7 @@ import java.beans.PropertyDescriptor;
 import java.lang.reflect.Array;
 import java.lang.reflect.Field;
 import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.function.BiFunction;
 import java.util.function.Function;
 import java.util.function.Supplier;
@@ -513,6 +514,8 @@ public final class FastBeanCopier {
 
             if (targetClass == List.class) {
                 return new ArrayList<>();
+            } else if (targetClass == ConcurrentHashMap.KeySetView.class) {
+                return ConcurrentHashMap.newKeySet();
             } else if (targetClass == Set.class) {
                 return new HashSet<>();
             } else if (targetClass == Queue.class) {
@@ -568,7 +571,7 @@ public final class FastBeanCopier {
                     return (T) new Date(((Date) source).getTime());
                 }
             }
-            if (Collection.class.isAssignableFrom(targetClass)) {
+            if (target.isCollectionType()) {
                 Collection collection = newCollection(targetClass);
                 Collection sourceCollection;
                 if (source instanceof Collection) {
@@ -619,7 +622,7 @@ public final class FastBeanCopier {
                     Enum t = ((Enum<?>) e);
                     if ((t.name().equalsIgnoreCase(strSource)
                             || Objects.equals(String.valueOf(t.ordinal()), strSource))) {
-                        return (T)e;
+                        return (T) e;
                     }
                 }
 
@@ -642,7 +645,7 @@ public final class FastBeanCopier {
                 //快速复制map
                 if (targetClass == Map.class) {
                     if (source instanceof Map) {
-                        return (T) new HashMap(((Map<?, ?>) source));
+                        return (T) copyMap(((Map<?, ?>) source));
                     }
                     ClassDescription sourType = ClassDescriptions.getDescription(source.getClass());
                     return (T) copy(source, Maps.newHashMapWithExpectedSize(sourType.getFieldSize()));
@@ -656,6 +659,22 @@ public final class FastBeanCopier {
 //            return null;
         }
 
+        private Map<?, ?> copyMap(Map<?, ?> map) {
+            if (map instanceof TreeMap) {
+                return new TreeMap<>(map);
+            }
+
+            if (map instanceof LinkedHashMap) {
+                return new LinkedHashMap<>(map);
+            }
+
+            if (map instanceof ConcurrentHashMap) {
+                return new ConcurrentHashMap<>(map);
+            }
+
+            return new HashMap<>(map);
+        }
+
         private Object converterByApache(Class<?> targetClass, Object source) {
             org.apache.commons.beanutils.Converter converter = convertUtils.lookup(targetClass);
             if (null != converter) {