create package .result.*

This commit is contained in:
Anatoly Karlov 2024-10-31 19:24:32 +07:00
parent e930555f06
commit f971b61473
7 changed files with 50 additions and 27 deletions

View File

@ -2,7 +2,7 @@ package dev.vality.disputes.callback;
import dev.vality.disputes.dao.DisputeDao;
import dev.vality.disputes.dao.ProviderDisputeDao;
import dev.vality.disputes.schedule.handler.DisputeStatusResultHandler;
import dev.vality.disputes.schedule.result.DisputeStatusResultHandler;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.thrift.TException;

View File

@ -10,6 +10,7 @@ import dev.vality.disputes.domain.tables.pojos.Dispute;
import dev.vality.disputes.schedule.converter.InvoicePaymentCapturedAdjustmentParamsConverter;
import dev.vality.disputes.schedule.converter.InvoicePaymentCashFlowAdjustmentParamsConverter;
import dev.vality.disputes.schedule.converter.InvoicePaymentFailedAdjustmentParamsConverter;
import dev.vality.disputes.schedule.result.ErrorResultHandler;
import dev.vality.disputes.schedule.service.AdjustmentExtractor;
import dev.vality.disputes.service.external.InvoicingService;
import lombok.RequiredArgsConstructor;
@ -34,6 +35,7 @@ public class AdjustmentsService {
private final InvoicePaymentCashFlowAdjustmentParamsConverter invoicePaymentCashFlowAdjustmentParamsConverter;
private final InvoicePaymentFailedAdjustmentParamsConverter invoicePaymentFailedAdjustmentParamsConverter;
private final AdjustmentExtractor adjustmentExtractor;
private final ErrorResultHandler errorResultHandler;
@Transactional(propagation = Propagation.REQUIRED)
public List<Dispute> getDisputesForHgCall(int batchSize) {
@ -62,16 +64,13 @@ public class AdjustmentsService {
log.debug("GetDisputeForUpdateSkipLocked has been found {}", dispute);
var invoicePayment = getInvoicePayment(dispute);
if (invoicePayment == null || !invoicePayment.isSetRoute()) {
updateFailed(dispute, ErrorReason.PAYMENT_NOT_FOUND);
errorResultHandler.updateFailed(dispute, ErrorReason.PAYMENT_NOT_FOUND);
return;
}
if (!adjustmentExtractor.isCashFlowAdjustmentByDisputeExist(invoicePayment, dispute)
&& !Objects.equals(dispute.getAmount(), dispute.getChangedAmount())) {
var params = invoicePaymentCashFlowAdjustmentParamsConverter.convert(dispute);
var paymentAdjustment = createAdjustment(dispute, params);
if (paymentAdjustment == null) {
var errorReason = ErrorReason.INVOICE_NOT_FOUND;
updateFailed(dispute, errorReason);
if (!createAdjustment(dispute, params)) {
return;
}
} else {
@ -80,16 +79,12 @@ public class AdjustmentsService {
if (!adjustmentExtractor.isCapturedAdjustmentByDisputeExist(invoicePayment, dispute)) {
if (invoicePayment.getPayment().getStatus().isSetCaptured()) {
var params = invoicePaymentFailedAdjustmentParamsConverter.convert(dispute);
var paymentAdjustment = createAdjustment(dispute, params);
if (paymentAdjustment == null) {
updateFailed(dispute, ErrorReason.INVOICE_NOT_FOUND);
if (!createAdjustment(dispute, params)) {
return;
}
}
var params = invoicePaymentCapturedAdjustmentParamsConverter.convert(dispute);
var paymentAdjustment = createAdjustment(dispute, params);
if (paymentAdjustment == null) {
updateFailed(dispute, ErrorReason.INVOICE_NOT_FOUND);
if (!createAdjustment(dispute, params)) {
return;
}
} else {
@ -100,14 +95,18 @@ public class AdjustmentsService {
log.debug("Dispute status has been set to succeeded {}", dispute.getId());
}
@Transactional(propagation = Propagation.REQUIRED)
void updateFailed(Dispute dispute, String errorReason) {
log.error("Trying to set failed Dispute status with {} error reason {}", errorReason, dispute.getId());
disputeDao.update(dispute.getId(), DisputeStatus.failed, errorReason);
log.debug("Dispute status has been set to failed {}", dispute.getId());
boolean createAdjustment(Dispute dispute, InvoicePaymentAdjustmentParams params) {
var paymentAdjustment = createPaymentAdjustment(dispute, params);
if (paymentAdjustment == null) {
errorResultHandler.updateFailed(dispute, ErrorReason.INVOICE_NOT_FOUND);
return false;
}
return true;
}
private InvoicePaymentAdjustment createAdjustment(Dispute dispute, InvoicePaymentAdjustmentParams params) {
private InvoicePaymentAdjustment createPaymentAdjustment(Dispute dispute, InvoicePaymentAdjustmentParams params) {
return invoicingService.createPaymentAdjustment(dispute.getInvoiceId(), dispute.getPaymentId(), params);
}

View File

@ -9,8 +9,9 @@ import dev.vality.disputes.provider.DisputeCreatedResult;
import dev.vality.disputes.schedule.catcher.WRuntimeExceptionCatcher;
import dev.vality.disputes.schedule.client.DefaultRemoteClient;
import dev.vality.disputes.schedule.client.RemoteClient;
import dev.vality.disputes.schedule.handler.DisputeCreateResultHandler;
import dev.vality.disputes.schedule.model.ProviderData;
import dev.vality.disputes.schedule.result.DisputeCreateResultHandler;
import dev.vality.disputes.schedule.result.ErrorResultHandler;
import dev.vality.disputes.schedule.service.AttachmentsService;
import dev.vality.disputes.schedule.service.ProviderDataService;
import dev.vality.disputes.service.external.InvoicingService;
@ -40,6 +41,7 @@ public class CreatedDisputesService {
private final ProviderDataService providerDataService;
private final DefaultRemoteClient defaultRemoteClient;
private final DisputeCreateResultHandler disputeCreateResultHandler;
private final ErrorResultHandler errorResultHandler;
private final WRuntimeExceptionCatcher wRuntimeExceptionCatcher;
@Transactional(propagation = Propagation.REQUIRED)
@ -61,16 +63,12 @@ public class CreatedDisputesService {
log.debug("GetDisputeForUpdateSkipLocked has been found {}", dispute);
var invoicePayment = getInvoicePayment(dispute);
if (invoicePayment == null || !invoicePayment.isSetRoute()) {
log.error("Trying to set failed Dispute status with PAYMENT_NOT_FOUND error reason {}", dispute.getId());
disputeDao.update(dispute.getId(), DisputeStatus.failed, ErrorReason.PAYMENT_NOT_FOUND);
log.debug("Dispute status has been set to failed {}", dispute.getId());
errorResultHandler.updateFailed(dispute, ErrorReason.PAYMENT_NOT_FOUND);
return;
}
var attachments = attachmentsService.getAttachments(dispute);
if (attachments == null || attachments.isEmpty()) {
log.error("Trying to set failed Dispute status with NO_ATTACHMENTS error reason {}", dispute.getId());
disputeDao.update(dispute.getId(), DisputeStatus.failed, ErrorReason.NO_ATTACHMENTS);
log.debug("Dispute status has been set to failed {}", dispute.getId());
errorResultHandler.updateFailed(dispute, ErrorReason.NO_ATTACHMENTS);
return;
}
var providerData = providerDataService.getProviderData(dispute.getProviderId(), dispute.getTerminalId());

View File

@ -9,7 +9,7 @@ import dev.vality.disputes.polling.PollingInfoService;
import dev.vality.disputes.provider.DisputeStatusResult;
import dev.vality.disputes.schedule.catcher.WRuntimeExceptionCatcher;
import dev.vality.disputes.schedule.client.RemoteClient;
import dev.vality.disputes.schedule.handler.DisputeStatusResultHandler;
import dev.vality.disputes.schedule.result.DisputeStatusResultHandler;
import dev.vality.disputes.schedule.service.ProviderDataService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

View File

@ -1,4 +1,4 @@
package dev.vality.disputes.schedule.handler;
package dev.vality.disputes.schedule.result;
import dev.vality.disputes.admin.callback.CallbackNotifier;
import dev.vality.disputes.admin.management.MdcTopicProducer;

View File

@ -1,4 +1,4 @@
package dev.vality.disputes.schedule.handler;
package dev.vality.disputes.schedule.result;
import dev.vality.disputes.admin.callback.CallbackNotifier;
import dev.vality.disputes.admin.management.MdcTopicProducer;

View File

@ -0,0 +1,26 @@
package dev.vality.disputes.schedule.result;
import dev.vality.disputes.dao.DisputeDao;
import dev.vality.disputes.domain.enums.DisputeStatus;
import dev.vality.disputes.domain.tables.pojos.Dispute;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
@Slf4j
@Service
@RequiredArgsConstructor
@SuppressWarnings({"ParameterName", "LineLength", "MissingSwitchDefault"})
public class ErrorResultHandler {
private final DisputeDao disputeDao;
@Transactional(propagation = Propagation.REQUIRED)
public void updateFailed(Dispute dispute, String errorReason) {
log.error("Trying to set failed Dispute status with {} error reason {}", errorReason, dispute.getId());
disputeDao.update(dispute.getId(), DisputeStatus.failed, errorReason);
log.debug("Dispute status has been set to failed {}", dispute.getId());
}
}