creation DF-03/12 by PaymentInstruction

This commit is contained in:
etreshenkov 2023-06-01 16:37:59 +03:00
parent 0987180bd3
commit 36e8d5f096

View file

@ -26,6 +26,8 @@ import ru.spcex.platform.enumeration.*;
import ru.spcex.platform.imdg.api.Imdg; import ru.spcex.platform.imdg.api.Imdg;
import ru.spcex.platform.imdg.api.ImdgId; import ru.spcex.platform.imdg.api.ImdgId;
import ru.spcex.platform.imdg.api.ImdgProvider; import ru.spcex.platform.imdg.api.ImdgProvider;
import ru.spcex.platform.imdg.api.predicate.ImdgPredicate;
import ru.spcex.platform.imdg.api.predicate.ImdgPredicateBuilder;
import ru.spcex.platform.imdg.api.predicate.specific.RegistryCodeSqlBuilder; import ru.spcex.platform.imdg.api.predicate.specific.RegistryCodeSqlBuilder;
import ru.spcex.platform.utils.enumeration.IEnumKey; import ru.spcex.platform.utils.enumeration.IEnumKey;
import ru.spcex.platform.utils.enumeration.IMessageResolver; import ru.spcex.platform.utils.enumeration.IMessageResolver;
@ -33,6 +35,7 @@ import ru.spcex.platform.utils.enumeration.SimpleMessageResolver;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.Instant; import java.time.Instant;
import java.time.format.DateTimeFormatter;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -271,22 +274,26 @@ public class FormingPaymentInstruction implements ISessionStage {
} }
private void sendSdfs(List<PaymentInstruction> formedPaymentInstructions) { private void sendSdfs(List<PaymentInstruction> formedPaymentInstructions) {
Long sdf03GroupId = null; List<SDf03> sDf03Created = new ArrayList<>();
Long sdf12GroupId = null; List<SDf12> sDf12Created = new ArrayList<>();
for (PaymentInstruction paymentInstruction : formedPaymentInstructions) { for (PaymentInstruction paymentInstruction : formedPaymentInstructions) {
Security security = securityImdg.getSingleObjectByID(paymentInstruction.getCreditLeg_securityId()); Security security = securityImdg.getSingleObjectByID(paymentInstruction.getCreditLeg_securityId());
Account account = accountImdg.getSingleObjectByID(paymentInstruction.getCreditLeg_accountId()); Account account = accountImdg.getSingleObjectByID(paymentInstruction.getCreditLeg_accountId());
if (InstrumentType.CRNC.equalsByKey(security.getInstrumentType()) && if (InstrumentType.CRNC.equalsByKey(security.getInstrumentType()) &&
List.of(AccountType.Corr, AccountType.Clrn).contains(IEnumKey.getEnumByKey(AccountType.class, account.getAccountType()))) { List.of(AccountType.Corr, AccountType.Clrn).contains(IEnumKey.getEnumByKey(AccountType.class, account.getAccountType()))) {
sdf03GroupId = sdf03GroupId != null ? sdf12GroupId : imdgProvider.getImdgIdGenerator().nextId(); sDf03Created.add(newSDf03(paymentInstruction));
newSDf03(paymentInstruction, sdf03GroupId);
} else if (!InstrumentType.CRNC.equalsByKey(security.getInstrumentType()) && } else if (!InstrumentType.CRNC.equalsByKey(security.getInstrumentType()) &&
AccountType.Depo.equalsByKey(account.getAccountType())) { AccountType.Depo.equalsByKey(account.getAccountType())) {
sdf12GroupId = sdf12GroupId != null ? sdf12GroupId : imdgProvider.getImdgIdGenerator().nextId(); sDf12Created.add(newSDf12(paymentInstruction));
newSDf12(paymentInstruction, sdf12GroupId);
} }
} }
Long sdf03GroupId = !sDf03Created.isEmpty() ? imdgProvider.getImdgIdGenerator().nextId() : null;
for (SDf03 sDf03 : sDf03Created) {
sDf03.setGenerationId(sdf03GroupId);
sDf03Imdg.insert(sDf03);
}
if (sdf03GroupId != null) { if (sdf03GroupId != null) {
ExportToFileRequest exportToFileRequest = new ExportToFileRequest(); ExportToFileRequest exportToFileRequest = new ExportToFileRequest();
exportToFileRequest.setNameOfTable("DF-03"); exportToFileRequest.setNameOfTable("DF-03");
@ -294,6 +301,25 @@ public class FormingPaymentInstruction implements ISessionStage {
kafkaSender.sendRequestToQueue(Consts.EXPORT_PROCESS, exportToFileRequest); kafkaSender.sendRequestToQueue(Consts.EXPORT_PROCESS, exportToFileRequest);
} }
Long sdf12GroupId = null;
Long maxTxNumber = 1L;
if (!sDf12Created.isEmpty()) {
sdf12GroupId = !sDf12Created.isEmpty() ? imdgProvider.getImdgIdGenerator().nextId() : null;
ImdgPredicateBuilder predicateBuilder = sDf12Imdg.predicateBuilder();
ImdgPredicate notEmptyTransactionNum = predicateBuilder.not(predicateBuilder.equals("transaction_number", ""));
Long maxId = sDf12Imdg.aggregateLongMax("id", notEmptyTransactionNum);
if (maxId != null) {
SDf12 sDf12 = sDf12Imdg.getSingleObjectByID(maxId);
maxTxNumber = Long.parseLong(sDf12.getTransactionNumber()) + 1;
}
}
for (SDf12 sDf12 : sDf12Created) {
sDf12.setGenerationId(sdf03GroupId);
sDf12.setTransactionNumber(maxTxNumber.toString());
sDf12.setTransactionQuantity(String.valueOf(sDf12Created.size()));
sDf12Imdg.insert(sDf12);
}
if (sdf12GroupId != null) { if (sdf12GroupId != null) {
ExportToFileRequest exportToFileRequest = new ExportToFileRequest(); ExportToFileRequest exportToFileRequest = new ExportToFileRequest();
exportToFileRequest.setNameOfTable("DF-12"); exportToFileRequest.setNameOfTable("DF-12");
@ -309,7 +335,7 @@ public class FormingPaymentInstruction implements ISessionStage {
return paymentInstructionBuilder.build(); return paymentInstructionBuilder.build();
} }
private void newSDf03(PaymentInstruction paymentInstruction, Long sdf03GroupId) { private SDf03 newSDf03(PaymentInstruction paymentInstruction) {
log.debug("creating sdf03"); log.debug("creating sdf03");
SDf03 sDf03 = new SDf03(); SDf03 sDf03 = new SDf03();
sDf03.setId(idGenerator.nextId()); sDf03.setId(idGenerator.nextId());
@ -318,7 +344,7 @@ public class FormingPaymentInstruction implements ISessionStage {
String strId = paymentInstruction.getId().toString(); String strId = paymentInstruction.getId().toString();
String strIdCut = strId.length() > 16 ? strId.substring(strId.length() - 16) : strId; String strIdCut = strId.length() > 16 ? strId.substring(strId.length() - 16) : strId;
sDf03.setDocnm_ref(strIdCut); sDf03.setDocnm_ref(strIdCut);
sDf03.setC_acc_deb(paymentInstruction.getDebitLeg_account()); sDf03.setC_acc_deb(paymentInstruction.getCreditLeg_account());
String senderSbankName = ""; String senderSbankName = "";
if (paymentInstruction.getSenderId().equals(1L)) { if (paymentInstruction.getSenderId().equals(1L)) {
@ -335,7 +361,7 @@ public class FormingPaymentInstruction implements ISessionStage {
sDf03.setSbanknam4(senderSbankName); sDf03.setSbanknam4(senderSbankName);
sDf03.setSbanknam5(senderSbankName); sDf03.setSbanknam5(senderSbankName);
sDf03.setC_acc_cred(paymentInstruction.getCreditLeg_account()); sDf03.setC_acc_cred(paymentInstruction.getDebitLeg_account());
String addresseeSbankName = ""; String addresseeSbankName = "";
if (paymentInstruction.getAddresseeId().equals(1L)) { if (paymentInstruction.getAddresseeId().equals(1L)) {
@ -352,29 +378,35 @@ public class FormingPaymentInstruction implements ISessionStage {
sDf03.setRbanknam4(addresseeSbankName); sDf03.setRbanknam4(addresseeSbankName);
sDf03.setRbanknam5(addresseeSbankName); sDf03.setRbanknam5(addresseeSbankName);
// sDf03.setPay_date();// sDf03.setPay_date(payDateFormatter.format(paymentInstruction.getPaymentDate()));
sDf03.setPay_val("RUR"); sDf03.setPay_val("RUR");
sDf03.setSum_deb(paymentInstruction.getDebitLeg_amount() != null ? paymentInstruction.getDebitLeg_amount().toString() : ""); sDf03.setSum_deb(paymentInstruction.getDebitLeg_amount() != null ? paymentInstruction.getDebitLeg_amount().toString() : "");
sDf03.setSpecif_1(paymentInstruction.getPaymentPurpose()); sDf03.setSpecif_1(paymentInstruction.getPaymentPurpose());
sDf03.setGenerationTime(Instant.now()); sDf03.setGenerationTime(Instant.now());
sDf03.setGenerationId(sdf03GroupId);
sDf03.setPaymentInstructionId(paymentInstruction.getId()); sDf03.setPaymentInstructionId(paymentInstruction.getId());
sDf03Imdg.insert(sDf03);
log.debug("successfully processed, new id {}", sDf03.getId()); log.debug("successfully processed, new id {}", sDf03.getId());
return sDf03;
} }
private void newSDf12(PaymentInstruction paymentInstruction, Long sdf12GroupId) { private SDf12 newSDf12(PaymentInstruction paymentInstruction) {
log.debug("creating sdf12"); log.debug("creating sdf12");
SDf12 sDf12 = new SDf12(); SDf12 sDf12 = new SDf12();
sDf12.setId(idGenerator.nextId()); sDf12.setId(idGenerator.nextId());
sDf12.setOutDocument(sDf12.getId().toString()); sDf12.setOutDocument(sDf12.getId().toString());
// sDf12.setQuantity(); sDf12.setDirection("DELFREE");
sDf12.setQuantity(paymentInstruction.getCreditLeg_amount().toString());
sDf12.setSecurityCode(paymentInstruction.getCreditLeg_securityId().toString());
sDf12.setDepoCodeSender(paymentInstruction.getCreditLeg_account());
sDf12.setDepoCodeAdressee(paymentInstruction.getDebitLeg_account());
// sDf12.setTransactionNumber();
sDf12.setGenerationTime(Instant.now()); sDf12.setGenerationTime(Instant.now());
sDf12.setGenerationId(sdf12GroupId); return sDf12;
sDf12Imdg.insert(sDf12);
} }
private BigDecimal safeBD(BigDecimal value) { private BigDecimal safeBD(BigDecimal value) {
return value != null ? value : BigDecimal.ZERO; return value != null ? value : BigDecimal.ZERO;
} }
DateTimeFormatter payDateFormatter = DateTimeFormatter.ofPattern("dd.MM.yy");
} }