Commit ee8a1640 authored by 刘林's avatar 刘林

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

parent cb3ef711
...@@ -192,8 +192,6 @@ public class DataDockServiceImpl { ...@@ -192,8 +192,6 @@ public class DataDockServiceImpl {
* @param equLists 数据集 * @param equLists 数据集
* @return 保存结果 * @return 保存结果
*/ */
@Transactional(rollbackFor = Exception.class)
@GlobalTransactional(rollbackFor = Exception.class)
public boolean xiAnSaveEquipmentData(List<Map<String, Object>> equLists) { public boolean xiAnSaveEquipmentData(List<Map<String, Object>> equLists) {
RequestContextWrapper contextWrapper = RequestContextWrapper.capture(); RequestContextWrapper contextWrapper = RequestContextWrapper.capture();
Set<String> recordSet = new HashSet<>(); Set<String> recordSet = new HashSet<>();
...@@ -214,6 +212,7 @@ public class DataDockServiceImpl { ...@@ -214,6 +212,7 @@ public class DataDockServiceImpl {
} }
@GlobalTransactional(rollbackFor = Exception.class) @GlobalTransactional(rollbackFor = Exception.class)
@Transactional(rollbackFor = Exception.class)
public String saveEquipmentDataInTransaction(Map<String, Object> equ, String dataSource, String remark) { 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); ReginParams reginParams = JSONObject.parseObject(redisUtils.get(RedisKey.buildReginKey(RequestContext.getExeUserId(), RequestContext.getToken())).toString(), ReginParams.class);
CompanyBo company = reginParams.getCompany(); CompanyBo company = reginParams.getCompany();
...@@ -2350,35 +2349,19 @@ public class DataDockServiceImpl { ...@@ -2350,35 +2349,19 @@ public class DataDockServiceImpl {
} }
CompletableFuture<Void> useInfoFuture = CompletableFuture.runAsync( idxBizJgRegisterInfoServiceImpl.batchInsert(idxBizJgUseInfoMapper, useInfoList, "使用信息");
() -> idxBizJgRegisterInfoServiceImpl.batchInsert(idxBizJgUseInfoMapper, useInfoList, "使用信息")); idxBizJgRegisterInfoServiceImpl.batchInsert(idxBizJgDesignInfoMapper, designInfoList, "设计信息");
CompletableFuture<Void> designInfoFuture = CompletableFuture.runAsync( idxBizJgRegisterInfoServiceImpl.batchInsert(idxBizJgConstructionInfoMapper, constructionInfoList, "施工信息");
() -> idxBizJgRegisterInfoServiceImpl.batchInsert(idxBizJgDesignInfoMapper, designInfoList, "设计信息")); idxBizJgRegisterInfoServiceImpl.batchInsert(idxBizJgFactoryInfoMapper, factoryInfoList, "制造信息");
CompletableFuture<Void> constructionFuture = CompletableFuture.runAsync( idxBizJgRegisterInfoServiceImpl.batchInsert(idxBizJgRegisterInfoMapper, registerInfoList, "登记信息");
() -> idxBizJgRegisterInfoServiceImpl.batchInsert(idxBizJgConstructionInfoMapper, constructionInfoList, "施工信息")); idxBizJgRegisterInfoServiceImpl.batchInsert(idxBizJgOtherInfoMapper, otherInfoList, "其他信息");
CompletableFuture<Void> factoryFuture = CompletableFuture.runAsync( idxBizJgRegisterInfoServiceImpl.batchInsert(idxBizJgSupervisionInfoMapper, supervisionInfoList, "监管信息");
() -> idxBizJgRegisterInfoServiceImpl.batchInsert(idxBizJgFactoryInfoMapper, factoryInfoList, "制造信息")); idxBizJgRegisterInfoServiceImpl.batchInsert(idxBizJgTechParamsPipelineMapper, paramsPipelineList, "管道参数信息");
CompletableFuture<Void> registerFuture = CompletableFuture.runAsync( idxBizJgRegisterInfoServiceImpl.batchInsert(idxBizJgInspectionDetectionInfoMapper, inspectionDetectionInfoList, "检验检测信息");
() -> idxBizJgRegisterInfoServiceImpl.batchInsert(idxBizJgRegisterInfoMapper, registerInfoList, "登记信息")); if (!esEquipmentCategoryList.isEmpty()) {
CompletableFuture<Void> otherFuture = CompletableFuture.runAsync( esEquipmentCategory.saveAll(esEquipmentCategoryList);
() -> idxBizJgRegisterInfoServiceImpl.batchInsert(idxBizJgOtherInfoMapper, otherInfoList, "其他信息")); log.info("ES批量保存完成,数量:{}", esEquipmentCategoryList.size());
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();
log.info("所有批量操作完成"); log.info("所有批量操作完成");
return recordList; return recordList;
} }
......
...@@ -4808,18 +4808,14 @@ public class IdxBizJgRegisterInfoServiceImpl extends BaseService<IdxBizJgRegiste ...@@ -4808,18 +4808,14 @@ public class IdxBizJgRegisterInfoServiceImpl extends BaseService<IdxBizJgRegiste
} }
batchInsert(idxBizJgUseInfoMapper, useInfoList, "使用信息"); batchInsert(idxBizJgUseInfoMapper, useInfoList, "使用信息");
batchInsert(idxBizJgRegisterInfoMapper, registerInfoList, "注册信息"); batchInsert(idxBizJgRegisterInfoMapper, registerInfoList, "注册信息");
List<CompletableFuture<Void>> futures = new ArrayList<>(); batchInsert(idxBizJgSupervisionInfoMapper, supervisionInfoList, "监督信息");
futures.add(CompletableFuture.runAsync(() -> batchInsert(idxBizJgSupervisionInfoMapper, supervisionInfoList, "监督信息"), executor)); batchInsert(idxBizJgDesignInfoMapper, designInfoList, "设计信息");
futures.add(CompletableFuture.runAsync(() -> batchInsert(idxBizJgDesignInfoMapper, designInfoList, "设计信息"), executor)); batchInsert(idxBizJgFactoryInfoMapper, factoryInfoList, "制造信息");
futures.add(CompletableFuture.runAsync(() -> batchInsert(idxBizJgFactoryInfoMapper, factoryInfoList, "制造信息"), executor)); batchInsert(otherInfoMapper, otherInfoList, "其他信息");
futures.add(CompletableFuture.runAsync(() -> batchInsert(otherInfoMapper, otherInfoList, "其他信息"), executor)); batchInsert(idxBizJgTechParamsVesselMapper, paramsVesselList, "容器参数信息");
futures.add(CompletableFuture.runAsync(() -> batchInsert(idxBizJgTechParamsVesselMapper, paramsVesselList, "容器参数信息"), executor)); batchInsert(idxBizJgInspectionDetectionInfoMapper, inspectionDetectionInfoList, "检验检测信息");
futures.add(CompletableFuture.runAsync(() -> batchInsert(idxBizJgInspectionDetectionInfoMapper, inspectionDetectionInfoList, "检验检测信息"), executor)); batchInsert(certificateChangeRecordEqMapper, jgCertificateChangeRecordEqList, "登记证关系信息");
futures.add(CompletableFuture.runAsync(() -> batchInsert(certificateChangeRecordEqMapper, jgCertificateChangeRecordEqList, "登记证关系信息"), executor)); esEquipmentCategory.saveAll(esEquipmentCategoryList);
futures.add(CompletableFuture.runAsync(() -> esEquipmentCategory.saveAll(esEquipmentCategoryList), executor));
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join();
// 使用事务同步回调确保事件在事务提交后发送 // 使用事务同步回调确保事件在事务提交后发送
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() { TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() {
@Override @Override
...@@ -4836,8 +4832,6 @@ public class IdxBizJgRegisterInfoServiceImpl extends BaseService<IdxBizJgRegiste ...@@ -4836,8 +4832,6 @@ public class IdxBizJgRegisterInfoServiceImpl extends BaseService<IdxBizJgRegiste
}); });
return String.format("导入完成,成功导入: %d 条数据!", useInfoList.size()); 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) { 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