mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-07-25 00:15:06 +08:00
1. 创建流程实例时,同时也插入流程
2. 修改 Activiti 使用 TTL 上下文
This commit is contained in:
@ -1,5 +1,7 @@
|
||||
package cn.iocoder.yudao.framework.activiti.core.util;
|
||||
|
||||
import cn.hutool.core.util.ReflectUtil;
|
||||
import com.alibaba.ttl.TransmittableThreadLocal;
|
||||
import org.activiti.engine.impl.identity.Authentication;
|
||||
|
||||
/**
|
||||
@ -9,6 +11,19 @@ import org.activiti.engine.impl.identity.Authentication;
|
||||
*/
|
||||
public class ActivitiUtils {
|
||||
|
||||
static {
|
||||
setAuthenticationThreadLocal();
|
||||
}
|
||||
|
||||
/**
|
||||
* 反射修改 Authentication 的 authenticatedUserIdThreadLocal 静态变量,使用 TTL 线程变量
|
||||
* 目的:保证 @Async 等异步执行时,变量丢失的问题
|
||||
*/
|
||||
private static void setAuthenticationThreadLocal() {
|
||||
ReflectUtil.setFieldValue(Authentication.class, "authenticatedUserIdThreadLocal",
|
||||
new TransmittableThreadLocal<String>());
|
||||
}
|
||||
|
||||
public static void setAuthenticatedUserId(Long userId) {
|
||||
Authentication.setAuthenticatedUserId(String.valueOf(userId));
|
||||
}
|
||||
|
Reference in New Issue
Block a user