From 87349837f3f666550392a7afb8946f8e0499204a Mon Sep 17 00:00:00 2001 From: etreschenkov Date: Mon, 10 Jul 2023 13:31:43 +0300 Subject: [PATCH] http://jira.mfd.msk:8088/browse/CLS-411 // http://jira.mfd.msk:8088/browse/CLS-410 --- .../stage/SecondaryAuctionT0Session.java | 14 ++++--- ...ormingPaymentInstructionDealsFinalMkr.java | 15 +++++-- .../FormingPaymentInstructionSecondaryT0.java | 39 +++++++++++++++++-- ...mingPaymentInstructionDealsMkrPayload.java | 19 +++++++++ 4 files changed, 74 insertions(+), 13 deletions(-) diff --git a/clearing-parent/clearing-service/src/main/java/ru/spcex/clearing/session/stage/SecondaryAuctionT0Session.java b/clearing-parent/clearing-service/src/main/java/ru/spcex/clearing/session/stage/SecondaryAuctionT0Session.java index bab6c30ca..4bd87a84f 100644 --- a/clearing-parent/clearing-service/src/main/java/ru/spcex/clearing/session/stage/SecondaryAuctionT0Session.java +++ b/clearing-parent/clearing-service/src/main/java/ru/spcex/clearing/session/stage/SecondaryAuctionT0Session.java @@ -23,6 +23,7 @@ import ru.spcex.platform.imdg.api.predicate.ImdgPredicateBuilder; import ru.spcex.platform.utils.enumeration.IMessageResolver; import java.time.LocalDate; +import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.function.Supplier; @@ -39,7 +40,7 @@ public class SecondaryAuctionT0Session extends AbstractSession implements Initia private final InspectionObligations inspectionObligations; private final FormingRegistersOnOS formingRegistersOnOS; private final FormingPaymentInstructionSecondaryT0 formingPaymentInstruction; - private final FormingPaymentInstructionReturnMkr formingPaymentInstructionReturnMkr; + private final FormingPaymentInstructionDealsFinalMkr formingPaymentInstructionDealsFinalMkr; private final UnlockResources unlockResources; private final FinishingSession finishingSession; private final EndStageNotification endStageNotification; @@ -57,7 +58,7 @@ public class SecondaryAuctionT0Session extends AbstractSession implements Initia InclusionObligations inclusionObligations, FormingRegistersOnOS formingRegistersOnOS, FormingPaymentInstructionSecondaryT0 formingPaymentInstruction, - FormingPaymentInstructionReturnMkr formingPaymentInstructionReturnMkr, + FormingPaymentInstructionDealsFinalMkr formingPaymentInstructionDealsFinalMkr, UnlockResources unlockResources, FinishingSession finishingSession, EndStageNotification endStageNotification, @@ -77,7 +78,7 @@ public class SecondaryAuctionT0Session extends AbstractSession implements Initia this.endStageNotification = endStageNotification; this.executionFondImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_ExecutionFond, ExecutionFond.class); this.inspectionObligations = inspectionObligations; - this.formingPaymentInstructionReturnMkr = formingPaymentInstructionReturnMkr; + this.formingPaymentInstructionDealsFinalMkr = formingPaymentInstructionDealsFinalMkr; this.marketCodes = marketCodes; } @@ -156,10 +157,13 @@ public class SecondaryAuctionT0Session extends AbstractSession implements Initia } StageResult> returnsPayment = null; { - FormingPaymentInstructionPayload payload = new FormingPaymentInstructionPayload(); + FormingPaymentInstructionDealsMkrPayload payload = new FormingPaymentInstructionDealsMkrPayload(); payload.setSessionId(currSession.getId()); + payload.setSendSdfs(false); + payload.setSection(section()); + payload.setPaymentInstructionReturns(new ArrayList<>()); //stage 7 - returnsPayment = runStage(TaskType.FormingPaymentInstruction, payload, formingPaymentInstructionReturnMkr); + returnsPayment = runStage(TaskType.FormingPaymentInstruction, payload, formingPaymentInstructionDealsFinalMkr); } StageResult> paymentResult = null; diff --git a/clearing-parent/clearing-service/src/main/java/ru/spcex/clearing/session/stage/impl/FormingPaymentInstructionDealsFinalMkr.java b/clearing-parent/clearing-service/src/main/java/ru/spcex/clearing/session/stage/impl/FormingPaymentInstructionDealsFinalMkr.java index 37084a3ee..571dff08c 100644 --- a/clearing-parent/clearing-service/src/main/java/ru/spcex/clearing/session/stage/impl/FormingPaymentInstructionDealsFinalMkr.java +++ b/clearing-parent/clearing-service/src/main/java/ru/spcex/clearing/session/stage/impl/FormingPaymentInstructionDealsFinalMkr.java @@ -89,7 +89,8 @@ public class FormingPaymentInstructionDealsFinalMkr implements ISessionStage { FormingPaymentInstructionDealsMkrPayload payload = (FormingPaymentInstructionDealsMkrPayload) task.getData(); switch (task.getTaskType()) { case FormingPaymentInstruction -> { - return formingPaymentInstructions(payload.getSessionId(), payload.getPaymentInstructionReturns()); + return formingPaymentInstructions(payload.getSessionId(), payload.getSection(), + payload.getPaymentInstructionReturns(), payload.isSendSdfs()); } default -> { throw new IllegalStateException("Unknown task type: " + task.getTaskType()); @@ -111,6 +112,7 @@ public class FormingPaymentInstructionDealsFinalMkr implements ISessionStage { .filter(rgs -> Objects.equals(rgs.getValueDate(), rgs.getSettlementDate())) .collect(Collectors.toList()); } + /** * аккаунт-счет с accountType='TRAN' - это счет СПВБ который принадлежит самой бирже
* хранят деньги разных участников
@@ -119,7 +121,8 @@ public class FormingPaymentInstructionDealsFinalMkr implements ISessionStage { * регистр LMAT кто переводит деньги (registry.account)
* в итоге создается 2 PaymentInstruction: LMAT -> TRAN счет -> CMAT счет */ - private StageResult formingPaymentInstructions(Long sessionId, Collection paymentInstructionReturns) { + private StageResult formingPaymentInstructions(Long sessionId, Section section, + Collection paymentInstructionReturns, boolean sendSdfs) { Collection registries = selectRegistries(); log.debug("found registries.size() = {}", registries.size()); //клиринговый счет, через который будут проводиться сделки @@ -188,13 +191,15 @@ public class FormingPaymentInstructionDealsFinalMkr implements ISessionStage { groupId, cm_t.getId(), lm_t.getId()); + String paymentPurpose = section != null && section == Section.FOND ? "" : + "Размещение депозита " + lm_t.getContract() + " по ТКР " + lm_t.getTradingClearingRegistry(); Pair pmtInstrs = PaymentInstructionBuilderFinalMkrDeals .builder(imdgProvider) .cm_t(cm_t) .lm_t(lm_t) .tranAcc(tranAcc) .sessionId(sessionId) - .paymentPurpose("Размещение депозита " + lm_t.getContract() + " по ТКР " + lm_t.getTradingClearingRegistry()) + .paymentPurpose(paymentPurpose) .build(); Pair.forEach(pmtInstrs, pmtInstr -> { paymentInstructionImdg.insert(pmtInstr); @@ -210,7 +215,9 @@ public class FormingPaymentInstructionDealsFinalMkr implements ISessionStage { paymentInstructionReturns.size(), paymentInstructionDeals.size()); List returnsAndDeals = Stream.concat(paymentInstructionReturns.stream(), paymentInstructionDeals.stream()).toList(); - sendSdfs(returnsAndDeals); + if (sendSdfs) { + sendSdfs(returnsAndDeals); + } StageResult> stageResult = new StageResult<>(null, true); stageResult.setStageResult(returnsAndDeals); return stageResult; diff --git a/clearing-parent/clearing-service/src/main/java/ru/spcex/clearing/session/stage/impl/FormingPaymentInstructionSecondaryT0.java b/clearing-parent/clearing-service/src/main/java/ru/spcex/clearing/session/stage/impl/FormingPaymentInstructionSecondaryT0.java index cfda8e1de..bbf7c520b 100644 --- a/clearing-parent/clearing-service/src/main/java/ru/spcex/clearing/session/stage/impl/FormingPaymentInstructionSecondaryT0.java +++ b/clearing-parent/clearing-service/src/main/java/ru/spcex/clearing/session/stage/impl/FormingPaymentInstructionSecondaryT0.java @@ -17,6 +17,7 @@ import ru.spcex.clearing.error.ClearingError; import ru.spcex.clearing.imdg.IMDGDistributedNames; import ru.spcex.clearing.platform.messaging.domain.Consts; import ru.spcex.clearing.platform.messaging.domain.cud.balance.ExportToFileRequest; +import ru.spcex.clearing.platform.messaging.domain.cud.importexport.SwtExporterRequest; import ru.spcex.clearing.platform.messaging.service.sender.KafkaSender; import ru.spcex.clearing.service.Sdf03Creator; import ru.spcex.clearing.service.builder.PaymentInstructionBuilderFinalMkrDeals; @@ -122,14 +123,14 @@ public class FormingPaymentInstructionSecondaryT0 implements ISessionStage { Collection registries = selectRegistries(); log.debug("found registries.size() = {}", registries.size()); //клиринговый счет, через который будут проводиться сделки - Account tranAcc = accountImdg.getSingleObjectBySQL("accountType = '%s' and status = '%s' and processingSign = '%s'" + Account dtrnAcc = accountImdg.getSingleObjectBySQL("accountType = '%s' and status = '%s' and processingSign = '%s'" .formatted(AccountType.Dtrn.getKey(), AccountStatus.ACTIVE.getKey(), Allowed.ALLOWED.getKey())); - if (tranAcc == null) { + if (dtrnAcc == null) { return new StageResult<>( new EnumMessage(ClearingError.AccountNotPresent, "accountType = " + AccountType.Dtrn.getKey()), false); } - log.debug("found tranAcc.id = {}", tranAcc.getId()); + log.debug("found dtrnAcc.id = {}", dtrnAcc.getId()); //группируем регистры по groupId Map> groups = registries .stream() @@ -191,7 +192,7 @@ public class FormingPaymentInstructionSecondaryT0 implements ISessionStage { .builder(imdgProvider) .cm_t(cs_t) .lm_t(ls_t) - .tranAcc(tranAcc) + .tranAcc(dtrnAcc) .sessionId(sessionId) .paymentPurpose("")//todo пока неизвестная формулировка .build(); @@ -234,11 +235,16 @@ public class FormingPaymentInstructionSecondaryT0 implements ISessionStage { private void sendSdfs(List formedPaymentInstructions) { List sDf03Created = new ArrayList<>(); + List sDf12Created = new ArrayList<>(); for (PaymentInstruction paymentInstruction : formedPaymentInstructions) { Account account = accountImdg.getSingleObjectByID(paymentInstruction.getCreditLeg_accountId()); + Security security = securityImdg.getSingleObjectByID(paymentInstruction.getCreditLeg_securityId()); if (List.of(AccountType.Corr, AccountType.Clrn, AccountType.Tran, AccountType.Anlt, AccountType.Info) .contains(IEnumKey.getEnumByKey(AccountType.class, account.getAccountType()))) { sDf03Created.add(sdf03Creator.create(paymentInstruction)); + } else if (!InstrumentType.CRNC.equalsByKey(security.getInstrumentType()) && + AccountType.Depo.equalsByKey(account.getAccountType())) { + sDf12Created.add(newSDf12(paymentInstruction)); } } @@ -254,6 +260,31 @@ public class FormingPaymentInstructionSecondaryT0 implements ISessionStage { exportToFileRequest.setSdfGroupId(sdf03GroupId); kafkaSender.sendRequestToQueue(Consts.EXPORT_PROCESS, exportToFileRequest); } + + Long sdf12GroupId = null; + Long maxTxNumber = 1L; + if (!sDf12Created.isEmpty()) { + sdf12GroupId = imdgProvider.getImdgIdGenerator().nextId(); + ImdgPredicateBuilder predicateBuilder = sDf12Imdg.predicateBuilder(); + ImdgPredicate notEmptyTransactionNum = predicateBuilder.not(predicateBuilder.equals("transactionNumber", "")); + 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) { + SwtExporterRequest swtExporterRequest = new SwtExporterRequest(); + swtExporterRequest.setType("SDF_12"); + kafkaSender.sendRequestToQueue(Consts.SWT_EXPORTER, swtExporterRequest); + } } private SDf12 newSDf12(PaymentInstruction paymentInstruction) { diff --git a/clearing-parent/clearing-service/src/main/java/ru/spcex/clearing/session/stage/task/FormingPaymentInstructionDealsMkrPayload.java b/clearing-parent/clearing-service/src/main/java/ru/spcex/clearing/session/stage/task/FormingPaymentInstructionDealsMkrPayload.java index 51fd741d6..2072c223a 100644 --- a/clearing-parent/clearing-service/src/main/java/ru/spcex/clearing/session/stage/task/FormingPaymentInstructionDealsMkrPayload.java +++ b/clearing-parent/clearing-service/src/main/java/ru/spcex/clearing/session/stage/task/FormingPaymentInstructionDealsMkrPayload.java @@ -1,16 +1,19 @@ package ru.spcex.clearing.session.stage.task; import ru.clearing.classes.statics.data.payment.PaymentInstruction; +import ru.spcex.platform.enumeration.Section; import java.util.Collection; public class FormingPaymentInstructionDealsMkrPayload { private Long sessionId; + private Section section; /** * для МКР итоговой сессии SDF будет отправляться по 1. возвратам 2. сделкам * соотв. поле нужно чтобы передать сделанные пейменты из пункта 1 в 2 */ private Collection paymentInstructionReturns; + private boolean isSendSdfs = true; public Long getSessionId() { return sessionId; } @@ -26,4 +29,20 @@ public class FormingPaymentInstructionDealsMkrPayload { public void setPaymentInstructionReturns(Collection paymentInstructionReturns) { this.paymentInstructionReturns = paymentInstructionReturns; } + + public boolean isSendSdfs() { + return isSendSdfs; + } + + public void setSendSdfs(boolean sendSdfs) { + isSendSdfs = sendSdfs; + } + + public Section getSection() { + return section; + } + + public void setSection(Section section) { + this.section = section; + } }