1、禅道#1456问题修复;2、webcad拆单导入优化、注释完善;

This commit is contained in:
gaoqr
2025-04-02 12:07:02 +08:00
parent 444f9cc0cb
commit 1d98af568d
5 changed files with 200 additions and 92 deletions
@@ -61,7 +61,7 @@ public class WebCadDataBlockReqVO {
private Long plateGoodsId; private Long plateGoodsId;
private String goodsId; private String goodsId;
private List<GroupInfo> groupInfos = new ArrayList<>(); private List<Integer> groupIds = new ArrayList<>();
@NoArgsConstructor @NoArgsConstructor
@Data @Data
@@ -62,7 +62,7 @@ public class WebCadDataPartsReqVO {
private Long imesPartsId; private Long imesPartsId;
private List<WebCadDataBlockReqVO.GroupInfo> groupInfos = new ArrayList<>(); private List<Integer> groupIds = new ArrayList<>();
private GroupDataDTO groupData; private GroupDataDTO groupData;
@@ -0,0 +1,30 @@
package com.cf.imes.module.plan.framework.executor.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import java.util.concurrent.ThreadPoolExecutor;
/**
* @author Gqr
* @since 2025/3/24 15:21
*/
@Configuration(proxyBeanMethods = false)
public class PlanThreadPoolConfiguration {
public static final String PLAN_IMPOT_THREAD_POOL_TASK_EXECUTOR = "PLAN_IMPORT_THREAD_POOL_TASK_EXECUTOR";
@Bean(PLAN_IMPOT_THREAD_POOL_TASK_EXECUTOR)
public ThreadPoolTaskExecutor planThreadPoolTaskExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(8); // 设置核心线程数
executor.setMaxPoolSize(8); // 设置最大线程数
executor.setKeepAliveSeconds(60); // 设置空闲时间
executor.setQueueCapacity(100); // 设置队列大小
executor.setThreadNamePrefix("plan-import-Executor-"); // 配置线程池的前缀
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
// 进行加载
executor.initialize();
return executor;
}
}
@@ -26,6 +26,7 @@ import com.cf.imes.module.system.api.systemconfig.SystemConfigApi;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.jdbc.datasource.DataSourceTransactionManager; import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@@ -34,6 +35,7 @@ import javax.annotation.Resource;
import static com.cf.imes.module.executor.enums.ErrorCodeConstants.ORDER_IMPORT_ORGAN_LOCK_ERROR; import static com.cf.imes.module.executor.enums.ErrorCodeConstants.ORDER_IMPORT_ORGAN_LOCK_ERROR;
import static com.cf.imes.module.plan.enums.ErrorCodeConstants.WEBCAD_ORDER_IMPORT_FAILED; import static com.cf.imes.module.plan.enums.ErrorCodeConstants.WEBCAD_ORDER_IMPORT_FAILED;
import static com.cf.imes.module.plan.enums.ErrorCodeConstants.WEBCAD_ORDER_IMPORT_ORGANID_EMPTY_ERROR; import static com.cf.imes.module.plan.enums.ErrorCodeConstants.WEBCAD_ORDER_IMPORT_ORGANID_EMPTY_ERROR;
import static com.cf.imes.module.plan.framework.executor.config.PlanThreadPoolConfiguration.PLAN_IMPOT_THREAD_POOL_TASK_EXECUTOR;
/** /**
* 生产单导入服务Service实现类 * 生产单导入服务Service实现类
@@ -96,6 +98,9 @@ public class WebCadOrderImportServiceImpl implements WebCadOrderImportService {
@Resource @Resource
private SystemConfigApi systemConfigApi; private SystemConfigApi systemConfigApi;
@Resource(name = PLAN_IMPOT_THREAD_POOL_TASK_EXECUTOR)
private ThreadPoolTaskExecutor threadPoolTaskExecutor;
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void webCadOrderImport(WebCadDataReqVO webCadDataReqVO) { public void webCadOrderImport(WebCadDataReqVO webCadDataReqVO) {
@@ -112,7 +117,7 @@ public class WebCadOrderImportServiceImpl implements WebCadOrderImportService {
throw new ServiceException(ORDER_IMPORT_ORGAN_LOCK_ERROR); throw new ServiceException(ORDER_IMPORT_ORGAN_LOCK_ERROR);
} }
WebCadOrderImportFactory webCadOrderImportFactory = new WebCadOrderImportFactory(organId, orderMapper, snowFlakeGenerator, orderBodyMapper, plateMapper, orderItemMapper, orderGroupMapper, WebCadOrderImportFactory webCadOrderImportFactory = new WebCadOrderImportFactory(organId, orderMapper, snowFlakeGenerator, orderBodyMapper, plateMapper, orderItemMapper, orderGroupMapper,
idWorker, orderInputProcessor, orderPartsMapper, goodsMapper, rawGoodsMapper, plateGoodMapper, customPlateNoGenerateService, transactionManager, systemConfigApi); idWorker, orderInputProcessor, orderPartsMapper, goodsMapper, rawGoodsMapper, plateGoodMapper, customPlateNoGenerateService, transactionManager, systemConfigApi, threadPoolTaskExecutor);
webCadOrderImportFactory.analyzeTempData(webCadDataReqVO); webCadOrderImportFactory.analyzeTempData(webCadDataReqVO);
} catch (ServiceException se) { } catch (ServiceException se) {
throw se; throw se;
@@ -65,6 +65,7 @@ import com.cf.imes.module.system.api.systemconfig.dto.SystemConfigSealEdgeRespDT
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.springframework.jdbc.datasource.DataSourceTransactionManager; import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.transaction.TransactionDefinition; import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus; import org.springframework.transaction.TransactionStatus;
@@ -77,8 +78,6 @@ 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;
@@ -98,9 +97,9 @@ import static com.cf.imes.module.plan.service.order.OrderInputProcessor.ORDER_PL
@Slf4j @Slf4j
public class WebCadOrderImportFactory { public class WebCadOrderImportFactory {
/** /**
* 分组中做分页的阈值,如:总数100以上就边分组边分页,否则一次性查出来 * 批量操作阈值
*/ */
private static final int BATCH_THRESHOLD_NUMBER = 100; private static final int BATCH_THRESHOLD_NUMBER = 300;
private OrderMapper orderMapper; private OrderMapper orderMapper;
@@ -132,6 +131,8 @@ public class WebCadOrderImportFactory {
private DataSourceTransactionManager transactionManager; private DataSourceTransactionManager transactionManager;
private ThreadPoolTaskExecutor threadPoolTaskExecutor;
private Long organId; private Long organId;
// 批次id // 批次id
@@ -163,6 +164,9 @@ public class WebCadOrderImportFactory {
// 房间名+柜体名+加工组名 // 房间名+柜体名+加工组名
private Map<String, OrderGroupDO> orderGroupMap = new HashMap<>(); private Map<String, OrderGroupDO> orderGroupMap = new HashMap<>();
// 加工组缓存
private Map<Integer, WebCadDataBlockReqVO.GroupInfo> processGroupMap = new HashMap<>();
private List<PlateDO> plateDOS = ListUtils.newArrayListWithExpectedSize(BATCH_THRESHOLD_NUMBER); private List<PlateDO> plateDOS = ListUtils.newArrayListWithExpectedSize(BATCH_THRESHOLD_NUMBER);
private List<OrderItemDO> orderItemDOS = ListUtils.newArrayListWithExpectedSize(BATCH_THRESHOLD_NUMBER); private List<OrderItemDO> orderItemDOS = ListUtils.newArrayListWithExpectedSize(BATCH_THRESHOLD_NUMBER);
private List<OrderGroupDO> orderGroupDOS = ListUtils.newArrayListWithExpectedSize(BATCH_THRESHOLD_NUMBER); private List<OrderGroupDO> orderGroupDOS = ListUtils.newArrayListWithExpectedSize(BATCH_THRESHOLD_NUMBER);
@@ -173,9 +177,9 @@ public class WebCadOrderImportFactory {
private List<SystemConfigSealEdgeRespDTO> sealEdgeConfigList; private List<SystemConfigSealEdgeRespDTO> sealEdgeConfigList;
private static String PART_CATEGORY_ONE = "封边条"; private static final String PART_CATEGORY_ONE = "封边条";
private static String PART_CATEGORY_TWO = "五金"; private static final String PART_CATEGORY_TWO = "五金";
private static String PART_CATEGORY_THREE = "组件"; private static final String PART_CATEGORY_THREE = "组件";
private static final String EMPTY_STRING = new String(); private static final String EMPTY_STRING = new String();
public WebCadOrderImportFactory(Long organId, public WebCadOrderImportFactory(Long organId,
@@ -193,7 +197,8 @@ public class WebCadOrderImportFactory {
PlateGoodMapper plateGoodMapper, PlateGoodMapper plateGoodMapper,
CustomPlateNoGenerateService customPlateNoGenerateService, CustomPlateNoGenerateService customPlateNoGenerateService,
DataSourceTransactionManager transactionManager, DataSourceTransactionManager transactionManager,
SystemConfigApi systemConfigApi) { SystemConfigApi systemConfigApi,
ThreadPoolTaskExecutor threadPoolTaskExecutor) {
this.organId = organId; this.organId = organId;
this.orderMapper = orderMapper; this.orderMapper = orderMapper;
this.snowFlakeGenerator = snowFlakeGenerator; this.snowFlakeGenerator = snowFlakeGenerator;
@@ -210,6 +215,7 @@ public class WebCadOrderImportFactory {
this.customPlateNoGenerateService = customPlateNoGenerateService; this.customPlateNoGenerateService = customPlateNoGenerateService;
this.transactionManager = transactionManager; this.transactionManager = transactionManager;
this.systemConfigApi = systemConfigApi; this.systemConfigApi = systemConfigApi;
this.threadPoolTaskExecutor = threadPoolTaskExecutor;
operatorName = SecurityFrameworkUtils.getLoginUser().getNickname(); operatorName = SecurityFrameworkUtils.getLoginUser().getNickname();
now = LocalDateTime.now(); now = LocalDateTime.now();
batchId = (Long) snowFlakeGenerator.nextId(null); batchId = (Long) snowFlakeGenerator.nextId(null);
@@ -242,8 +248,8 @@ public class WebCadOrderImportFactory {
// 解析配件列表 // 解析配件列表
analyzeParts(webCadDataReqVO.getParts()); analyzeParts(webCadDataReqVO.getParts());
// 数据保存入库 // 异步保存数据
saveData(); saveDataAsync();
} catch (Exception e) { } catch (Exception e) {
if (esInsert) { if (esInsert) {
@@ -419,10 +425,18 @@ public class WebCadOrderImportFactory {
// 加工组信息缓存到cad block和part上 // 加工组信息缓存到cad block和part上
if (CollUtil.isNotEmpty(projects)) { if (CollUtil.isNotEmpty(projects)) {
for (WebCadDataProcessGroupReqVO.ProjectsDTO project : projects) { for (WebCadDataProcessGroupReqVO.ProjectsDTO project : projects) {
// 缓存加工组信息
WebCadDataBlockReqVO.GroupInfo processGroupInfo = new WebCadDataBlockReqVO.GroupInfo();
processGroupInfo.setGroupName(project.getProjName());
processGroupInfo.setGroupTypeName(groupTypeName);
processGroupInfo.setHeight(project.getBoxSize().getHeight());
processGroupInfo.setWidth(project.getBoxSize().getWidth());
processGroupInfo.setDepth(project.getBoxSize().getDepth());
processGroupMap.put(project.getGroupID(), processGroupInfo);
// 板件 // 板件
processBlocksGroup(project, blockReqVOS, groupTypeName); processBlocksGroup(project, blockReqVOS);
// 配件 // 配件
processPartsGroup(project, partsReqVO, groupTypeName); processPartsGroup(project, partsReqVO);
} }
} }
} }
@@ -430,49 +444,35 @@ public class WebCadOrderImportFactory {
} }
/** /**
* 存板件加工组 * 加工组缓存到对应的板件下
* *
* @param project * @param project
* @param blockReqVOS * @param blockReqVOS
* @param groupTypeName
*/ */
private void processBlocksGroup(WebCadDataProcessGroupReqVO.ProjectsDTO project, List<WebCadDataBlockReqVO> blockReqVOS, String groupTypeName) { private void processBlocksGroup(WebCadDataProcessGroupReqVO.ProjectsDTO project, List<WebCadDataBlockReqVO> blockReqVOS) {
List<Integer> brIds = project.getBrIds(); List<Integer> brIds = project.getBrIds();
if (CollUtil.isNotEmpty(brIds)) { if (CollUtil.isNotEmpty(brIds)) {
for (Integer brId : brIds) { for (Integer brId : brIds) {
// brId 板件序号获取板件 // brId 板件序号获取板件
WebCadDataBlockReqVO webCadDataBlockReqVO = blockReqVOS.get(brId - 1); WebCadDataBlockReqVO webCadDataBlockReqVO = blockReqVOS.get(brId - 1);
WebCadDataBlockReqVO.GroupInfo groupInfo = new WebCadDataBlockReqVO.GroupInfo(); webCadDataBlockReqVO.getGroupIds().add(project.getGroupID());
groupInfo.setGroupTypeName(groupTypeName);
groupInfo.setGroupName(project.getProjName());
groupInfo.setWidth(project.getBoxSize().getWidth());
groupInfo.setHeight(project.getBoxSize().getHeight());
groupInfo.setDepth(project.getBoxSize().getDepth());
webCadDataBlockReqVO.getGroupInfos().add(groupInfo);
} }
} }
} }
/** /**
* 存配件加工组 * 加工组缓存到对应的配件下
* *
* @param project * @param project
* @param partsReqVO * @param partsReqVO
* @param groupTypeName
*/ */
private void processPartsGroup(WebCadDataProcessGroupReqVO.ProjectsDTO project, WebCadDataPartsReqVO partsReqVO, String groupTypeName) { private void processPartsGroup(WebCadDataProcessGroupReqVO.ProjectsDTO project, WebCadDataPartsReqVO partsReqVO) {
List<Integer> objIds = project.getObjIds(); List<Integer> objIds = project.getObjIds();
if (CollUtil.isNotEmpty(objIds)) { if (CollUtil.isNotEmpty(objIds)) {
for (Integer objId : objIds) { for (Integer objId : objIds) {
// objId 配件序号获取配件 // objId 配件序号获取配件
WebCadDataPartsReqVO.BlockObjectListDTO part = partsReqVO.getBlockObjectList().get(objId - 1); WebCadDataPartsReqVO.BlockObjectListDTO part = partsReqVO.getBlockObjectList().get(objId - 1);
WebCadDataBlockReqVO.GroupInfo groupInfo = new WebCadDataBlockReqVO.GroupInfo(); part.getGroupIds().add(project.getGroupID());
groupInfo.setGroupTypeName(groupTypeName);
groupInfo.setGroupName(project.getProjName());
groupInfo.setWidth(project.getBoxSize().getWidth());
groupInfo.setHeight(project.getBoxSize().getHeight());
groupInfo.setDepth(project.getBoxSize().getDepth());
part.getGroupInfos().add(groupInfo);
} }
} }
} }
@@ -632,7 +632,7 @@ public class WebCadOrderImportFactory {
// 从info.remarks中获取备注相关 // 从info.remarks中获取备注相关
WebCadDataBlockRemarkVO plateRemark = getPlateRemark(blockInfo); WebCadDataBlockRemarkVO plateRemark = getPlateRemark(blockInfo);
List<String> remarks = plateRemark.getRemarks(); List<String> remarks = plateRemark.getRemarks();
StringBuffer remark = new StringBuffer(); StringBuilder remark = new StringBuilder();
if (CollUtil.isNotEmpty(remarks)) { if (CollUtil.isNotEmpty(remarks)) {
for (String remarkStr : remarks) { for (String remarkStr : remarks) {
remark.append(remarkStr).append(","); remark.append(remarkStr).append(",");
@@ -1063,10 +1063,11 @@ public class WebCadOrderImportFactory {
// 是否矩形,不是矩形那就是异形 // 是否矩形,不是矩形那就是异形
Boolean unRegular = !infoDTO.getIsRect(); Boolean unRegular = !infoDTO.getIsRect();
List<WebCadDataBlockReqVO.GroupInfo> groupInfos = block.getGroupInfos(); List<Integer> groupIds = block.getGroupIds();
if (CollUtil.isNotEmpty(groupInfos)) { if (CollUtil.isNotEmpty(groupIds)) {
// 加工组缓存存在,一个加工组一个orderGroup+orderItem // 加工组缓存存在,一个加工组一个orderGroup+orderItem
for (WebCadDataBlockReqVO.GroupInfo groupInfo : groupInfos) { for (Integer groupId : groupIds) {
WebCadDataBlockReqVO.GroupInfo groupInfo = processGroupMap.get(groupId);
String groupMapKey = orderBodyDO.getMultiRoomBodyName() + groupInfo.getGroupName(); String groupMapKey = orderBodyDO.getMultiRoomBodyName() + groupInfo.getGroupName();
OrderGroupDO orderGroupDO = orderGroupMap.get(groupMapKey); OrderGroupDO orderGroupDO = orderGroupMap.get(groupMapKey);
// 房间+柜体+加工组名称存在累加板件和异形数量,不存在新增groupDO和orderGroupMap缓存 // 房间+柜体+加工组名称存在累加板件和异形数量,不存在新增groupDO和orderGroupMap缓存
@@ -1245,12 +1246,13 @@ public class WebCadOrderImportFactory {
Long roomId = orderBodyDO.getRoomId(); Long roomId = orderBodyDO.getRoomId();
// 遍历加工组信息,生成对应的orderItem // 遍历加工组信息,生成对应的orderItem
List<WebCadDataBlockReqVO.GroupInfo> groupInfos = part.getGroupInfos(); List<Integer> groupIds = part.getGroupIds();
if (CollUtil.isNotEmpty(groupInfos)) { if (CollUtil.isNotEmpty(groupIds)) {
Double partNum = 0.0; Double partNum = 0.0;
// 带加工组的配件增加item只记录配件id和数量 // 带加工组的配件增加item只记录配件id和数量
partNum += part.getNum(); partNum += part.getNum();
for (WebCadDataBlockReqVO.GroupInfo groupInfo : groupInfos) { for (Integer groupId : groupIds) {
WebCadDataBlockReqVO.GroupInfo groupInfo = processGroupMap.get(groupId);
String groupMapKey = orderBodyDO.getMultiRoomBodyName() + groupInfo.getGroupName(); String groupMapKey = orderBodyDO.getMultiRoomBodyName() + groupInfo.getGroupName();
OrderGroupDO orderGroupDO = orderGroupMap.get(groupMapKey); OrderGroupDO orderGroupDO = orderGroupMap.get(groupMapKey);
// 房间+柜体+加工组名称存在累加配件item,不存在新增groupDO和orderGroupMap缓存 // 房间+柜体+加工组名称存在累加配件item,不存在新增groupDO和orderGroupMap缓存
@@ -1485,6 +1487,8 @@ public class WebCadOrderImportFactory {
} }
/** /**
* 根据对应的宽度修改spec规格中的第二段宽度
*
* @param spec * @param spec
* @param width * @param width
* @return * @return
@@ -1492,6 +1496,10 @@ public class WebCadOrderImportFactory {
private String modifySealEdgeSpec(String spec, String width) { private String modifySealEdgeSpec(String spec, String width) {
if (StringUtils.isNotEmpty(spec)) { if (StringUtils.isNotEmpty(spec)) {
String[] specSplit = spec.split("-"); String[] specSplit = spec.split("-");
// 例:15mm-18mm
if (specSplit.length == 2) {
return specSplit[0] + "-" + width + "mm-";
}
// 例:9mm-18mm-经典檀木 // 例:9mm-18mm-经典檀木
if (specSplit.length == 3) { if (specSplit.length == 3) {
return specSplit[0] + "-" + width + "mm-" + specSplit[2]; return specSplit[0] + "-" + width + "mm-" + specSplit[2];
@@ -1600,62 +1608,21 @@ public class WebCadOrderImportFactory {
} }
} }
/** /**
* 数据保存入库 * 异步保存数据
* orderBody、orderItem、orderGroup * orderBody、orderItem、orderGroup
*/ */
private void saveData() { private void saveDataAsync() {
TransactionStatus transactionStatus = transactionManager.getTransaction(TransactionDefinition.withDefaults()); TransactionStatus transactionStatus = transactionManager.getTransaction(TransactionDefinition.withDefaults());
ExecutorService executorService = Executors.newFixedThreadPool(3);
AtomicBoolean hasError = new AtomicBoolean(false); AtomicBoolean hasError = new AtomicBoolean(false);
CountDownLatch latch = new CountDownLatch(3); CountDownLatch latch = new CountDownLatch(3);
// 当前数据源data_code // 当前数据源data_code
String peek = DynamicDataSourceContextHolder.peek(); String peek = DynamicDataSourceContextHolder.peek();
Runnable bodyTask = () -> { // 保存
try { saveBodyAsync(latch, hasError, peek);
// 子线程同步主线程的多数据源 saveGroupAsync(latch, hasError, peek);
DynamicDataSourceContextHolder.push(peek); saveItemAsync(latch, hasError, 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 {
// 等待所有任务完成 // 等待所有任务完成
@@ -1664,9 +1631,6 @@ 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()) {
@@ -1680,6 +1644,114 @@ public class WebCadOrderImportFactory {
} }
} }
/**
* 异步插入柜体
*
* @param latch
* @param hasError
* @param peek
*/
private void saveBodyAsync(CountDownLatch latch, AtomicBoolean hasError, String peek) {
List<OrderBodyDO> orderBodyDOS = bodyMap.values().stream().toList();
List<List<OrderBodyDO>> bodyList = batchProcess(orderBodyDOS);
for (List<OrderBodyDO> bodyDOS : bodyList) {
threadPoolTaskExecutor.submit(() -> {
try {
// 子线程同步主线程的多数据源
DynamicDataSourceContextHolder.push(peek);
orderBodyMapper.insertBatchSomeColumn(bodyDOS);
} catch (Exception e) {
log.error("WEBCAD import saveBodyAsync error", e);
boolean b = hasError.get();
if (!b) {
hasError.set(true);
}
} finally {
latch.countDown(); // 任务完成,计数器减1
}
});
}
}
/**
* 异步插入加工组
*
* @param latch
* @param hasError
* @param peek
*/
private void saveGroupAsync(CountDownLatch latch, AtomicBoolean hasError, String peek) {
List<List<OrderGroupDO>> groupList = batchProcess(orderGroupDOS);
for (List<OrderGroupDO> orderGroupDOS : groupList) {
threadPoolTaskExecutor.submit(() -> {
try {
// 子线程同步主线程的多数据源
DynamicDataSourceContextHolder.push(peek);
orderGroupMapper.insertBatchSomeColumn(orderGroupDOS);
} catch (Exception e) {
log.error("WEBCAD import saveGroupAsync error", e);
boolean b = hasError.get();
if (!b) {
hasError.set(true);
}
} finally {
latch.countDown(); // 任务完成,计数器减1
}
});
}
}
/**
* 异步插入明细item
*
* @param latch
* @param hasError
* @param peek
*/
private void saveItemAsync(CountDownLatch latch, AtomicBoolean hasError, String peek) {
List<List<OrderItemDO>> itemList = batchProcess(orderItemDOS);
for (List<OrderItemDO> itemDOS : itemList) {
threadPoolTaskExecutor.submit(() -> {
try {
// 子线程同步主线程的多数据源
DynamicDataSourceContextHolder.push(peek);
orderItemMapper.insertBatchSomeColumn(itemDOS);
} catch (Exception e) {
log.error("WEBCAD import saveItemAsync error", e);
boolean b = hasError.get();
if (!b) {
hasError.set(true);
}
} finally {
latch.countDown(); // 任务完成,计数器减1
}
});
}
}
/**
* 每batchSize条拆分dataList
*
* @param dataList
*/
private <T> List<List<T>> batchProcess(List<T> dataList) {
List<List<T>> resultList = new ArrayList<>();
if (CollUtil.isEmpty(dataList)) {
return resultList;
}
int total = dataList.size();
for (int i = 0; i < total; i += BATCH_THRESHOLD_NUMBER) {
int end = Math.min(i + BATCH_THRESHOLD_NUMBER, total);
List<T> subList = dataList.subList(i, end);
if (!subList.isEmpty()) {
resultList.add(subList);
}
}
return resultList;
}
/** /**
* 清空所有列表 * 清空所有列表
*/ */
@@ -1693,5 +1765,6 @@ public class WebCadOrderImportFactory {
roomBodyMap.clear(); roomBodyMap.clear();
bodyMap.clear(); bodyMap.clear();
sealEdgeConfigList.clear(); sealEdgeConfigList.clear();
processGroupMap.clear();
} }
} }