session type & section checks: FormingPaymentInstructionAssets/InclusionObligations/InspectionObligations

UNIT session: RequirementsAndObligationCreationCompound sorting order
This commit is contained in:
ialbert 2024-06-10 18:06:48 +03:00
parent ea73e16a81
commit 95ad4837e1
5 changed files with 48 additions and 26 deletions

View file

@ -24,6 +24,7 @@ import ru.spcex.clearing.session.stage.impl.InclusionObligations;
import ru.spcex.clearing.session.stage.impl.InspectionObligations; import ru.spcex.clearing.session.stage.impl.InspectionObligations;
import ru.spcex.clearing.session.stage.impl.InspectionObligationsDepositReturn; import ru.spcex.clearing.session.stage.impl.InspectionObligationsDepositReturn;
import ru.spcex.clearing.session.stage.impl.ObligationAdmission; import ru.spcex.clearing.session.stage.impl.ObligationAdmission;
import ru.spcex.clearing.session.stage.impl.PaymentInfo;
import ru.spcex.clearing.session.stage.impl.RequirementsAndObligationCreationCompound; import ru.spcex.clearing.session.stage.impl.RequirementsAndObligationCreationCompound;
import ru.spcex.clearing.session.stage.impl.UnlockResources; import ru.spcex.clearing.session.stage.impl.UnlockResources;
import ru.spcex.clearing.session.stage.impl.compound.CompoundStageDealsPrepare; import ru.spcex.clearing.session.stage.impl.compound.CompoundStageDealsPrepare;
@ -32,6 +33,7 @@ import ru.spcex.clearing.session.stage.monitor.SessionMonitorFactory;
import ru.spcex.clearing.session.stage.task.DealsPreparePayload; import ru.spcex.clearing.session.stage.task.DealsPreparePayload;
import ru.spcex.clearing.session.stage.task.EndStageNotificationPayload; import ru.spcex.clearing.session.stage.task.EndStageNotificationPayload;
import ru.spcex.clearing.session.stage.task.FinishingSessionPayload; import ru.spcex.clearing.session.stage.task.FinishingSessionPayload;
import ru.spcex.clearing.session.stage.task.FormingPaymentInstructionPayload;
import ru.spcex.clearing.session.stage.task.FormingRegistersOnOSPayload; import ru.spcex.clearing.session.stage.task.FormingRegistersOnOSPayload;
import ru.spcex.clearing.session.stage.task.InclusionToPoolPayload; import ru.spcex.clearing.session.stage.task.InclusionToPoolPayload;
import ru.spcex.clearing.session.stage.task.InspectionPoolPayload; import ru.spcex.clearing.session.stage.task.InspectionPoolPayload;
@ -133,6 +135,7 @@ public class UnitedSession extends AbstractSession implements InitializingBean {
inspectionObligationsReturn.setSessionType(sessionType()); inspectionObligationsReturn.setSessionType(sessionType());
inspectionObligations.setSection(section()); inspectionObligations.setSection(section());
inspectionObligations.setSessionType(sessionType()); inspectionObligations.setSessionType(sessionType());
formingPaymentInstructionAssets.setSessionType(sessionType());
finishingSession.setSection(section()); finishingSession.setSection(section());
finishingSession.setSessionType(sessionType()); finishingSession.setSessionType(sessionType());
imdgProvider.waitAvailable(); imdgProvider.waitAvailable();
@ -236,21 +239,21 @@ public class UnitedSession extends AbstractSession implements InitializingBean {
runStage(TaskType.FormingRegistersOnOS, payload, formingRegistersOnOS); //returns Collection<Registry> runStage(TaskType.FormingRegistersOnOS, payload, formingRegistersOnOS); //returns Collection<Registry>
} }
//stage 7 //stage 7
//fixmeStageResult<PaymentInfo> paymentResult = null; StageResult<PaymentInfo> paymentResult = null;
//fixme { {
//fixme FormingPaymentInstructionPayload payload = new FormingPaymentInstructionPayload(); FormingPaymentInstructionPayload payload = new FormingPaymentInstructionPayload();
//fixme payload.setSessionId(currSession.getId()); payload.setSessionId(currSession.getId());
//fixme paymentResult = runStage(TaskType.FormingPaymentInstruction, payload, formingPaymentInstructionAssets); paymentResult = runStage(TaskType.FormingPaymentInstruction, payload, formingPaymentInstructionAssets);
//fixme } }
//fixme if (paymentResult.getStageResult().getPaymentInstructions().isEmpty()) { if (paymentResult.getStageResult().getPaymentInstructions().isEmpty()) {
//fixme log.info("no payment instructions were created"); log.info("no payment instructions were created");
//fixme finishPart(); finishPart();
//fixme } else { } else {
//fixme this.afterPaymentsSdf4And13Monitor = SessionMonitorFactory.waitStep7(section()); this.afterPaymentsSdf4And13Monitor = SessionMonitorFactory.waitStep7(section());
//fixme log.info("created {} PaymentInstructions, waiting for {}", log.info("created {} PaymentInstructions, waiting for {}",
//fixme paymentResult.getStageResult().getPaymentInstructions().size(), paymentResult.getStageResult().getPaymentInstructions().size(),
//fixme this.afterPaymentsSdf4And13Monitor.allConditions()); this.afterPaymentsSdf4And13Monitor.allConditions());
//fixme } }
} catch (StageException e) { } catch (StageException e) {
//already logged //already logged
} }

