Browse Source

1.异步线程创建绑定租户并绑定租户数据源

dist.1.3.0
pref_mail@163.com 9 months ago
parent
commit
dca62a3286
  1. 2
      blade-service/logpm-aftersales/src/main/java/com/logpm/aftersales/aspect/AsyncAnnotationAspect.java
  2. 7
      blade-service/logpm-aftersales/src/main/java/com/logpm/aftersales/config/ExecutorConfig.java
  3. 2
      blade-service/logpm-basic/src/main/java/com/logpm/basic/aspect/AsyncAnnotationAspect.java
  4. 7
      blade-service/logpm-basic/src/main/java/com/logpm/basic/config/ExecutorConfig.java
  5. 2
      blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/aspect/AsyncAnnotationAspect.java
  6. 7
      blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/config/ExecutorConfig.java
  7. 2
      blade-service/logpm-business/src/main/java/com/logpm/business/aspect/AsyncAnnotationAspect.java
  8. 2
      blade-service/logpm-distribution/src/main/java/com/logpm/distribution/aspect/AsyncAnnotationAspect.java
  9. 7
      blade-service/logpm-distribution/src/main/java/com/logpm/distribution/config/ExecutorConfig.java
  10. 2
      blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/aspect/AsyncAnnotationAspect.java
  11. 14
      blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/config/ExecutorConfig.java
  12. 2
      blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/aspect/AsyncAnnotationAspect.java
  13. 14
      blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/config/ExecutorConfig.java
  14. 2
      blade-service/logpm-factory-data/logpm-factory-data-mwh/src/main/java/com/logpm/factorydata/mwh/aspect/AsyncAnnotationAspect.java
  15. 14
      blade-service/logpm-factory-data/logpm-factory-data-mwh/src/main/java/com/logpm/factorydata/mwh/config/ExecutorConfig.java
  16. 2
      blade-service/logpm-factory-data/logpm-factory-data-olo/src/main/java/com/logpm/factorydata/olo/aspect/AsyncAnnotationAspect.java
  17. 14
      blade-service/logpm-factory-data/logpm-factory-data-olo/src/main/java/com/logpm/factorydata/olo/config/ExecutorConfig.java
  18. 2
      blade-service/logpm-factory-data/logpm-factory-data-suofeiya/src/main/java/com/logpm/factorydata/suofeiya/aspect/AsyncAnnotationAspect.java
  19. 14
      blade-service/logpm-factory-data/logpm-factory-data-suofeiya/src/main/java/com/logpm/factorydata/suofeiya/config/ExecutorConfig.java
  20. 2
      blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/aspect/AsyncAnnotationAspect.java
  21. 14
      blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/config/ExecutorConfig.java
  22. 2
      blade-service/logpm-factory/src/main/java/com/logpm/factory/aspect/AsyncAnnotationAspect.java
  23. 8
      blade-service/logpm-factory/src/main/java/com/logpm/factory/config/ExecutorConfig.java
  24. 2
      blade-service/logpm-report/src/main/java/com/logpm/report/aspect/AsyncAnnotationAspect.java
  25. 6
      blade-service/logpm-report/src/main/java/com/logpm/report/config/ExecutorConfig.java
  26. 2
      blade-service/logpm-statisticsdata/src/main/java/com/logpm/statistics/aspect/AsyncAnnotationAspect.java
  27. 2
      blade-service/logpm-supervise/src/main/java/com/logpm/supervise/aspect/AsyncAnnotationAspect.java
  28. 2
      blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/aspect/AsyncAnnotationAspect.java
  29. 7
      blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/config/ExecutorConfig.java
  30. 2
      blade-service/logpm-warehouse/src/main/java/com/logpm/warehouse/aspect/AsyncAnnotationAspect.java
  31. 8
      blade-service/logpm-warehouse/src/main/java/com/logpm/warehouse/config/ExecutorConfig.java
  32. 31
      blade-service/logpm-warehouse/src/main/java/com/logpm/warehouse/service/impl/WarehouseUpdownTypeServiceImpl.java

2
blade-service/logpm-aftersales/src/main/java/com/logpm/aftersales/aspect/AsyncAnnotationAspect.java

