Commit cbdbde69 authored by 刘林's avatar 刘林

fix:(jg):批量导入接口修改

parent 1345952f
...@@ -155,6 +155,7 @@ public class DataDockServiceImpl { ...@@ -155,6 +155,7 @@ public class DataDockServiceImpl {
private final JgVehicleInformationMapper jgVehicleInformationMapper; private final JgVehicleInformationMapper jgVehicleInformationMapper;
private final IdxBizJgRegisterInfoMapper idxBizJgRegisterInfoMapper; private final IdxBizJgRegisterInfoMapper idxBizJgRegisterInfoMapper;
private final ExcelImportErrorLogDao excelImportErrorLogDao; private final ExcelImportErrorLogDao excelImportErrorLogDao;
private final SuperviseInfoMapper superviseInfoMapper;
// 设备分类表单id // 设备分类表单id
public static final String EQUIP_CLASS_FORM_ID = "equipClass"; public static final String EQUIP_CLASS_FORM_ID = "equipClass";
// 设备基本信息表单id // 设备基本信息表单id
...@@ -192,8 +193,6 @@ public class DataDockServiceImpl { ...@@ -192,8 +193,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,18 +213,15 @@ public class DataDockServiceImpl { ...@@ -214,18 +213,15 @@ 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();
String record = UUID.randomUUID().toString(); String record = UUID.randomUUID().toString();
try { try {
// transactionTemplate.execute(status -> { String equList = Objects.toString(equ.get("equList"), null);
String equList = String.valueOf(equ.get("equList")); String equCategory = Objects.toString(equ.get("equCategory"), null);
String equCategory = String.valueOf(equ.get("equCategory")); String isCompleteXa = Objects.toString(equ.get("isCompleteXa"), null);
String isCompleteXa = String.valueOf(equ.get("isCompleteXa"));
// 压力管道保存 工程装置表信息 必须在saveUseInfo之前进行,需要提前生成工程装置id
//saveProjectContraption(equ, equList, company, dataSource);
// 保存到设备表
saveUseInfo(equ, record, dataSource, remark, company); saveUseInfo(equ, record, dataSource, remark, company);
saveDesignInfo(equ, record); saveDesignInfo(equ, record);
saveFactoryInfo(equ, record); saveFactoryInfo(equ, record);
...@@ -233,24 +229,57 @@ public class DataDockServiceImpl { ...@@ -233,24 +229,57 @@ public class DataDockServiceImpl {
saveSupervisionInfo(equ, record); saveSupervisionInfo(equ, record);
saveOtherInfo(equ, record, equList); saveOtherInfo(equ, record, equList);
saveInspectInfo(equ, record); saveInspectInfo(equ, record);
if ("安装改造维修单位".equals(company.getCompanyType())){
if ("安装改造维修单位".equals(company.getCompanyType())) {
saveConstructionInfo(equ, record, company); saveConstructionInfo(equ, record, company);
} }
// 保存技术参数
saveTechParams(equ, record, equList); saveTechParams(equ, record, equList);
// 保存到ES
saveEquInfoToEs(record, isCompleteXa); saveEquInfoToEs(record, isCompleteXa);
return record; return record;
// });
} catch (Exception e) { } catch (Exception e) {
esEquipmentCategory.deleteById(record); handleSaveException(e, equ, dataSource, record);
e.printStackTrace();
log.error("{}数据:保存时出现异常,对应数据:{}", dataSource, toJSONString(equ));
log.error("异常信息:{}", e.getMessage());
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
private void handleSaveException(Exception e, Map<String, Object> equ, String dataSource, String record) {
try {
esEquipmentCategory.deleteById(record);
} catch (Exception ex) {
log.warn("ES 删除失败,record={}", record, ex);
}
try {
superviseInfoMapper.deleteDataAll(Collections.singletonList(record));
} catch (Exception ex) {
log.warn("清理监督信息失败,record={}", record, ex);
}
String traceInfo = Arrays.stream(e.getStackTrace())
.filter(x -> x.getClassName().startsWith("com.yeejoin"))
.map(x -> x.getClassName() + "." + x.getMethodName() + ":" + x.getLineNumber())
.collect(Collectors.toList())
.toString();
try {
ExcelImportErrorLogDto errorLogDto =
JSON.parseObject(toJSONString(equ), ExcelImportErrorLogDto.class);
errorLogDto.setErrorInfo(e.getMessage());
errorLogDto.setTraceInfo(traceInfo);
errorLogDto.setCreateTime(new Date());
excelImportErrorLogDao.save(errorLogDto);
} catch (Exception ex) {
log.warn("保存 Excel 错误日志失败", ex);
}
log.error("{} 数据保存失败,record={}", dataSource, record, e);
Map<String, String> errorResult = new HashMap<>();
errorResult.put("id", record);
errorResult.put("type", "error");
errorResult.put("msg",Optional.ofNullable(e.getMessage()).orElse("Unknown error: " + e.getClass().getName()));
errorResult.put("traceInfo", traceInfo);
throw new LocalBadRequest(toJSONString(errorResult));
}
/** /**
* 保存施工信息表 * 保存施工信息表
* *
...@@ -2350,35 +2379,19 @@ public class DataDockServiceImpl { ...@@ -2350,35 +2379,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;
} }
......
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