feat: 用户会话后端代码.
This commit is contained in:
@@ -46,11 +46,11 @@ public enum ErrorCode implements CodeInfo {
|
||||
|
||||
// -------------------- 自定义 - 业务 --------------------
|
||||
|
||||
OTHER_DEVICE_LOGIN(700, "该账号于 {} 已在其他设备登录 {}({})"),
|
||||
USER_DISABLED(700, "当前用户已禁用"),
|
||||
|
||||
USER_DISABLED(701, "当前用户已禁用"),
|
||||
USER_LOCKED(701, "当前用户已被锁定"),
|
||||
|
||||
USER_LOCKED(702, "当前用户已被锁定"),
|
||||
OTHER_DEVICE_LOGIN(702, "该账号于 {} 已在其他设备登录 {}({})"),
|
||||
|
||||
// -------------------- 自定义 - 通用 --------------------
|
||||
|
||||
|
||||
@@ -31,6 +31,9 @@ public class LoginUser {
|
||||
@Schema(description = "头像地址")
|
||||
private String avatar;
|
||||
|
||||
@Schema(description = "登录时间戳")
|
||||
private Long timestamp;
|
||||
|
||||
@Schema(description = "角色")
|
||||
private List<String> roles;
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.orion.lang.define.cache.CacheKeyDefine;
|
||||
import com.orion.lang.utils.Strings;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -83,7 +84,7 @@ public class RedisStrings extends RedisUtils {
|
||||
* @param keys keys
|
||||
* @return cache
|
||||
*/
|
||||
public static List<JSONObject> getJsonList(List<String> keys) {
|
||||
public static List<JSONObject> getJsonList(Collection<String> keys) {
|
||||
List<String> values = redisTemplate.opsForValue().multiGet(keys);
|
||||
if (values == null) {
|
||||
return new ArrayList<>();
|
||||
@@ -101,7 +102,7 @@ public class RedisStrings extends RedisUtils {
|
||||
* @param <T> T
|
||||
* @return cache
|
||||
*/
|
||||
public static <T> List<T> getJsonList(List<String> keys, CacheKeyDefine define) {
|
||||
public static <T> List<T> getJsonList(Collection<String> keys, CacheKeyDefine define) {
|
||||
return getJsonList(keys, (Class<T>) define.getType());
|
||||
}
|
||||
|
||||
@@ -113,7 +114,7 @@ public class RedisStrings extends RedisUtils {
|
||||
* @param <T> T
|
||||
* @return cache
|
||||
*/
|
||||
public static <T> List<T> getJsonList(List<String> keys, Class<T> type) {
|
||||
public static <T> List<T> getJsonList(Collection<String> keys, Class<T> type) {
|
||||
List<String> values = redisTemplate.opsForValue().multiGet(keys);
|
||||
if (values == null) {
|
||||
return new ArrayList<>();
|
||||
@@ -182,7 +183,7 @@ public class RedisStrings extends RedisUtils {
|
||||
* @param keys keys
|
||||
* @return cache
|
||||
*/
|
||||
public static List<JSONArray> getJsonArrayList(List<String> keys) {
|
||||
public static List<JSONArray> getJsonArrayList(Collection<String> keys) {
|
||||
List<String> values = redisTemplate.opsForValue().multiGet(keys);
|
||||
if (values == null) {
|
||||
return new ArrayList<>();
|
||||
@@ -200,7 +201,7 @@ public class RedisStrings extends RedisUtils {
|
||||
* @param <T> T
|
||||
* @return cache
|
||||
*/
|
||||
public static <T> List<List<T>> getJsonArrayList(List<String> keys, CacheKeyDefine define) {
|
||||
public static <T> List<List<T>> getJsonArrayList(Collection<String> keys, CacheKeyDefine define) {
|
||||
return getJsonArrayList(keys, (Class<T>) define.getType());
|
||||
}
|
||||
|
||||
@@ -212,7 +213,7 @@ public class RedisStrings extends RedisUtils {
|
||||
* @param <T> T
|
||||
* @return cache
|
||||
*/
|
||||
public static <T> List<List<T>> getJsonArrayList(List<String> keys, Class<T> type) {
|
||||
public static <T> List<List<T>> getJsonArrayList(Collection<String> keys, Class<T> type) {
|
||||
List<String> values = redisTemplate.opsForValue().multiGet(keys);
|
||||
if (values == null) {
|
||||
return new ArrayList<>();
|
||||
|
||||
@@ -88,6 +88,16 @@ public class SecurityUtils {
|
||||
return loginUser != null ? loginUser.getUsername() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前 timestamp
|
||||
*
|
||||
* @return timestamp
|
||||
*/
|
||||
public static Long getLoginTimestamp() {
|
||||
LoginUser loginUser = getLoginUser();
|
||||
return loginUser != null ? loginUser.getTimestamp() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置当前用户
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user