使用嵌套事务解决因事务回滚无法保存操作日志数据问题
外部事务
//保存不可回收记录
CarriageContractRecycleAmountHandler proxy = (CarriageContractRecycleAmountHandler) AopContext.currentProxy();
logCommand.setMsg("回收量大于承运合同未执行量,不可回收");
proxy.createContractNotRecycleRecord(contract, currentRecycleAmount, deliverAmountDTO, logCommand);
throw new BizException(CommonCode.FAIL.getCode(), "回收量大于承运合同未执行量,不可回收");
内部事务
/** 保存不可回收记录 **/
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void createContractNotRecycleRecord(CarriageContractInfo contract, BigDecimal currentRecycleAmount, DeliverAmountDTO deliverAmountDTO, CarriageContractRecycleLogCommand logCommand) {
carriagePlanRecycleRecordDomainService.createRecycleRecord(CarriagePlanRecycleRecord.builder()
.bizId(contract.getId())
.bizType(CarriagePlanRecycleEnum.RecycleBizType.CARRIAGE_CONTRACT.getCode())
.carriageContractNo(contract.getCarriageContractNo())
.carriagePlanNo(null)
.sysInvoiceNo(null)
.currentRecycleAmount(currentRecycleAmount)
.recycleAmount(currentRecycleAmount)
.recycleStatus(CarriagePlanRecycleEnum.RecycleStatus.NOT_RECYCLE.getCode())
.bizData(JsonUtil.toJson(logCommand))
.createUserId(OperateLogEnum.SYS_USER_ID)
.createTime(LocalDateTime.now())
.createUserName(OperateLogEnum.SYS_USER_NAME)
.build());
}