mirror of
https://gitee.com/dromara/RuoYi-Vue-Plus.git
synced 2026-09-21 02:25:56 +08:00
update 更新 ThreadLocalHolder 使用 TransmittableThreadLocal 初始化支持异步操作 ;
update 更新 PlusWebInvokeTimeInterceptor 结束后清空缓存 ; rollback 回滚 LOGIN_USER_KEY, DataPermissionHelper 提交 ;
This commit is contained in:
parent
c182fcd103
commit
90177a3eaf
@ -94,6 +94,11 @@
|
|||||||
<artifactId>ip2region</artifactId>
|
<artifactId>ip2region</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba</groupId>
|
||||||
|
<artifactId>transmittable-thread-local</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@ -139,9 +139,4 @@ public interface UserConstants {
|
|||||||
*/
|
*/
|
||||||
Long SUPER_ADMIN_ID = 1L;
|
Long SUPER_ADMIN_ID = 1L;
|
||||||
|
|
||||||
/**
|
|
||||||
* 登录用户 key
|
|
||||||
*/
|
|
||||||
String LOGIN_USER_KEY = "loginUser";
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
package org.dromara.common.core.context;
|
package org.dromara.common.core.context;
|
||||||
|
|
||||||
|
import com.alibaba.ttl.TransmittableThreadLocal;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -13,12 +15,7 @@ public class ThreadLocalHolder {
|
|||||||
/**
|
/**
|
||||||
* 初始化 (支持异步)
|
* 初始化 (支持异步)
|
||||||
*/
|
*/
|
||||||
private static final ThreadLocal<Map<String, Object>> THREAD_LOCAL = new InheritableThreadLocal<>() {
|
private static final ThreadLocal<Map<String, Object>> THREAD_LOCAL = TransmittableThreadLocal.withInitial(HashMap::new);
|
||||||
@Override
|
|
||||||
protected Map<String, Object> initialValue() {
|
|
||||||
return new HashMap<>();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置值
|
* 设置值
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
package org.dromara.common.mybatis.helper;
|
package org.dromara.common.mybatis.helper;
|
||||||
|
|
||||||
|
import cn.dev33.satoken.context.SaHolder;
|
||||||
|
import cn.dev33.satoken.context.model.SaStorage;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import com.baomidou.mybatisplus.core.plugins.IgnoreStrategy;
|
import com.baomidou.mybatisplus.core.plugins.IgnoreStrategy;
|
||||||
import com.baomidou.mybatisplus.core.plugins.InterceptorIgnoreHelper;
|
import com.baomidou.mybatisplus.core.plugins.InterceptorIgnoreHelper;
|
||||||
@ -35,10 +37,11 @@ public class DataPermissionHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Map<String, Object> getContext() {
|
public static Map<String, Object> getContext() {
|
||||||
Object attribute = ThreadLocalHolder.get(DATA_PERMISSION_KEY);
|
SaStorage saStorage = SaHolder.getStorage();
|
||||||
|
Object attribute = saStorage.get(DATA_PERMISSION_KEY);
|
||||||
if (ObjectUtil.isNull(attribute)) {
|
if (ObjectUtil.isNull(attribute)) {
|
||||||
ThreadLocalHolder.set(DATA_PERMISSION_KEY, new HashMap<>());
|
saStorage.set(DATA_PERMISSION_KEY, new HashMap<>());
|
||||||
attribute = ThreadLocalHolder.get(DATA_PERMISSION_KEY);
|
attribute = saStorage.get(DATA_PERMISSION_KEY);
|
||||||
}
|
}
|
||||||
if (attribute instanceof Map map) {
|
if (attribute instanceof Map map) {
|
||||||
return map;
|
return map;
|
||||||
|
|||||||
@ -31,7 +31,7 @@ import java.util.function.Supplier;
|
|||||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||||
public class LoginHelper {
|
public class LoginHelper {
|
||||||
|
|
||||||
public static final String LOGIN_USER_KEY = UserConstants.LOGIN_USER_KEY;
|
public static final String LOGIN_USER_KEY = "loginUser";
|
||||||
public static final String TENANT_KEY = "tenantId";
|
public static final String TENANT_KEY = "tenantId";
|
||||||
public static final String USER_KEY = "userId";
|
public static final String USER_KEY = "userId";
|
||||||
public static final String DEPT_KEY = "deptId";
|
public static final String DEPT_KEY = "deptId";
|
||||||
|
|||||||
@ -73,7 +73,7 @@ public class PlusWebInvokeTimeInterceptor implements HandlerInterceptor {
|
|||||||
StopWatch stopWatch = ThreadLocalHolder.get(STOP_WATCH_KEY);
|
StopWatch stopWatch = ThreadLocalHolder.get(STOP_WATCH_KEY);
|
||||||
stopWatch.stop();
|
stopWatch.stop();
|
||||||
log.info("[PLUS]结束请求 => URL[{}],耗时:[{}]毫秒", request.getMethod() + " " + request.getRequestURI(), stopWatch.getTime());
|
log.info("[PLUS]结束请求 => URL[{}],耗时:[{}]毫秒", request.getMethod() + " " + request.getRequestURI(), stopWatch.getTime());
|
||||||
ThreadLocalHolder.remove(STOP_WATCH_KEY);
|
ThreadLocalHolder.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user