@ -23,7 +23,7 @@ public class AsyncAnnotationAspect {
* 定义一个切点匹配所有带有@LogpmAsync("asyncExecutor")注解的方法
* 注意实际上Spring Framework自带对@LogpmAsync("asyncExecutor")的处理直接这样配置可能会导致预期之外的行为
*/
@Around("@annotation(org.springblade.common.annotations.LogpmAsync)")
//@Around("@annotation(org.springblade.common.annotations.LogpmAsync)")
public Object logAroundAsyncMethods(ProceedingJoinPoint joinPoint) throws Throwable {
MethodSignature signature = (MethodSignature) joinPoint.getSignature();

7
blade-service/logpm-aftersales/src/main/java/com/logpm/aftersales/config/ExecutorConfig.java

@ -1,5 +1,6 @@
package com.logpm.aftersales.config;
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.MDC;
import org.springblade.core.secure.utils.AuthUtil;
@ -63,8 +64,9 @@ public class ExecutorConfig {
MDC.setContextMap(mdcMap);
}
RequestContextHolder.setRequestAttributes(context);
String tenantId1 = AuthUtil.getTenantId();
// 未当前的异步线程绑定租户ID 和切换数据源
log.info(">>>> 异步线程创建,绑定租户数据源 {}",tenantId);
DynamicDataSourceContextHolder.push(tenantId);
runnable.run();
} finally {
RequestContextHolder.resetRequestAttributes();
@ -74,6 +76,7 @@ public class ExecutorConfig {
}
ThreadLocalUtil.clear();
MDC.clear();
DynamicDataSourceContextHolder.poll();
}
};
}

2
blade-service/logpm-basic/src/main/java/com/logpm/basic/aspect/AsyncAnnotationAspect.java

@ -23,7 +23,7 @@ public class AsyncAnnotationAspect {
* 定义一个切点匹配所有带有@LogpmAsync("asyncExecutor")注解的方法
* 注意实际上Spring Framework自带对@LogpmAsync("asyncExecutor")的处理直接这样配置可能会导致预期之外的行为
*/
@Around("@annotation(org.springblade.common.annotations.LogpmAsync)")
//@Around("@annotation(org.springblade.common.annotations.LogpmAsync)")
public Object logAroundAsyncMethods(ProceedingJoinPoint joinPoint) throws Throwable {
MethodSignature signature = (MethodSignature) joinPoint.getSignature();

7
blade-service/logpm-basic/src/main/java/com/logpm/basic/config/ExecutorConfig.java

@ -1,5 +1,6 @@
package com.logpm.basic.config;
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.MDC;
import org.springblade.core.secure.utils.AuthUtil;
@ -63,8 +64,9 @@ public class ExecutorConfig {
MDC.setContextMap(mdcMap);
}
RequestContextHolder.setRequestAttributes(context);
String tenantId1 = AuthUtil.getTenantId();
// 未当前的异步线程绑定租户ID 和切换数据源
log.info(">>>> 异步线程创建,绑定租户数据源 {}",tenantId);
DynamicDataSourceContextHolder.push(tenantId);
runnable.run();
} finally {
RequestContextHolder.resetRequestAttributes();
@ -74,6 +76,7 @@ public class ExecutorConfig {
}
ThreadLocalUtil.clear();
MDC.clear();
DynamicDataSourceContextHolder.poll();
}
};
}

2
blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/aspect/AsyncAnnotationAspect.java

@ -23,7 +23,7 @@ public class AsyncAnnotationAspect {
* 定义一个切点匹配所有带有@LogpmAsync("asyncExecutor")注解的方法
* 注意实际上Spring Framework自带对@LogpmAsync("asyncExecutor")的处理直接这样配置可能会导致预期之外的行为
*/
@Around("@annotation(org.springblade.common.annotations.LogpmAsync)")
//@Around("@annotation(org.springblade.common.annotations.LogpmAsync)")
public Object logAroundAsyncMethods(ProceedingJoinPoint joinPoint) throws Throwable {
MethodSignature signature = (MethodSignature) joinPoint.getSignature();

7
blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/config/ExecutorConfig.java

@ -1,5 +1,6 @@
package com.logpm.basicdata.config;
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.MDC;
import org.springblade.core.secure.utils.AuthUtil;
@ -63,8 +64,9 @@ public class ExecutorConfig {
MDC.setContextMap(mdcMap);
}
RequestContextHolder.setRequestAttributes(context);
String tenantId1 = AuthUtil.getTenantId();
// 未当前的异步线程绑定租户ID 和切换数据源
log.info(">>>> 异步线程创建,绑定租户数据源 {}",tenantId);
DynamicDataSourceContextHolder.push(tenantId);
runnable.run();
} finally {
RequestContextHolder.resetRequestAttributes();
@ -74,6 +76,7 @@ public class ExecutorConfig {
}
ThreadLocalUtil.clear();
MDC.clear();
DynamicDataSourceContextHolder.poll();
}
};
}

2
blade-service/logpm-business/src/main/java/com/logpm/business/aspect/AsyncAnnotationAspect.java

