ab
2024-11-05 0c6faf64f2a02ae94b0d719729754f7ca29da416
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package com.nova.sankuai.infra.utils;
 
import com.nova.sankuai.security.UserDetail;
import org.apache.commons.lang.StringUtils;
 
import java.util.*;
 
/**
 * @author weikangdi
 * @create 2021/11/1
 */
public class UserUtil {
    public static Map<String, UserDetail> USER_LIST = new HashMap<>();
 
    public static UserDetail getUser(String token) {
        return USER_LIST.get(token);
    }
 
    public static void setUser(String token, UserDetail userDetail) {
        USER_LIST.putIfAbsent(token, userDetail);
    }
 
    public static void removeUserByPhone(String phone) {
        Set<String> keys = new HashSet<>();
        USER_LIST.forEach((token, authInfo) -> {
            if (authInfo != null && StringUtils.isNotBlank(phone) && phone.equals(authInfo.getPhone())) {
                keys.add(token);
            }
        });
        for (String key : keys) {
            USER_LIST.remove(key);
        }
    }
 
    public static void removeUserByToken(String token) {
        USER_LIST.remove(token);
    }
}