diff --git a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/undefined/LoginUser.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/undefined/LoginUser.java
index 3e167e38..d93e713d 100644
--- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/undefined/LoginUser.java
+++ b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/undefined/LoginUser.java
@@ -1,5 +1,6 @@
package cc.iotkit.common.undefined;
+import cc.iotkit.common.utils.StringUtils;
import lombok.Data;
import lombok.NoArgsConstructor;
@@ -117,4 +118,26 @@ public class LoginUser implements Serializable {
return userType + ":" + userId;
}
+ /**
+ * 根据loginId构造loginUser对象
+ *
+ * @param loginId 登录id
+ * @return LoginUser
+ * @see LoginUser::getLoginId
+ */
+ public static LoginUser from(String loginId) {
+ if (StringUtils.isBlank(loginId)) {
+ return null;
+ }
+ String[] split = loginId.split(":");
+ if (split.length < 2) {
+ return null;
+ }
+
+ LoginUser user = new LoginUser();
+ user.setUserType(split[0]);
+ user.setUserId(Long.parseLong(split[1]));
+ return user;
+ }
+
}
diff --git a/iot-common/iot-common-satoken/pom.xml b/iot-common/iot-common-satoken/pom.xml
index 2e10d678..22600dc9 100644
--- a/iot-common/iot-common-satoken/pom.xml
+++ b/iot-common/iot-common-satoken/pom.xml
@@ -19,6 +19,11 @@
sa-token-spring-boot-starter
+
+ cn.dev33
+ sa-token-dao-redis-jackson
+
+
cn.dev33
diff --git a/iot-common/iot-common-satoken/src/main/java/cc/iotkit/common/satoken/utils/LoginHelper.java b/iot-common/iot-common-satoken/src/main/java/cc/iotkit/common/satoken/utils/LoginHelper.java
index 49392f2c..bea9fbbe 100644
--- a/iot-common/iot-common-satoken/src/main/java/cc/iotkit/common/satoken/utils/LoginHelper.java
+++ b/iot-common/iot-common-satoken/src/main/java/cc/iotkit/common/satoken/utils/LoginHelper.java
@@ -60,8 +60,8 @@ public class LoginHelper {
model.setDevice(deviceType.getDevice());
}
StpUtil.login(loginUser.getLoginId(),
- model.setExtra(TENANT_KEY, loginUser.getTenantId())
- .setExtra(USER_KEY, loginUser.getUserId()));
+ model.setExtra(TENANT_KEY, loginUser.getTenantId())
+ .setExtra(USER_KEY, loginUser.getUserId()));
StpUtil.getTokenSession().set(LOGIN_USER_KEY, loginUser);
}
@@ -89,17 +89,15 @@ public class LoginHelper {
* 获取用户id
*/
public static Long getUserId() {
- Long userId;
try {
- userId = Convert.toLong(SaHolder.getStorage().get(USER_KEY));
- if (ObjectUtil.isNull(userId)) {
- userId = Convert.toLong(StpUtil.getExtra(USER_KEY));
- SaHolder.getStorage().set(USER_KEY, userId);
+ LoginUser user = LoginUser.from(StpUtil.getLoginIdAsString());
+ if (user == null) {
+ return null;
}
+ return user.getUserId();
} catch (Exception e) {
return null;
}
- return userId;
}
/**
diff --git a/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/handler/ResponseResultHandler.java b/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/handler/ResponseResultHandler.java
index b943fa38..09e3e8f8 100644
--- a/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/handler/ResponseResultHandler.java
+++ b/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/handler/ResponseResultHandler.java
@@ -10,7 +10,6 @@
package cc.iotkit.common.web.handler;
import cc.iotkit.common.api.Response;
-
import cn.dev33.satoken.util.SaResult;
import org.springframework.core.MethodParameter;
import org.springframework.http.MediaType;
@@ -18,20 +17,15 @@ import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.server.ServerHttpRequest;
import org.springframework.http.server.ServerHttpResponse;
import org.springframework.web.bind.annotation.ControllerAdvice;
-import org.springframework.web.context.request.RequestContextHolder;
-import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
-import javax.servlet.http.HttpServletRequest;
import java.util.Map;
@ControllerAdvice
public class ResponseResultHandler implements ResponseBodyAdvice
+
+
+ cn.dev33
+ sa-token-dao-redis-jackson
+ ${satoken.version}
+
+
cn.dev33