Commit ee8a1640 authored by 刘林's avatar 刘林

fix:(jg):导入功能去掉异步执行,避免用户取消操作导致脏数据

parent cb3ef711
......@@ -192,8 +192,6 @@ public class DataDockServiceImpl {
* @param equLists 数据集
* @return 保存结果
*/
@Transactional(rollbackFor = Exception.class)
@GlobalTransactional(rollbackFor = Exception.class)
public boolean xiAnSaveEquipmentData(List<Map<String, Object>> equLists) {
RequestContextWrapper contextWrapper = RequestContextWrapper.capture();
Set<String> recordSet = new HashSet<>();
......@@ -214,6 +212,7 @@ public class DataDockServiceImpl {
}
@GlobalTransactional(rollbackFor = Exception.class)
@Transactional(rollbackFor = Exception.class)
public String saveEquipmentDataInTransaction(Map<String, Object> equ, String dataSource, String remark) {
ReginParams reginParams = JSONObject.parseObject(redisUtils.get(RedisKey.buildReginKey(RequestContext.getExeUserId(), RequestContext.getToken())).toString(), ReginParams.class);
CompanyBo company = reginParams.getCompany();
......@@ -2350,35 +2349,19 @@ public class DataDockServiceImpl {
}
CompletableFuture<Void> useInfoFuture = CompletableFuture.runAsync(
() -> idxBizJgRegisterInfoServiceImpl.batchInsert(idxBizJgUseInfoMapper, useInfoList, "使用信息"));
CompletableFuture<Void> designInfoFuture = CompletableFuture.runAsync(
() -> idxBizJgRegisterInfoServiceImpl.batchInsert(idxBizJgDesignInfoMapper, designInfoList, "设计信息"));
CompletableFuture<Void> constructionFuture = CompletableFuture.runAsync(
() -> idxBizJgRegisterInfoServiceImpl.batchInsert(idxBizJgConstructionInfoMapper, constructionInfoList, "施工信息"));
CompletableFuture<Void> factoryFuture = CompletableFuture.runAsync(
() -> idxBizJgRegisterInfoServiceImpl.batchInsert(idxBizJgFactoryInfoMapper, factoryInfoList, "制造信息"));
CompletableFuture<Void> registerFuture = CompletableFuture.runAsync(
() -> idxBizJgRegisterInfoServiceImpl.batchInsert(idxBizJgRegisterInfoMapper, registerInfoList, "登记信息"));
CompletableFuture<Void> otherFuture = CompletableFuture.runAsync(
() -> idxBizJgRegisterInfoServiceImpl.batchInsert(idxBizJgOtherInfoMapper, otherInfoList, "其他信息"));
CompletableFuture<Void> supervisionFuture = CompletableFuture.runAsync(
() -> idxBizJgRegisterInfoServiceImpl.batchInsert(idxBizJgSupervisionInfoMapper, supervisionInfoList, "监管信息"));
CompletableFuture<Void> paramsPipelineFuture = CompletableFuture.runAsync(
() -> idxBizJgRegisterInfoServiceImpl.batchInsert(idxBizJgTechParamsPipelineMapper, paramsPipelineList, "管道参数信息"));
CompletableFuture<Void> inspectionFuture = CompletableFuture.runAsync(
() -> idxBizJgRegisterInfoServiceImpl.batchInsert(idxBizJgInspectionDetectionInfoMapper, inspectionDetectionInfoList, "检验检测信息"));
CompletableFuture<Void> esFuture = CompletableFuture.runAsync(() -> {
if (!esEquipmentCategoryList.isEmpty()) {
esEquipmentCategory.saveAll(esEquipmentCategoryList);
log.info("ES批量保存完成,数量:{}", esEquipmentCategoryList.size());
}
});
CompletableFuture.allOf(
useInfoFuture, designInfoFuture, constructionFuture, factoryFuture,
registerFuture, otherFuture, supervisionFuture, paramsPipelineFuture,
inspectionFuture, esFuture
).join();
idxBizJgRegisterInfoServiceImpl.batchInsert(idxBizJgUseInfoMapper, useInfoList, "使用信息");
idxBizJgRegisterInfoServiceImpl.batchInsert(idxBizJgDesignInfoMapper, designInfoList, "设计信息");
idxBizJgRegisterInfoServiceImpl.batchInsert(idxBizJgConstructionInfoMapper, constructionInfoList, "施工信息");
idxBizJgRegisterInfoServiceImpl.batchInsert(idxBizJgFactoryInfoMapper, factoryInfoList, "制造信息");
idxBizJgRegisterInfoServiceImpl.batchInsert(idxBizJgRegisterInfoMapper, registerInfoList, "登记信息");
idxBizJgRegisterInfoServiceImpl.batchInsert(idxBizJgOtherInfoMapper, otherInfoList, "其他信息");
idxBizJgRegisterInfoServiceImpl.batchInsert(idxBizJgSupervisionInfoMapper, supervisionInfoList, "监管信息");
idxBizJgRegisterInfoServiceImpl.batchInsert(idxBizJgTechParamsPipelineMapper, paramsPipelineList, "管道参数信息");
idxBizJgRegisterInfoServiceImpl.batchInsert(idxBizJgInspectionDetectionInfoMapper, inspectionDetectionInfoList, "检验检测信息");
if (!esEquipmentCategoryList.isEmpty()) {
esEquipmentCategory.saveAll(esEquipmentCategoryList);
log.info("ES批量保存完成,数量:{}", esEquipmentCategoryList.size());
}
log.info("所有批量操作完成");
return recordList;
}
......
......@@ -4808,18 +4808,14 @@ public class IdxBizJgRegisterInfoServiceImpl extends BaseService<IdxBizJgRegiste
}
batchInsert(idxBizJgUseInfoMapper, useInfoList, "使用信息");
batchInsert(idxBizJgRegisterInfoMapper, registerInfoList, "注册信息");
List<CompletableFuture<Void>> futures = new ArrayList<>();
futures.add(CompletableFuture.runAsync(() -> batchInsert(idxBizJgSupervisionInfoMapper, supervisionInfoList, "监督信息"), executor));
futures.add(CompletableFuture.runAsync(() -> batchInsert(idxBizJgDesignInfoMapper, designInfoList, "设计信息"), executor));
futures.add(CompletableFuture.runAsync(() -> batchInsert(idxBizJgFactoryInfoMapper, factoryInfoList, "制造信息"), executor));
futures.add(CompletableFuture.runAsync(() -> batchInsert(otherInfoMapper, otherInfoList, "其他信息"), executor));
futures.add(CompletableFuture.runAsync(() -> batchInsert(idxBizJgTechParamsVesselMapper, paramsVesselList, "容器参数信息"), executor));
futures.add(CompletableFuture.runAsync(() -> batchInsert(idxBizJgInspectionDetectionInfoMapper, inspectionDetectionInfoList, "检验检测信息"), executor));
futures.add(CompletableFuture.runAsync(() -> batchInsert(certificateChangeRecordEqMapper, jgCertificateChangeRecordEqList, "登记证关系信息"), executor));
futures.add(CompletableFuture.runAsync(() -> esEquipmentCategory.saveAll(esEquipmentCategoryList), executor));
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join();
batchInsert(idxBizJgSupervisionInfoMapper, supervisionInfoList, "监督信息");
batchInsert(idxBizJgDesignInfoMapper, designInfoList, "设计信息");
batchInsert(idxBizJgFactoryInfoMapper, factoryInfoList, "制造信息");
batchInsert(otherInfoMapper, otherInfoList, "其他信息");
batchInsert(idxBizJgTechParamsVesselMapper, paramsVesselList, "容器参数信息");
batchInsert(idxBizJgInspectionDetectionInfoMapper, inspectionDetectionInfoList, "检验检测信息");
batchInsert(certificateChangeRecordEqMapper, jgCertificateChangeRecordEqList, "登记证关系信息");
esEquipmentCategory.saveAll(esEquipmentCategoryList);
// 使用事务同步回调确保事件在事务提交后发送
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() {
@Override
......@@ -4836,8 +4832,6 @@ public class IdxBizJgRegisterInfoServiceImpl extends BaseService<IdxBizJgRegiste
});
return String.format("导入完成,成功导入: %d 条数据!", useInfoList.size());
}
// 定义线程池,CPU 核数 * 2,避免阻塞主线程
ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 2);
/** 通用批量插入方法 */
public <T> void batchInsert(CustomBaseMapper<T> mapper, List<T> list, String name) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment