|
@@ -3,6 +3,7 @@ package cn.com.qmth.examcloud.app.service;
|
|
|
import cn.com.qmth.examcloud.app.core.exception.ApiException;
|
|
|
import cn.com.qmth.examcloud.app.core.utils.JsonMapper;
|
|
|
import cn.com.qmth.examcloud.app.core.utils.ThreadUtils;
|
|
|
+import cn.com.qmth.examcloud.app.model.Constants;
|
|
|
import cn.com.qmth.examcloud.app.model.UserToken;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -13,7 +14,7 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
-import static cn.com.qmth.examcloud.app.model.Constants.REDIS_KEY_PREFIX;
|
|
|
+import static cn.com.qmth.examcloud.app.model.Constants.APP_SESSION_USER_KEY_PREFIX;
|
|
|
|
|
|
/**
|
|
|
* @author: fengdesheng
|
|
@@ -54,7 +55,7 @@ public class RedisService {
|
|
|
if (key == null) {
|
|
|
throw new ApiException("Key must be not null.");
|
|
|
}
|
|
|
- this.set(REDIS_KEY_PREFIX + key, new JsonMapper().toJson(value), seconds);
|
|
|
+ this.set(APP_SESSION_USER_KEY_PREFIX + key, new JsonMapper().toJson(value), seconds);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -64,7 +65,7 @@ public class RedisService {
|
|
|
if (key == null) {
|
|
|
throw new ApiException("Key must be not null.");
|
|
|
}
|
|
|
- String value = this.get(REDIS_KEY_PREFIX + key);
|
|
|
+ String value = this.get(APP_SESSION_USER_KEY_PREFIX + key);
|
|
|
if (value != null) {
|
|
|
return new JsonMapper().fromJson(value, UserToken.class);
|
|
|
}
|
|
@@ -77,7 +78,22 @@ public class RedisService {
|
|
|
public void initTraceRequest() {
|
|
|
String key = "C_" + ThreadUtils.getTraceID();
|
|
|
Long millis = System.currentTimeMillis();
|
|
|
- stringRedisTemplate.opsForValue().set(key, millis.toString(), 60, TimeUnit.SECONDS);
|
|
|
+ this.set(key, millis.toString(), 10);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取平台端的默认过期时间(秒)
|
|
|
+ */
|
|
|
+ public int getSessionTimeout() {
|
|
|
+ try {
|
|
|
+ String timeout = this.get(Constants.PLATFORM_SESSION_TIMEOUT_KEY);
|
|
|
+ if (timeout != null) {
|
|
|
+ return Integer.parseInt(timeout);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ //ignore
|
|
|
+ }
|
|
|
+ return Constants.PLATFORM_SESSION_EXPIRE_TIME;
|
|
|
}
|
|
|
|
|
|
}
|