|
|
|
@ -1,6 +1,9 @@
|
|
|
|
|
package com.logpm.trunkline.config; |
|
|
|
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import org.slf4j.MDC; |
|
|
|
|
import org.springblade.core.secure.utils.AuthUtil; |
|
|
|
|
import org.springblade.core.tool.utils.ThreadLocalUtil; |
|
|
|
|
import org.springframework.context.annotation.Bean; |
|
|
|
|
import org.springframework.context.annotation.Configuration; |
|
|
|
|
import org.springframework.core.task.TaskDecorator; |
|
|
|
@ -10,6 +13,7 @@ import org.springframework.web.context.request.RequestAttributes;
|
|
|
|
|
import org.springframework.web.context.request.RequestContextHolder; |
|
|
|
|
|
|
|
|
|
import javax.annotation.Nonnull; |
|
|
|
|
import java.util.Map; |
|
|
|
|
import java.util.concurrent.Executor; |
|
|
|
|
import java.util.concurrent.ThreadPoolExecutor; |
|
|
|
|
|
|
|
|
@ -49,12 +53,27 @@ public class ExecutorConfig {
|
|
|
|
|
@Override |
|
|
|
|
public Runnable decorate(@Nonnull Runnable runnable) { |
|
|
|
|
RequestAttributes context = RequestContextHolder.currentRequestAttributes(); |
|
|
|
|
String tenantId = AuthUtil.getTenantId(); |
|
|
|
|
Map<String, Object> all = ThreadLocalUtil.getAll(); |
|
|
|
|
Map<String, String> mdcMap = MDC.getCopyOfContextMap(); |
|
|
|
|
return () -> { |
|
|
|
|
try { |
|
|
|
|
all.keySet().forEach(key -> ThreadLocalUtil.put(key, all.get(key))); |
|
|
|
|
if (mdcMap != null && !mdcMap.isEmpty()) { |
|
|
|
|
MDC.setContextMap(mdcMap); |
|
|
|
|
} |
|
|
|
|
RequestContextHolder.setRequestAttributes(context); |
|
|
|
|
String tenantId1 = AuthUtil.getTenantId(); |
|
|
|
|
|
|
|
|
|
runnable.run(); |
|
|
|
|
} finally { |
|
|
|
|
RequestContextHolder.resetRequestAttributes(); |
|
|
|
|
all.clear(); |
|
|
|
|
if (mdcMap != null) { |
|
|
|
|
mdcMap.clear(); |
|
|
|
|
} |
|
|
|
|
ThreadLocalUtil.clear(); |
|
|
|
|
MDC.clear(); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|