Browse Source

1.多租户逻辑修改

dist.1.3.0
zhenghaoyu 11 months ago
parent
commit
fc0549ce6a
  1. 2
      blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/TrunkLineApplication.java
  2. 4
      blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/config/ExecutorConfig.java
  3. 2
      blade-service/logpm-warehouse/src/main/java/com/logpm/warehouse/WarehouseApplication.java
  4. 63
      blade-service/logpm-warehouse/src/main/java/com/logpm/warehouse/config/ExecutorConfig.java
  5. 4
      blade-service/logpm-warehouse/src/main/java/com/logpm/warehouse/feign/WarehouseWaybillClient.java

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

@ -19,6 +19,7 @@ package com.logpm.trunkline;
import org.springblade.common.constant.ModuleNameConstant;
import org.springblade.core.cloud.client.BladeCloudApplication;
import org.springblade.core.launch.BladeApplication;
import org.springblade.core.transaction.annotation.SeataCloudApplication;
/**
* Demo启动器
@ -26,6 +27,7 @@ import org.springblade.core.launch.BladeApplication;
* @author Chill
*/
@BladeCloudApplication
@SeataCloudApplication
public class TrunkLineApplication {
public static void main(String[] args) {

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

@ -27,9 +27,9 @@ public class ExecutorConfig {
// 配置最大线程数
threadPoolTaskExecutor.setMaxPoolSize(20);
// 配置队列大小
// threadPoolTaskExecutor.setQueueCapacity(ThreadPoolConstant.QUEUE_CAPACITY);
threadPoolTaskExecutor.setQueueCapacity(50);
// 配置线程池中线程的名称前缀
threadPoolTaskExecutor.setThreadNamePrefix("IMPORT_ADVANCE_DATA");
threadPoolTaskExecutor.setThreadNamePrefix("ASYNC_THREAD_");
// HelloWorldServiceImpl rejection-policy: 当pool已经达到max size时,如何处理新任务:
// CallerRunsPolicy: 不在新线程中执行任务,而是由调用者所在的线程来执行;
// AbortPolicy: 拒绝执行新任务,并抛出RejectedExecutionException异常;

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

@ -19,6 +19,7 @@ package com.logpm.warehouse;
import org.springblade.common.constant.ModuleNameConstant;
import org.springblade.core.cloud.client.BladeCloudApplication;
import org.springblade.core.launch.BladeApplication;
import org.springblade.core.transaction.annotation.SeataCloudApplication;
/**
* Demo启动器
@ -26,6 +27,7 @@ import org.springblade.core.launch.BladeApplication;
* @author Chill
*/
@BladeCloudApplication
@SeataCloudApplication
public class WarehouseApplication {
public static void main(String[] args) {

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

@ -0,0 +1,63 @@
package com.logpm.warehouse.config;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.TaskDecorator;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import javax.annotation.Nonnull;
import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;
@Configuration
@Slf4j
@EnableAsync
public class ExecutorConfig {
@Bean
public Executor asyncExecutor() {
log.info("start async executor");
ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor();
// 配置核心线程数
threadPoolTaskExecutor.setCorePoolSize(10);
// 配置最大线程数
threadPoolTaskExecutor.setMaxPoolSize(20);
// 配置队列大小
threadPoolTaskExecutor.setQueueCapacity(50);
// 配置线程池中线程的名称前缀
threadPoolTaskExecutor.setThreadNamePrefix("ASYNC_THREAD_");
// HelloWorldServiceImpl rejection-policy: 当pool已经达到max size时,如何处理新任务:
// CallerRunsPolicy: 不在新线程中执行任务,而是由调用者所在的线程来执行;
// AbortPolicy: 拒绝执行新任务,并抛出RejectedExecutionException异常;
// DiscardPolicy:丢弃当前将要加入队列的任务;
// DiscardOldestPolicy:丢弃任务队列中最旧的任务;
threadPoolTaskExecutor.setRejectedExecutionHandler(
new ThreadPoolExecutor.CallerRunsPolicy()
);
threadPoolTaskExecutor.setTaskDecorator(new ContextCopyingDecorator());
threadPoolTaskExecutor.initialize();
return threadPoolTaskExecutor;
}
static class ContextCopyingDecorator implements TaskDecorator {
@Nonnull
@Override
public Runnable decorate(@Nonnull Runnable runnable) {
RequestAttributes context = RequestContextHolder.currentRequestAttributes();
return () -> {
try {
RequestContextHolder.setRequestAttributes(context);
runnable.run();
} finally {
RequestContextHolder.resetRequestAttributes();
}
};
}
}
}

4
blade-service/logpm-warehouse/src/main/java/com/logpm/warehouse/feign/WarehouseWaybillClient.java

@ -7,7 +7,7 @@ import lombok.AllArgsConstructor;
import org.springblade.core.mp.support.BladePage;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tenant.annotation.NonDS;
import org.springblade.core.secure.utils.AuthUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
@ -36,6 +36,8 @@ public class WarehouseWaybillClient implements IWarehouseWaybillClient {
@Override
@GetMapping(API_PREFIX + "/findByWaybillNo")
public WarehouseWaybillEntity findByWaybillNo(String waybillNo) {
String tenantId = AuthUtil.getTenantId();
return warehouseWaybillService.findByWaybillNo(waybillNo);
}

Loading…
Cancel
Save