@ -23,7 +23,7 @@ public class AsyncAnnotationAspect {
* 定义一个切点匹配所有带有@LogpmAsync("asyncExecutor")注解的方法
* 注意实际上Spring Framework自带对@LogpmAsync("asyncExecutor")的处理直接这样配置可能会导致预期之外的行为
*/
@Around("@annotation(org.springblade.common.annotations.LogpmAsync)")
//@Around("@annotation(org.springblade.common.annotations.LogpmAsync)")
public Object logAroundAsyncMethods(ProceedingJoinPoint joinPoint) throws Throwable {
MethodSignature signature = (MethodSignature) joinPoint.getSignature();

2
blade-service/logpm-distribution/src/main/java/com/logpm/distribution/aspect/AsyncAnnotationAspect.java

@ -25,7 +25,7 @@ public class AsyncAnnotationAspect {
* 定义一个切点匹配所有带有@LogpmAsync("asyncExecutor")注解的方法
* 注意实际上Spring Framework自带对@LogpmAsync("asyncExecutor")的处理直接这样配置可能会导致预期之外的行为
*/
@Around("@annotation(org.springblade.common.annotations.LogpmAsync)")
//@Around("@annotation(org.springblade.common.annotations.LogpmAsync)")
public Object logAroundAsyncMethods(ProceedingJoinPoint joinPoint) throws Throwable {
MethodSignature signature = (MethodSignature) joinPoint.getSignature();

7
blade-service/logpm-distribution/src/main/java/com/logpm/distribution/config/ExecutorConfig.java

@ -1,5 +1,6 @@
package com.logpm.distribution.config;
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.MDC;
import org.springblade.core.secure.utils.AuthUtil;
@ -63,8 +64,9 @@ public class ExecutorConfig {
MDC.setContextMap(mdcMap);
}
RequestContextHolder.setRequestAttributes(context);
String tenantId1 = AuthUtil.getTenantId();
// 未当前的异步线程绑定租户ID 和切换数据源
log.info(">>>> 异步线程创建,绑定租户数据源 {}",tenantId);
DynamicDataSourceContextHolder.push(tenantId);
runnable.run();
} finally {
RequestContextHolder.resetRequestAttributes();
@ -74,6 +76,7 @@ public class ExecutorConfig {
}
ThreadLocalUtil.clear();
MDC.clear();
DynamicDataSourceContextHolder.poll();
}
};
}

2
blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/aspect/AsyncAnnotationAspect.java

@ -23,7 +23,7 @@ public class AsyncAnnotationAspect {
* 定义一个切点匹配所有带有@LogpmAsync("asyncExecutor")注解的方法
* 注意实际上Spring Framework自带对@LogpmAsync("asyncExecutor")的处理直接这样配置可能会导致预期之外的行为
*/
@Around("@annotation(org.springblade.common.annotations.LogpmAsync)")
//@Around("@annotation(org.springblade.common.annotations.LogpmAsync)")
public Object logAroundAsyncMethods(ProceedingJoinPoint joinPoint) throws Throwable {
MethodSignature signature = (MethodSignature) joinPoint.getSignature();

14
blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/config/ExecutorConfig.java

@ -1,12 +1,13 @@
package com.logpm.factorydata.jinpai.config;
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
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;
import org.springframework.http.HttpHeaders;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.web.context.request.RequestAttributes;
@ -53,24 +54,29 @@ public class ExecutorConfig {
@Override
public Runnable decorate(@Nonnull Runnable runnable) {
RequestAttributes context = RequestContextHolder.currentRequestAttributes();
HttpHeaders headers = (HttpHeaders) ThreadLocalUtil.get("bladeContext");
String tenantId = AuthUtil.getTenantId();
Map<String, Object> all = ThreadLocalUtil.getAll();
Map<String, String> mdcMap = MDC.getCopyOfContextMap();
return () -> {
try {
ThreadLocalUtil.put("bladeContext", headers);
all.keySet().forEach(key -> ThreadLocalUtil.put(key, all.get(key)));
if (mdcMap != null && !mdcMap.isEmpty()) {
MDC.setContextMap(mdcMap);
}
RequestContextHolder.setRequestAttributes(context);
// 未当前的异步线程绑定租户ID 和切换数据源
log.info(">>>> 异步线程创建,绑定租户数据源 {}",tenantId);
DynamicDataSourceContextHolder.push(tenantId);
runnable.run();
} finally {
RequestContextHolder.resetRequestAttributes();
all.clear();
if (mdcMap != null) {
mdcMap.clear();
}
ThreadLocalUtil.clear();
MDC.clear();
DynamicDataSourceContextHolder.poll();
}
};
}

2
blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/aspect/AsyncAnnotationAspect.java

@ -23,7 +23,7 @@ public class AsyncAnnotationAspect {
* 定义一个切点匹配所有带有@LogpmAsync("asyncExecutor")注解的方法
* 注意实际上Spring Framework自带对@LogpmAsync("asyncExecutor")的处理直接这样配置可能会导致预期之外的行为
*/
@Around("@annotation(org.springblade.common.annotations.LogpmAsync)")
//@Around("@annotation(org.springblade.common.annotations.LogpmAsync)")
public Object logAroundAsyncMethods(ProceedingJoinPoint joinPoint) throws Throwable {
MethodSignature signature = (MethodSignature) joinPoint.getSignature();

14
blade-service/logpm-factory-data/logpm-factory-data-linsy/src/main/java/com/logpm/factorydata/linsy/config/ExecutorConfig.java

@ -1,12 +1,13 @@
package com.logpm.factorydata.linsy.config;
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
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;
import org.springframework.http.HttpHeaders;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.web.context.request.RequestAttributes;
@ -53,24 +54,29 @@ public class ExecutorConfig {
@Override
public Runnable decorate(@Nonnull Runnable runnable) {
RequestAttributes context = RequestContextHolder.currentRequestAttributes();
HttpHeaders headers = (HttpHeaders) ThreadLocalUtil.get("bladeContext");
String tenantId = AuthUtil.getTenantId();
Map<String, Object> all = ThreadLocalUtil.getAll();
Map<String, String> mdcMap = MDC.getCopyOfContextMap();
return () -> {
try {
ThreadLocalUtil.put("bladeContext", headers);
all.keySet().forEach(key -> ThreadLocalUtil.put(key, all.get(key)));
if (mdcMap != null && !mdcMap.isEmpty()) {
MDC.setContextMap(mdcMap);
}
RequestContextHolder.setRequestAttributes(context);
// 未当前的异步线程绑定租户ID 和切换数据源
log.info(">>>> 异步线程创建,绑定租户数据源 {}",tenantId);
DynamicDataSourceContextHolder.push(tenantId);
runnable.run();
} finally {
RequestContextHolder.resetRequestAttributes();
all.clear();
if (mdcMap != null) {
mdcMap.clear();
}
ThreadLocalUtil.clear();
MDC.clear();
DynamicDataSourceContextHolder.poll();
}
};
}

2
blade-service/logpm-factory-data/logpm-factory-data-mwh/src/main/java/com/logpm/factorydata/mwh/aspect/AsyncAnnotationAspect.java

@ -23,7 +23,7 @@ public class AsyncAnnotationAspect {
* 定义一个切点匹配所有带有@LogpmAsync("asyncExecutor")注解的方法
* 注意实际上Spring Framework自带对@LogpmAsync("asyncExecutor")的处理直接这样配置可能会导致预期之外的行为
*/
@Around("@annotation(org.springblade.common.annotations.LogpmAsync)")
//@Around("@annotation(org.springblade.common.annotations.LogpmAsync)")
public Object logAroundAsyncMethods(ProceedingJoinPoint joinPoint) throws Throwable {
MethodSignature signature = (MethodSignature) joinPoint.getSignature();

14
blade-service/logpm-factory-data/logpm-factory-data-mwh/src/main/java/com/logpm/factorydata/mwh/config/ExecutorConfig.java

@ -1,12 +1,13 @@
package com.logpm.factorydata.mwh.config;
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
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;
import org.springframework.http.HttpHeaders;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.web.context.request.RequestAttributes;
@ -53,24 +54,29 @@ public class ExecutorConfig {
@Override
public Runnable decorate(@Nonnull Runnable runnable) {
RequestAttributes context = RequestContextHolder.currentRequestAttributes();
HttpHeaders headers = (HttpHeaders) ThreadLocalUtil.get("bladeContext");
String tenantId = AuthUtil.getTenantId();
Map<String, Object> all = ThreadLocalUtil.getAll();
Map<String, String> mdcMap = MDC.getCopyOfContextMap();
return () -> {
try {
ThreadLocalUtil.put("bladeContext", headers);
all.keySet().forEach(key -> ThreadLocalUtil.put(key, all.get(key)));
if (mdcMap != null && !mdcMap.isEmpty()) {
MDC.setContextMap(mdcMap);
}
RequestContextHolder.setRequestAttributes(context);
// 未当前的异步线程绑定租户ID 和切换数据源
log.info(">>>> 异步线程创建,绑定租户数据源 {}",tenantId);
DynamicDataSourceContextHolder.push(tenantId);
runnable.run();
} finally {
RequestContextHolder.resetRequestAttributes();
all.clear();
if (mdcMap != null) {
mdcMap.clear();
}
ThreadLocalUtil.clear();
MDC.clear();
DynamicDataSourceContextHolder.poll();
}
};
}

2
blade-service/logpm-factory-data/logpm-factory-data-olo/src/main/java/com/logpm/factorydata/olo/aspect/AsyncAnnotationAspect.java

@ -23,7 +23,7 @@ public class AsyncAnnotationAspect {
* 定义一个切点匹配所有带有@LogpmAsync("asyncExecutor")注解的方法
* 注意实际上Spring Framework自带对@LogpmAsync("asyncExecutor")的处理直接这样配置可能会导致预期之外的行为
*/
@Around("@annotation(org.springblade.common.annotations.LogpmAsync)")
//@Around("@annotation(org.springblade.common.annotations.LogpmAsync)")
public Object logAroundAsyncMethods(ProceedingJoinPoint joinPoint) throws Throwable {
MethodSignature signature = (MethodSignature) joinPoint.getSignature();

14
blade-service/logpm-factory-data/logpm-factory-data-olo/src/main/java/com/logpm/factorydata/olo/config/ExecutorConfig.java

@ -1,12 +1,13 @@
package com.logpm.factorydata.olo.config;
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
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;
import org.springframework.http.HttpHeaders;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.web.context.request.RequestAttributes;
@ -53,24 +54,29 @@ public class ExecutorConfig {
@Override
public Runnable decorate(@Nonnull Runnable runnable) {
RequestAttributes context = RequestContextHolder.currentRequestAttributes();
HttpHeaders headers = (HttpHeaders) ThreadLocalUtil.get("bladeContext");
String tenantId = AuthUtil.getTenantId();
Map<String, Object> all = ThreadLocalUtil.getAll();
Map<String, String> mdcMap = MDC.getCopyOfContextMap();
return () -> {
try {
ThreadLocalUtil.put("bladeContext", headers);
all.keySet().forEach(key -> ThreadLocalUtil.put(key, all.get(key)));
if (mdcMap != null && !mdcMap.isEmpty()) {
MDC.setContextMap(mdcMap);
}
RequestContextHolder.setRequestAttributes(context);
// 未当前的异步线程绑定租户ID 和切换数据源
log.info(">>>> 异步线程创建,绑定租户数据源 {}",tenantId);
DynamicDataSourceContextHolder.push(tenantId);
runnable.run();
} finally {
RequestContextHolder.resetRequestAttributes();
all.clear();
if (mdcMap != null) {
mdcMap.clear();
}
ThreadLocalUtil.clear();
MDC.clear();
DynamicDataSourceContextHolder.poll();
}
};
}

2
blade-service/logpm-factory-data/logpm-factory-data-suofeiya/src/main/java/com/logpm/factorydata/suofeiya/aspect/AsyncAnnotationAspect.java

@ -23,7 +23,7 @@ public class AsyncAnnotationAspect {
* 定义一个切点匹配所有带有@LogpmAsync("asyncExecutor")注解的方法
* 注意实际上Spring Framework自带对@LogpmAsync("asyncExecutor")的处理直接这样配置可能会导致预期之外的行为
*/
@Around("@annotation(org.springblade.common.annotations.LogpmAsync)")
//@Around("@annotation(org.springblade.common.annotations.LogpmAsync)")
public Object logAroundAsyncMethods(ProceedingJoinPoint joinPoint) throws Throwable {
MethodSignature signature = (MethodSignature) joinPoint.getSignature();

14
blade-service/logpm-factory-data/logpm-factory-data-suofeiya/src/main/java/com/logpm/factorydata/suofeiya/config/ExecutorConfig.java

@ -1,12 +1,13 @@
package com.logpm.factorydata.suofeiya.config;
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
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;
import org.springframework.http.HttpHeaders;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.web.context.request.RequestAttributes;
@ -53,24 +54,29 @@ public class ExecutorConfig {
@Override
public Runnable decorate(@Nonnull Runnable runnable) {
RequestAttributes context = RequestContextHolder.currentRequestAttributes();
HttpHeaders headers = (HttpHeaders) ThreadLocalUtil.get("bladeContext");
String tenantId = AuthUtil.getTenantId();
Map<String, Object> all = ThreadLocalUtil.getAll();
Map<String, String> mdcMap = MDC.getCopyOfContextMap();
return () -> {
try {
ThreadLocalUtil.put("bladeContext", headers);
all.keySet().forEach(key -> ThreadLocalUtil.put(key, all.get(key)));
if (mdcMap != null && !mdcMap.isEmpty()) {
MDC.setContextMap(mdcMap);
}
RequestContextHolder.setRequestAttributes(context);
// 未当前的异步线程绑定租户ID 和切换数据源
log.info(">>>> 异步线程创建,绑定租户数据源 {}",tenantId);
DynamicDataSourceContextHolder.push(tenantId);
runnable.run();
} finally {
RequestContextHolder.resetRequestAttributes();
all.clear();
if (mdcMap != null) {
mdcMap.clear();
}
ThreadLocalUtil.clear();
MDC.clear();
DynamicDataSourceContextHolder.poll();
}
};
}

2
blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/aspect/AsyncAnnotationAspect.java

@ -23,7 +23,7 @@ public class AsyncAnnotationAspect {
* 定义一个切点匹配所有带有@LogpmAsync("asyncExecutor")注解的方法
* 注意实际上Spring Framework自带对@LogpmAsync("asyncExecutor")的处理直接这样配置可能会导致预期之外的行为
*/
@Around("@annotation(org.springblade.common.annotations.LogpmAsync)")
//@Around("@annotation(org.springblade.common.annotations.LogpmAsync)")
public Object logAroundAsyncMethods(ProceedingJoinPoint joinPoint) throws Throwable {
MethodSignature signature = (MethodSignature) joinPoint.getSignature();

14
blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/config/ExecutorConfig.java

@ -1,12 +1,13 @@
package com.logpm.factorydata.zbom.config;
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
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;
import org.springframework.http.HttpHeaders;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.web.context.request.RequestAttributes;
@ -53,24 +54,29 @@ public class ExecutorConfig {
@Override
public Runnable decorate(@Nonnull Runnable runnable) {
RequestAttributes context = RequestContextHolder.currentRequestAttributes();
HttpHeaders headers = (HttpHeaders) ThreadLocalUtil.get("bladeContext");
String tenantId = AuthUtil.getTenantId();
Map<String, Object> all = ThreadLocalUtil.getAll();
Map<String, String> mdcMap = MDC.getCopyOfContextMap();
return () -> {
try {
ThreadLocalUtil.put("bladeContext", headers);
all.keySet().forEach(key -> ThreadLocalUtil.put(key, all.get(key)));
if (mdcMap != null && !mdcMap.isEmpty()) {
MDC.setContextMap(mdcMap);
}
RequestContextHolder.setRequestAttributes(context);
// 未当前的异步线程绑定租户ID 和切换数据源
log.info(">>>> 异步线程创建,绑定租户数据源 {}",tenantId);
DynamicDataSourceContextHolder.push(tenantId);
runnable.run();
} finally {
RequestContextHolder.resetRequestAttributes();
all.clear();
if (mdcMap != null) {
mdcMap.clear();
}
ThreadLocalUtil.clear();
MDC.clear();
DynamicDataSourceContextHolder.poll();
}
};
}

2
blade-service/logpm-factory/src/main/java/com/logpm/factory/aspect/AsyncAnnotationAspect.java

@ -23,7 +23,7 @@ public class AsyncAnnotationAspect {
* 定义一个切点匹配所有带有@LogpmAsync("asyncExecutor")注解的方法
* 注意实际上Spring Framework自带对@LogpmAsync("asyncExecutor")的处理直接这样配置可能会导致预期之外的行为
*/
@Around("@annotation(org.springblade.common.annotations.LogpmAsync)")
// //@Around("@annotation(org.springblade.common.annotations.LogpmAsync)")
public Object logAroundAsyncMethods(ProceedingJoinPoint joinPoint) throws Throwable {
MethodSignature signature = (MethodSignature) joinPoint.getSignature();

8
blade-service/logpm-factory/src/main/java/com/logpm/factory/config/ExecutorConfig.java

@ -1,5 +1,6 @@
package com.logpm.factory.config;
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.MDC;
import org.springblade.core.secure.utils.AuthUtil;
@ -63,9 +64,9 @@ public class ExecutorConfig {
MDC.setContextMap(mdcMap);
}
RequestContextHolder.setRequestAttributes(context);
String tenantId1 = AuthUtil.getTenantId();
log.info(">>>>>>>>>>>>>>>> decorate {}",tenantId1);
// 未当前的异步线程绑定租户ID 和切换数据源
log.info(">>>> 异步线程创建,绑定租户数据源 {}",tenantId);
DynamicDataSourceContextHolder.push(tenantId);
runnable.run();
} finally {
RequestContextHolder.resetRequestAttributes();
@ -75,6 +76,7 @@ public class ExecutorConfig {
}
ThreadLocalUtil.clear();
MDC.clear();
DynamicDataSourceContextHolder.poll();
}
};
}

2
blade-service/logpm-report/src/main/java/com/logpm/report/aspect/AsyncAnnotationAspect.java

@ -23,7 +23,7 @@ public class AsyncAnnotationAspect {
* 定义一个切点匹配所有带有@LogpmAsync("asyncExecutor")注解的方法
* 注意实际上Spring Framework自带对@LogpmAsync("asyncExecutor")的处理直接这样配置可能会导致预期之外的行为
*/
@Around("@annotation(org.springblade.common.annotations.LogpmAsync)")
//@Around("@annotation(org.springblade.common.annotations.LogpmAsync)")
public Object logAroundAsyncMethods(ProceedingJoinPoint joinPoint) throws Throwable {
MethodSignature signature = (MethodSignature) joinPoint.getSignature();

6
blade-service/logpm-report/src/main/java/com/logpm/report/config/ExecutorConfig.java

@ -64,9 +64,10 @@ public class ExecutorConfig {
MDC.setContextMap(mdcMap);
}
RequestContextHolder.setRequestAttributes(context);
DynamicDataSourceContextHolder.push(AuthUtil.getTenantId());
// 未当前的异步线程绑定租户ID 和切换数据源
log.info(">>>> 异步线程创建,绑定租户数据源 {}",tenantId);
DynamicDataSourceContextHolder.push(tenantId);
runnable.run();
DynamicDataSourceContextHolder.poll();
} finally {
RequestContextHolder.resetRequestAttributes();
all.clear();
@ -75,6 +76,7 @@ public class ExecutorConfig {
}
ThreadLocalUtil.clear();
MDC.clear();
DynamicDataSourceContextHolder.poll();
}
};
}

2
blade-service/logpm-statisticsdata/src/main/java/com/logpm/statistics/aspect/AsyncAnnotationAspect.java

@ -23,7 +23,7 @@ public class AsyncAnnotationAspect {
* 定义一个切点匹配所有带有@LogpmAsync("asyncExecutor")注解的方法
* 注意实际上Spring Framework自带对@LogpmAsync("asyncExecutor")的处理直接这样配置可能会导致预期之外的行为
*/
@Around("@annotation(org.springblade.common.annotations.LogpmAsync)")
//@Around("@annotation(org.springblade.common.annotations.LogpmAsync)")
public Object logAroundAsyncMethods(ProceedingJoinPoint joinPoint) throws Throwable {
MethodSignature signature = (MethodSignature) joinPoint.getSignature();

2
blade-service/logpm-supervise/src/main/java/com/logpm/supervise/aspect/AsyncAnnotationAspect.java

@ -23,7 +23,7 @@ public class AsyncAnnotationAspect {
* 定义一个切点匹配所有带有@LogpmAsync("asyncExecutor")注解的方法
* 注意实际上Spring Framework自带对@LogpmAsync("asyncExecutor")的处理直接这样配置可能会导致预期之外的行为
*/
@Around("@annotation(org.springblade.common.annotations.LogpmAsync)")
//@Around("@annotation(org.springblade.common.annotations.LogpmAsync)")
public Object logAroundAsyncMethods(ProceedingJoinPoint joinPoint) throws Throwable {
MethodSignature signature = (MethodSignature) joinPoint.getSignature();

2
blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/aspect/AsyncAnnotationAspect.java

@ -23,7 +23,7 @@ public class AsyncAnnotationAspect {
* 定义一个切点匹配所有带有@LogpmAsync("asyncExecutor")注解的方法
* 注意实际上Spring Framework自带对@LogpmAsync("asyncExecutor")的处理直接这样配置可能会导致预期之外的行为
*/
@Around("@annotation(org.springblade.common.annotations.LogpmAsync)")
////@Around("@annotation(org.springblade.common.annotations.LogpmAsync)")
public Object logAroundAsyncMethods(ProceedingJoinPoint joinPoint) throws Throwable {
MethodSignature signature = (MethodSignature) joinPoint.getSignature();

7
blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/config/ExecutorConfig.java

@ -1,5 +1,6 @@
package com.logpm.trunkline.config;
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.MDC;
import org.springblade.core.secure.utils.AuthUtil;
@ -63,8 +64,9 @@ public class ExecutorConfig {
MDC.setContextMap(mdcMap);
}
RequestContextHolder.setRequestAttributes(context);
String tenantId1 = AuthUtil.getTenantId();
// 未当前的异步线程绑定租户ID 和切换数据源
log.info(">>>> 异步线程创建,绑定租户数据源 {}",tenantId);
DynamicDataSourceContextHolder.push(tenantId);
runnable.run();
} finally {
RequestContextHolder.resetRequestAttributes();
@ -74,6 +76,7 @@ public class ExecutorConfig {
}
ThreadLocalUtil.clear();
MDC.clear();
DynamicDataSourceContextHolder.poll();
}
};
}

2
blade-service/logpm-warehouse/src/main/java/com/logpm/warehouse/aspect/AsyncAnnotationAspect.java

@ -23,7 +23,7 @@ public class AsyncAnnotationAspect {
* 定义一个切点匹配所有带有@LogpmAsync("asyncExecutor")注解的方法
* 注意实际上Spring Framework自带对@LogpmAsync("asyncExecutor")的处理直接这样配置可能会导致预期之外的行为
*/
@Around("@annotation(org.springblade.common.annotations.LogpmAsync)")
//@Around("@annotation(org.springblade.common.annotations.LogpmAsync)")
public Object logAroundAsyncMethods(ProceedingJoinPoint joinPoint) throws Throwable {
MethodSignature signature = (MethodSignature) joinPoint.getSignature();

8
blade-service/logpm-warehouse/src/main/java/com/logpm/warehouse/config/ExecutorConfig.java

@ -1,7 +1,9 @@
package com.logpm.warehouse.config;
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
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;
@ -52,6 +54,7 @@ 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 () -> {
@ -61,7 +64,9 @@ public class ExecutorConfig {
MDC.setContextMap(mdcMap);
}
RequestContextHolder.setRequestAttributes(context);
// 未当前的异步线程绑定租户ID 和切换数据源
log.info(">>>> 异步线程创建,绑定租户数据源 {}",tenantId);
DynamicDataSourceContextHolder.push(tenantId);
runnable.run();
} finally {
RequestContextHolder.resetRequestAttributes();
@ -71,6 +76,7 @@ public class ExecutorConfig {
}
ThreadLocalUtil.clear();
MDC.clear();
DynamicDataSourceContextHolder.poll();
}
};
}

31
blade-service/logpm-warehouse/src/main/java/com/logpm/warehouse/service/impl/WarehouseUpdownTypeServiceImpl.java

@ -33,6 +33,7 @@ import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.ObjectUtil;
import org.springblade.core.tool.utils.StringUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -1995,16 +1996,22 @@ public class WarehouseUpdownTypeServiceImpl extends BaseServiceImpl<WarehouseUpd
warehouseGoodsAllocationClient.updateAllocationCache(allocationId.toString());
}
// for (String orderCode : orderSet) {
// distributionStockArticleClient.updateOrderInfo(orderCode, warehouseId);
// }
try{
if(orderPackageCodes.isEmpty()){
log.warn(">>>> 没有需要下架的包件");
return Resp.scanSuccess("下架成功", "成功下架" + 0 + "件");
}
FindParamterDTO findParamterDTO = new FindParamterDTO();
findParamterDTO.setOrderPackageCodeList(orderPackageCodes);
findParamterDTO.setWarehouseId(warehouseId);
List<DistributionParcelListEntity> parcelListEntityList = distributionParcelListClient.findListByOrderPackageCodeList(findParamterDTO);
if(ObjectUtil.isEmpty(parcelListEntityList)){
log.warn(">>>> 当前包件集合 {}没有上架信息",orderPackageCodes);
return Resp.scanSuccess("下架成功", "成功下架" + 0 + "件");
}
//把parcelListEntityList中所有元素的conditions作为key进行分组成一个Map
Map<Integer, List<DistributionParcelListEntity>> listMap = parcelListEntityList.stream().collect(Collectors.groupingBy(DistributionParcelListEntity::getConditions));
@ -2041,8 +2048,6 @@ public class WarehouseUpdownTypeServiceImpl extends BaseServiceImpl<WarehouseUpd
log.info(">>>>> T downPackageAndDelTrayAndIsUpdate start");
int num = 0;
Set<String> orderSet = new TreeSet<>();
// upShelfPackageList
List<String> barcodeList = upShelfPackageList.stream()
@ -2151,27 +2156,11 @@ public class WarehouseUpdownTypeServiceImpl extends BaseServiceImpl<WarehouseUpd
log.warn("###########downPackageAndDelTrayAndIsUpdate: 发送打托广播失败");
}
}
}
}
// for (String orderCode : orderSet) {
// distributionStockArticleClient.updateOrderInfo(orderCode, warehouseId);
// }
// List<String> orders = new ArrayList<>(orderSet);
// if (orders.isEmpty()) {
// return Resp.scanSuccess("下架成功", "成功下架" + num + "件");
// }
// OrderPackageDTO orderPackageDTO1 = new OrderPackageDTO();
// orderPackageDTO1.setWarehouseId(warehouseId);
// orderPackageDTO1.setStrings(orders);
// distributionStockArticleClient.updateOrdersInfo(orderPackageDTO1);
// log.info(">>>>> T downPackageAndDelTrayAndIsUpdate end");
return Resp.scanSuccess("下架成功", "成功下架" + num + "件");
}

Loading…
Cancel
Save