Commit 2c2fdba5 authored by suhuiguang's avatar suhuiguang

fix(设备创建) : 事务回滚

1.回滚时,删除设备
parent c51777bc
......@@ -27,6 +27,7 @@ public class EquipRequestParamsDto {
private String dataSource;
private String orgBranchCode;
private String orgBranchName;
private String orgCompanyCode;
private String useOrgCode;
private String vehicleApanage;
private String receiveCompanyCode;
......
......@@ -39,7 +39,7 @@ public class DataDockController extends BaseController {
@PostMapping(value = "/xi-an/saveEquipmentData")
@ApiOperation(httpMethod = "POST", value = "西安数据对接-设备批量导入", notes = "西安数据对接-导入多个设备的数据文件")
public ResponseModel<?> saveEquipmentData(@RequestBody List<Map<String, Object>> equLists) {
return ResponseHelper.buildResponse(dataDockService.xiAnSaveEquipmentData(equLists));
return ResponseHelper.buildResponse(dataDockService.xiAnSaveEquipmentData(equLists, getSelectedOrgInfo()));
}
@TycloudOperation(ApiLevel = UserType.AGENCY)
......@@ -57,7 +57,7 @@ public class DataDockController extends BaseController {
if (!("application/vnd.ms-excel".equals(contentType) || "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet".equals(contentType)) || !("xls".equalsIgnoreCase(fileExtension) || "xlsx".equalsIgnoreCase(fileExtension))) {
return ResponseHelper.buildResponse("文件类型必须是 Excel 文件");
}
return ResponseHelper.buildResponse(dataDockService.dataCheckAndImportEquipmentData(remark, file));
return ResponseHelper.buildResponse(dataDockService.dataCheckAndImportEquipmentData(remark, file, getSelectedOrgInfo()));
}
/**
......@@ -137,7 +137,7 @@ public class DataDockController extends BaseController {
@ApiOperation(httpMethod = "POST", value = "台套类设备导入字段保存", notes = "台套类设备导入字段保存")
@RestEventTrigger(value = "operateLogRestEventHandler")
public ResponseModel<?> saveEquipImportData(@RequestBody Map<String, Object> paramMap) {
return ResponseHelper.buildResponse(dataDockService.saveEquipImportData(paramMap));
return ResponseHelper.buildResponse(dataDockService.saveEquipImportData(paramMap, getSelectedOrgInfo()));
}
/**
......
package com.yeejoin.amos.boot.module.jg.biz.hook;
import io.seata.tm.api.transaction.TransactionHook;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class EsSyncTransactionHook implements TransactionHook {
private final String xid; // final保证构造后不变
public EsSyncTransactionHook(String xid) {
this.xid = xid;
}
@Override
public void beforeBegin() {
log.info("beforeBegin:{}", xid);
}
@Override
public void afterBegin() {
log.info("afterBegin:{}", xid);
}
@Override
public void beforeCommit() {
log.info("beforeCommit:{}", xid);
}
@Override
public void afterCommit() {
log.info("afterCommit:{}", xid);
}
@Override
public void beforeRollback() {
log.info("beforeRollback:{}", xid);
}
@Override
public void afterRollback() {
log.info("afterRollback:{}", xid);
}
@Override
public void afterCompletion() {
log.info("afterCompletion:{}", xid);
}
}
......@@ -19,7 +19,6 @@ public class ElevatorDataTransactionService {
}
@Transactional(rollbackFor = Exception.class)
@GlobalTransactional(rollbackFor = Exception.class)
public Object saveSingleElevatorData(Map<String, Object> equ) {
return dataDockService.saveElevatorDataInTransaction(equ, "jg_his_xa", null);
}
......
......@@ -56,6 +56,7 @@ import com.yeejoin.amos.boot.module.ymt.api.dto.TzsUserInfoDto;
import com.yeejoin.amos.boot.module.ymt.api.entity.*;
import com.yeejoin.amos.boot.module.ymt.api.enums.*;
import com.yeejoin.amos.boot.module.ymt.api.mapper.*;
import com.yeejoin.amos.component.feign.config.InnerInvokException;
import com.yeejoin.amos.component.feign.model.FeignClientResult;
import com.yeejoin.amos.component.feign.utils.FeignUtil;
import com.yeejoin.amos.feign.systemctl.Systemctl;
......@@ -4454,6 +4455,7 @@ public class IdxBizJgRegisterInfoServiceImpl extends BaseService<IdxBizJgRegiste
if (paramMap == null) {
throw new IllegalArgumentException("参数Map不能为空");
}
try {
LinkedHashMap equipmentInfoForm = (LinkedHashMap) checkAndCast(paramMap.get(EQUIP_INFO_FORM_ID));
LinkedHashMap attachmentUpload = (LinkedHashMap) checkAndCast(paramMap.get(ATTACHMENT_UPLOAD));
EquipmentInfoDto equipInfoDto = this.createEquipmentInfoDto(equipmentInfoForm, jgVehicleInformationMapper);
......@@ -4603,16 +4605,16 @@ public class IdxBizJgRegisterInfoServiceImpl extends BaseService<IdxBizJgRegiste
.map(s -> DateUtil.parse(s, "yyyy-MM-dd"))
.ifPresent(inspectionDetectionInfo::setNextInspectDate);
// 根据条件确定增加的年数(杨生元说监管让去掉,企业自己输入)
// Optional.ofNullable(data.getInspectDate())
// .filter(s -> !s.trim().isEmpty())
// .map(dateStr -> LocalDate.parse(dateStr, DateTimeFormatter.ofPattern("yyyy-MM-dd")))
// .ifPresent(inspectDate -> {
// inspectionDetectionInfo.setInspectDate(Date.from(inspectDate.atStartOfDay(ZoneId.systemDefault()).toInstant()));
// // 计算下次检测日期(加 3 年或 4 年)
// int plusYears = SPECIAL_CYLINDER.getCode().equals(equipInfoDto.getEquDefineCode()) ? 3 : 4;
// LocalDate nextInspectDate = inspectDate.plusYears(plusYears);
// inspectionDetectionInfo.setNextInspectDate(Date.from(nextInspectDate.atStartOfDay(ZoneId.systemDefault()).toInstant()));
// });
// Optional.ofNullable(data.getInspectDate())
// .filter(s -> !s.trim().isEmpty())
// .map(dateStr -> LocalDate.parse(dateStr, DateTimeFormatter.ofPattern("yyyy-MM-dd")))
// .ifPresent(inspectDate -> {
// inspectionDetectionInfo.setInspectDate(Date.from(inspectDate.atStartOfDay(ZoneId.systemDefault()).toInstant()));
// // 计算下次检测日期(加 3 年或 4 年)
// int plusYears = SPECIAL_CYLINDER.getCode().equals(equipInfoDto.getEquDefineCode()) ? 3 : 4;
// LocalDate nextInspectDate = inspectDate.plusYears(plusYears);
// inspectionDetectionInfo.setNextInspectDate(Date.from(nextInspectDate.atStartOfDay(ZoneId.systemDefault()).toInstant()));
// });
inspectionDetectionInfoList.add(inspectionDetectionInfo);
// 其他信息
......@@ -4824,20 +4826,14 @@ public class IdxBizJgRegisterInfoServiceImpl extends BaseService<IdxBizJgRegiste
batchInsert(idxBizJgInspectionDetectionInfoMapper, inspectionDetectionInfoList, "检验检测信息");
batchInsert(certificateChangeRecordEqMapper, jgCertificateChangeRecordEqList, "登记证关系信息");
esEquipmentCategory.saveAll(esEquipmentCategoryList);
// 使用事务同步回调确保事件在事务提交后发送
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() {
@Override
public void afterCommit() {
eventPublisher.publish(
new EquipCreateOrEditEvent(
this,
BusinessTypeEnum.JG_NEW_EQUIP.name(),
recordSet,
EquipCreateOrEditEvent.EquipType.equip
)
);
// 事务提交成功后,发送消息
eventPublisher.publish(new EquipCreateOrEditEvent(this, BusinessTypeEnum.JG_NEW_EQUIP.name(), recordSet, EquipCreateOrEditEvent.EquipType.equip));
} catch (Exception e) {
if(!esEquipmentCategoryList.isEmpty()){
esEquipmentCategory.deleteAll(esEquipmentCategoryList);
}
throw e;
}
});
return String.format("导入完成,成功导入: %d 条数据!", useInfoList.size());
}
......
......@@ -142,8 +142,6 @@
ibjui."REC_DATE",
ibjui."USE_UNIT_NAME",
ibjui."USE_UNIT_CREDIT_CODE",
ibjui."USC_UNIT_NAME",
ibjui."USC_UNIT_CREDIT_CODE",
ibjri."EQU_LIST" AS "EQU_LIST_CODE",
ibjri."EQU_DEFINE" AS "EQU_DEFINE_CODE",
ibjri."PRODUCT_NAME",
......@@ -185,7 +183,13 @@
ibjoi."INFORMATION_SITUATION",
di."DESIGN_UNIT_CREDIT_CODE",
di."DESIGN_UNIT_NAME",
di."DESIGN_DATE"
di."DESIGN_DATE",
construction_info."USC_UNIT_CREDIT_CODE",
construction_info."USC_UNIT_NAME",
construction_info."CONSTRUCTION_TYPE",
construction_info."USC_DATE",
inspection_info."INSPECT_REPORT",
inspection_info."NEXT_INSPECT_DATE"
FROM
idx_biz_jg_use_info ibjui
LEFT JOIN (
......
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