mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-12 21:02:08 +08:00
新增webcad生产单导入:拆单异步还原
This commit is contained in:
+57
-4
@@ -78,6 +78,8 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@@ -99,7 +101,7 @@ public class WebCadOrderImportFactory {
|
|||||||
/**
|
/**
|
||||||
* 批量操作阈值
|
* 批量操作阈值
|
||||||
*/
|
*/
|
||||||
private static final int BATCH_THRESHOLD_NUMBER = 300;
|
private static final int BATCH_THRESHOLD_NUMBER = 200;
|
||||||
|
|
||||||
private OrderMapper orderMapper;
|
private OrderMapper orderMapper;
|
||||||
|
|
||||||
@@ -1615,14 +1617,58 @@ public class WebCadOrderImportFactory {
|
|||||||
private void saveDataAsync() {
|
private void saveDataAsync() {
|
||||||
TransactionStatus transactionStatus = transactionManager.getTransaction(TransactionDefinition.withDefaults());
|
TransactionStatus transactionStatus = transactionManager.getTransaction(TransactionDefinition.withDefaults());
|
||||||
AtomicBoolean hasError = new AtomicBoolean(false);
|
AtomicBoolean hasError = new AtomicBoolean(false);
|
||||||
|
ExecutorService executorService = Executors.newFixedThreadPool(3);
|
||||||
CountDownLatch latch = new CountDownLatch(3);
|
CountDownLatch latch = new CountDownLatch(3);
|
||||||
// 当前数据源data_code
|
// 当前数据源data_code
|
||||||
String peek = DynamicDataSourceContextHolder.peek();
|
String peek = DynamicDataSourceContextHolder.peek();
|
||||||
|
|
||||||
// 保存
|
// 保存
|
||||||
saveBodyAsync(latch, hasError, peek);
|
// saveBodyAsync(latch, hasError, peek);
|
||||||
saveGroupAsync(latch, hasError, peek);
|
// saveGroupAsync(latch, hasError, peek);
|
||||||
saveItemAsync(latch, hasError, peek);
|
// saveItemAsync(latch, hasError, peek);
|
||||||
|
Runnable bodyTask = () -> {
|
||||||
|
try {
|
||||||
|
// 子线程同步主线程的多数据源
|
||||||
|
DynamicDataSourceContextHolder.push(peek);
|
||||||
|
orderInfoBatchInsertWithinThreshold(orderBodyMapper, bodyMap.values().stream().toList(), true);
|
||||||
|
} catch (Exception e) {
|
||||||
|
hasError.set(true);
|
||||||
|
log.error("Error saving order bodies", e);
|
||||||
|
} finally {
|
||||||
|
latch.countDown();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Runnable itemTask = () -> {
|
||||||
|
try {
|
||||||
|
// 子线程同步主线程的多数据源
|
||||||
|
DynamicDataSourceContextHolder.push(peek);
|
||||||
|
orderInfoBatchInsertWithinThreshold(orderItemMapper, orderItemDOS, true);
|
||||||
|
} catch (Exception e) {
|
||||||
|
hasError.set(true);
|
||||||
|
log.error("Error saving order items", e);
|
||||||
|
} finally {
|
||||||
|
latch.countDown();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Runnable groupTask = () -> {
|
||||||
|
try {
|
||||||
|
// 子线程同步主线程的多数据源
|
||||||
|
DynamicDataSourceContextHolder.push(peek);
|
||||||
|
orderInfoBatchInsertWithinThreshold(orderGroupMapper, orderGroupDOS, true);
|
||||||
|
} catch (Exception e) {
|
||||||
|
hasError.set(true);
|
||||||
|
log.error("Error saving order groups", e);
|
||||||
|
} finally {
|
||||||
|
latch.countDown();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 执行子线程
|
||||||
|
executorService.submit(bodyTask);
|
||||||
|
executorService.submit(itemTask);
|
||||||
|
executorService.submit(groupTask);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 等待所有任务完成
|
// 等待所有任务完成
|
||||||
@@ -1631,6 +1677,9 @@ public class WebCadOrderImportFactory {
|
|||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
hasError.set(true);
|
hasError.set(true);
|
||||||
log.error("WEBCAD import saveData Thread interrupted", e);
|
log.error("WEBCAD import saveData Thread interrupted", e);
|
||||||
|
} finally {
|
||||||
|
// 中止所有任务
|
||||||
|
executorService.shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasError.get()) {
|
if (hasError.get()) {
|
||||||
@@ -1767,4 +1816,8 @@ public class WebCadOrderImportFactory {
|
|||||||
sealEdgeConfigList.clear();
|
sealEdgeConfigList.clear();
|
||||||
processGroupMap.clear();
|
processGroupMap.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.out.println(Math.ceil(205/100));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user