View file

@ -252,7 +252,8 @@ public class FormingPaymentInstructionAssets implements ISessionStage {
.debitLegAccount(debitLegAccount) .debitLegAccount(debitLegAccount)
.creditLegAccount(creditLegAccount) .creditLegAccount(creditLegAccount)
.amount(amount) .amount(amount)
.currency(SessionType.CURR.equals(sessionType) ? registry.getSecuritySymbol() : null) .currency(SessionType.CURR.equals(sessionType) || Section.CURR.equalsByKey(registry.getSection())
? registry.getSecuritySymbol() : null)
.sessionId(sessionId) .sessionId(sessionId)
.checkBLKD((SessionType.FINL.equals(sessionType) || SessionType.MEDM.equals(sessionType)) .checkBLKD((SessionType.FINL.equals(sessionType) || SessionType.MEDM.equals(sessionType))
&& !isPositiveBalance ? registry : null) && !isPositiveBalance ? registry : null)
@ -325,7 +326,8 @@ public class FormingPaymentInstructionAssets implements ISessionStage {
.creditLegAccount(creditLegAccount) .creditLegAccount(creditLegAccount)
.amount(amount) .amount(amount)
.sessionId(sessionId) .sessionId(sessionId)
.currency(SessionType.CURR.equals(sessionType) ? registry.getSecuritySymbol() : null) .currency(SessionType.CURR.equals(sessionType) || Section.CURR.equalsByKey(registry.getSection())
? registry.getSecuritySymbol() : null)
.purpose(String.format("Перевод по итогу клиринга по ТКР %s", registry.getTradingClearingRegistry())); .purpose(String.format("Перевод по итогу клиринга по ТКР %s", registry.getTradingClearingRegistry()));
PaymentInstruction paymentInstruction = paymentInstructionBuilder.build(); PaymentInstruction paymentInstruction = paymentInstructionBuilder.build();
log.debug("Created paymentInstruction by registry.id: {}", registry.getId()); log.debug("Created paymentInstruction by registry.id: {}", registry.getId());
@ -399,10 +401,11 @@ public class FormingPaymentInstructionAssets implements ISessionStage {
List<SDf12> sDf12Created = new ArrayList<>(); List<SDf12> sDf12Created = new ArrayList<>();
for (Pair<PaymentInstruction, Registry> pair : formedPaymentInstructions) { for (Pair<PaymentInstruction, Registry> pair : formedPaymentInstructions) {
PaymentInstruction paymentInstruction = pair.getFirst(); PaymentInstruction paymentInstruction = pair.getFirst();
Registry rgs = pair.getSecond();
Account account = accountImdg.getSingleObjectByID(paymentInstruction.getCreditLeg_accountId()); Account account = accountImdg.getSingleObjectByID(paymentInstruction.getCreditLeg_accountId());
Security security = securityImdg.getSingleObjectByID(paymentInstruction.getCreditLeg_securityId()); Security security = securityImdg.getSingleObjectByID(paymentInstruction.getCreditLeg_securityId());
if (SessionType.CURR.equals(sessionType)) { if (SessionType.CURR.equals(sessionType) || (rgs != null && Section.CURR.equalsByKey(rgs.getSection()))) {
boolean madeStatements = createStatementsIfNeeded(paymentInstruction, pair.getSecond()); boolean madeStatements = createStatementsIfNeeded(paymentInstruction, rgs);
if (madeStatements) { if (madeStatements) {
continue; continue;
} }

View file

@ -30,6 +30,7 @@ import ru.spcex.platform.enumeration.RegistryDesignation;
import ru.spcex.platform.enumeration.RegistryInstrumentType; import ru.spcex.platform.enumeration.RegistryInstrumentType;
import ru.spcex.platform.enumeration.RegistryStatus; import ru.spcex.platform.enumeration.RegistryStatus;
import ru.spcex.platform.enumeration.RegistryUnit; import ru.spcex.platform.enumeration.RegistryUnit;
import ru.spcex.platform.enumeration.Section;
import ru.spcex.platform.enumeration.SessionType; import ru.spcex.platform.enumeration.SessionType;
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;
@ -37,6 +38,7 @@ import ru.spcex.platform.imdg.api.ImdgProvider;
import ru.spcex.platform.imdg.api.predicate.ImdgPredicate; import ru.spcex.platform.imdg.api.predicate.ImdgPredicate;
import ru.spcex.platform.imdg.api.predicate.ImdgPredicateBuilder; import ru.spcex.platform.imdg.api.predicate.ImdgPredicateBuilder;
import ru.spcex.platform.utils.enumeration.IEnumKey; import ru.spcex.platform.utils.enumeration.IEnumKey;
import ru.spcex.platform.utils.text.TextUtil;
@Service @Service
@ -126,33 +128,46 @@ public class InclusionObligations implements ISessionStage {
for (Map.Entry<Long, List<Registry>> entrySet : registryByGroupId.entrySet()) { for (Map.Entry<Long, List<Registry>> entrySet : registryByGroupId.entrySet()) {
log.debug("Processing set of registry with groupId: {}", entrySet.getKey()); log.debug("Processing set of registry with groupId: {}", entrySet.getKey());
String rgsSection = null;
for (Registry registry : entrySet.getValue()) { for (Registry registry : entrySet.getValue()) {
registry.setRegistryStatus(RegistryStatus.POOL.getKey()); registry.setRegistryStatus(RegistryStatus.POOL.getKey());
registry.setClearingDate(LocalDate.now()); registry.setClearingDate(LocalDate.now());
registry.setSessionId(sessionId); registry.setSessionId(sessionId);
obtainSessionType(sessionId).ifPresent(st -> registry.setSessionType(st.getKey())); obtainSessionType(sessionId).ifPresent(st -> registry.setSessionType(st.getKey()));
registryImdg.update(registry); registryImdg.update(registry);
updateExecutions(sessionId, entrySet.getKey()); if (TextUtil.isEmpty(rgsSection)) {
rgsSection = registry.getSection();
}
} }
updateExecutions(sessionId, entrySet.getKey(), rgsSection);
} }
return new StageResult(null, true); return new StageResult(null, true);
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private <T extends ExecutionCommon> void updateExecutions(Long sessionId, Long rgsGroupId) { private <T extends ExecutionCommon> void updateExecutions(Long sessionId, Long rgsGroupId, String rgsSection) {
Instant now = Instant.now(); Instant now = Instant.now();
SessionType ssnTpe = obtainSessionType(sessionId).orElse(null); SessionType ssnTpe = obtainSessionType(sessionId).orElse(null);
if (ssnTpe == null || sessionId == null) { if (ssnTpe == null || sessionId == null) {
log.debug("will not update executions#sessionId - couldn't determine session type"); log.debug("will not update executions#sessionId - couldn't determine session type");
return; return;
} }
Imdg<T> execImdg; Imdg<T> execImdg = null;
switch (ssnTpe) { switch (ssnTpe) {
case MEDM, FINL, XDEP -> execImdg = (Imdg<T>) executionDepositImdg; case MEDM, FINL, XDEP -> execImdg = (Imdg<T>) executionDepositImdg;
case IPO0, IPOB, TRDT, IPOT -> execImdg = (Imdg<T>) executionFondImdg; case IPO0, IPOB, TRDT, IPOT -> execImdg = (Imdg<T>) executionFondImdg;
case CURR -> execImdg = (Imdg<T>) executionCurrImdg; case CURR -> execImdg = (Imdg<T>) executionCurrImdg;
default -> execImdg = null; default -> {
//кейс для "общих" сессий (напр. UNIT) в которых сочетаются разные сделки
//смотрим на секцию регистра.
Section section;
if ((section = IEnumKey.getEnumByKey(Section.class, rgsSection)) != null) {
if (section.equals(Section.MKR)) execImdg = (Imdg<T>) executionDepositImdg;
else if (section.equals(Section.FOND)) execImdg = (Imdg<T>) executionFondImdg;
else if (section.equals(Section.CURR)) execImdg = (Imdg<T>) executionCurrImdg;
}
}
} }
if (execImdg == null) { if (execImdg == null) {
log.warn("couldn't define Execution Type for session {}. Will not update executions#sessionId", log.warn("couldn't define Execution Type for session {}. Will not update executions#sessionId",
@ -162,10 +177,11 @@ public class InclusionObligations implements ISessionStage {
ImdgPredicateBuilder pb = execImdg.predicateBuilder(); ImdgPredicateBuilder pb = execImdg.predicateBuilder();
ImdgPredicate prdct = pb.equals("exchangeExecutionId", rgsGroupId); ImdgPredicate prdct = pb.equals("exchangeExecutionId", rgsGroupId);
Collection<T> execs = execImdg.getCollectionObjectsByPredicate(prdct); Collection<T> execs = execImdg.getCollectionObjectsByPredicate(prdct);
Imdg<T> finalExecImdg = execImdg;
execs.forEach(e -> { execs.forEach(e -> {
e.setUpdated(now); e.setUpdated(now);
e.setSessionId(sessionId); e.setSessionId(sessionId);
execImdg.update(e); finalExecImdg.update(e);
}); });
} }

View file

@ -156,7 +156,7 @@ public class InspectionObligations implements ISessionStage {
failGroup.run(); failGroup.run();
continue; continue;
} }
if (Section.MKR.equals(section) && mOrS.equals(RegistryInstrumentType.S)) { if (Section.MKR.equalsByKey(rgs.getSection()) && mOrS.equals(RegistryInstrumentType.S)) {
continue; continue;
} }
Optional<Registry> a__t = assets.searchByTcrCompanyAccount(rgs, A__T.type(mOrS)); Optional<Registry> a__t = assets.searchByTcrCompanyAccount(rgs, A__T.type(mOrS));

View file

@ -96,6 +96,6 @@ public class RequirementsAndObligationCreationCompound extends RequirementsAndOb
return Stream.of(fond, deposit, currency) return Stream.of(fond, deposit, currency)
.filter(Objects::nonNull) .filter(Objects::nonNull)
.max((p1, p2) -> tradeTimeComparator.compare(p1.getFirst(), p2.getFirst())).orElse(null); .min((p1, p2) -> tradeTimeComparator.compare(p1.getFirst(), p2.getFirst())).orElse(null);
} }
} }