Commit b261830f authored by yanzg's avatar yanzg

表结构修改

parent 12ed2d1a
......@@ -53,6 +53,36 @@ public class TokenHelper {
return String.valueOf(Thread.currentThread().getId());
}
/**
* 获取当前的登录信息
*
* @return 缓存的数据
*/
public static TokenData getTokenData(boolean readNewToken) {
String id = getCurrentId();
TokenData cacheTokenData = cache.get(id);
if (cacheTokenData == null) {
return null;
}
// 获取最新的token
if (!readNewToken) {
return cacheTokenData;
}
boolean isEmpty = cacheTokenData.getData() == null || cacheTokenData.getData().isEmpty();
boolean isExpire = cacheTokenData.getExpire() < System.currentTimeMillis();
boolean isToken = !StringHelper.isEmpty(cacheTokenData.getToken()) && (isEmpty || isExpire);
if (isToken) {
TokenData databaseToken = tokenLoad.load(cacheTokenData.getToken());
if (databaseToken == null || databaseToken.getData() == null) {
return null;
} else {
cache.put(id, databaseToken);
}
}
return cacheTokenData;
}
/**
* 获取当前的登录信息
*
......@@ -85,33 +115,13 @@ public class TokenHelper {
* @return 缓存的数据
*/
public static <T extends Object> T get(boolean checkFlag, Class<T> cls, boolean readNewToken) {
String id = getCurrentId();
TokenData tokenData = cache.get(id);
TokenData tokenData = getTokenData(readNewToken);
if (tokenData == null) {
if (checkFlag) {
throw YzgError.getRuntimeException("061");
}
return null;
}
// 获取最新的token
if (readNewToken) {
boolean isEmpty = tokenData.getData() == null || tokenData.getData().isEmpty();
boolean isExpire = tokenData.getExpire() < System.currentTimeMillis();
boolean isToken = !StringHelper.isEmpty(tokenData.getToken()) && (isEmpty || isExpire);
if (isToken) {
tokenData = tokenLoad.load(tokenData.getToken());
if (tokenData != null) {
cache.put(id, tokenData);
}
}
if (tokenData == null || tokenData.getData() == null) {
if (checkFlag) {
throw YzgError.getRuntimeException("061");
}
return null;
}
}
if (ObjectHelper.isSub(cls, tokenData.getData().getClass())) {
return (T) tokenData.getData();
} else {
......@@ -157,7 +167,17 @@ public class TokenHelper {
* @param data 数据时间
*/
public static void write(String token, Object data) {
write(token, StringHelper.EMPTY, 0, data);
write(token, StringHelper.EMPTY, null, 0, data);
}
/**
* 缓存数据
*
* @param token 标记
* @param data 数据时间
*/
public static void write(String token, RsaHelper.RsaInfo rsaInfo, Object data) {
write(token, StringHelper.EMPTY, rsaInfo, 0, data);
}
/**
......@@ -168,7 +188,7 @@ public class TokenHelper {
* @param data 数据时间
*/
public static void write(String token, long expire, Object data) {
write(token, StringHelper.EMPTY, expire, data);
write(token, StringHelper.EMPTY, null, expire, data);
}
/**
......@@ -180,22 +200,7 @@ public class TokenHelper {
* @param data 数据时间
*/
public static void write(String token, String dataPwd, long expire, Object data) {
String id = getCurrentId();
TokenData tokenData = cache.get(id);
if (tokenData == null) {
tokenData = new TokenData();
cache.put(id, tokenData);
}
tokenData.setToken(token);
tokenData.setDataPwd(dataPwd);
if (expire > 0) {
tokenData.setExpire(expire);
}
if (tokenData.getData() == null) {
tokenData.setData(new MapRow());
}
ObjectHelper.writeWithFrom(tokenData.getData(), data);
tokenData.setWrite(true);
write(token, dataPwd, null, expire, data);
}
......@@ -217,8 +222,10 @@ public class TokenHelper {
}
tokenData.setToken(token);
tokenData.setDataPwd(dataPwd);
tokenData.setPublicKey(rsaInfo.getPublicKey());
tokenData.setPrivateKey(rsaInfo.getPrivateKey());
if (rsaInfo != null) {
tokenData.setPublicKey(rsaInfo.getPublicKey());
tokenData.setPrivateKey(rsaInfo.getPrivateKey());
}
if (expire > 0) {
tokenData.setExpire(expire);
}
......@@ -256,6 +263,7 @@ public class TokenHelper {
return JsonHelper.serialize(tokenData);
}
/**
* 删除缓存信息
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment