Commit 0eb470e6 authored by yanzg's avatar yanzg

身份证识别

parent abd36a95
...@@ -2,10 +2,10 @@ package com.yanzuoguang.token; ...@@ -2,10 +2,10 @@ package com.yanzuoguang.token;
import com.yanzuoguang.util.YzgError; import com.yanzuoguang.util.YzgError;
import com.yanzuoguang.util.base.ObjectHelper; import com.yanzuoguang.util.base.ObjectHelper;
import com.yanzuoguang.util.cache.MemoryCache;
import com.yanzuoguang.util.helper.JsonHelper; import com.yanzuoguang.util.helper.JsonHelper;
import com.yanzuoguang.util.helper.RsaHelper; import com.yanzuoguang.util.helper.RsaHelper;
import com.yanzuoguang.util.helper.StringHelper; import com.yanzuoguang.util.helper.StringHelper;
import com.yanzuoguang.util.log.Log;
import com.yanzuoguang.util.vo.MapRow; import com.yanzuoguang.util.vo.MapRow;
/** /**
...@@ -41,7 +41,7 @@ public class TokenHelper { ...@@ -41,7 +41,7 @@ public class TokenHelper {
/** /**
* 内存缓存 * 内存缓存
*/ */
protected final static MemoryCache<TokenData> cache = new MemoryCache<>(); protected final static ThreadLocal<TokenData> cache = new ThreadLocal<>();
/** /**
...@@ -59,8 +59,7 @@ public class TokenHelper { ...@@ -59,8 +59,7 @@ public class TokenHelper {
* @return 缓存的数据 * @return 缓存的数据
*/ */
public static TokenData getTokenData(boolean readNewToken) { public static TokenData getTokenData(boolean readNewToken) {
String id = getCurrentId(); TokenData cacheTokenData = cache.get();
TokenData cacheTokenData = cache.get(id);
if (cacheTokenData == null) { if (cacheTokenData == null) {
return null; return null;
} }
...@@ -77,7 +76,7 @@ public class TokenHelper { ...@@ -77,7 +76,7 @@ public class TokenHelper {
if (databaseToken == null || databaseToken.getData() == null) { if (databaseToken == null || databaseToken.getData() == null) {
return null; return null;
} else { } else {
cache.put(id, databaseToken); cache.set(databaseToken);
return databaseToken; return databaseToken;
} }
} }
...@@ -116,7 +115,9 @@ public class TokenHelper { ...@@ -116,7 +115,9 @@ public class TokenHelper {
* @return 缓存的数据 * @return 缓存的数据
*/ */
public static <T> T get(boolean checkFlag, Class<T> cls, boolean readNewToken) { public static <T> T get(boolean checkFlag, Class<T> cls, boolean readNewToken) {
Log.info(TokenHelper.class, "获取登陆信息结果");
TokenData tokenData = getTokenData(readNewToken); TokenData tokenData = getTokenData(readNewToken);
Log.info(TokenHelper.class, "获取登陆信息结果");
if (tokenData == null) { if (tokenData == null) {
if (checkFlag) { if (checkFlag) {
throw YzgError.getRuntimeException("061"); throw YzgError.getRuntimeException("061");
...@@ -243,10 +244,11 @@ public class TokenHelper { ...@@ -243,10 +244,11 @@ public class TokenHelper {
* @param tokenString 登录标记字符串 * @param tokenString 登录标记字符串
*/ */
public static TokenData setTokenString(String tokenString) { public static TokenData setTokenString(String tokenString) {
String id = getCurrentId();
TokenData tokenData = JsonHelper.deserialize(tokenString, TokenData.class); TokenData tokenData = JsonHelper.deserialize(tokenString, TokenData.class);
cache.put(id, tokenData); if (tokenData != null) {
tokenData.setWrite(false); tokenData.setWrite(false);
}
cache.set(tokenData);
return tokenData; return tokenData;
} }
...@@ -256,8 +258,7 @@ public class TokenHelper { ...@@ -256,8 +258,7 @@ public class TokenHelper {
* @return 登录标记字符粗 * @return 登录标记字符粗
*/ */
public static String getTokenString() { public static String getTokenString() {
String id = getCurrentId(); TokenData tokenData = cache.get();
TokenData tokenData = cache.get(id);
if (tokenData == null) { if (tokenData == null) {
return StringHelper.EMPTY; return StringHelper.EMPTY;
} }
...@@ -269,7 +270,6 @@ public class TokenHelper { ...@@ -269,7 +270,6 @@ public class TokenHelper {
* 删除缓存信息 * 删除缓存信息
*/ */
public static void remove() { public static void remove() {
String id = getCurrentId(); cache.remove();
cache.remove(id);
} }
} }
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