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

View file

@ -252,7 +252,8 @@ public class FormingPaymentInstructionAssets implements ISessionStage {
.debitLegAccount(debitLegAccount)
.creditLegAccount(creditLegAccount)
.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)
.checkBLKD((SessionType.FINL.equals(sessionType) || SessionType.MEDM.equals(sessionType))
&& !isPositiveBalance ? registry : null)
@ -325,7 +326,8 @@ public class FormingPaymentInstructionAssets implements ISessionStage {
.creditLegAccount(creditLegAccount)
.amount(amount)
.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()));
PaymentInstruction paymentInstruction = paymentInstructionBuilder.build();
log.debug("Created paymentInstruction by registry.id: {}", registry.getId());
@ -399,10 +401,11 @@ public class FormingPaymentInstructionAssets implements ISessionStage {
List<SDf12> sDf12Created = new ArrayList<>();
for (Pair<PaymentInstruction, Registry> pair : formedPaymentInstructions) {
PaymentInstruction paymentInstruction = pair.getFirst();
Registry rgs = pair.getSecond();
Account account = accountImdg.getSingleObjectByID(paymentInstruction.getCreditLeg_accountId());
Security security = securityImdg.getSingleObjectByID(paymentInstruction.getCreditLeg_securityId());
if (SessionType.CURR.equals(sessionType)) {
boolean madeStatements = createStatementsIfNeeded(paymentInstruction, pair.getSecond());
if (SessionType.CURR.equals(sessionType) || (rgs != null && Section.CURR.equalsByKey(rgs.getSection()))) {
boolean madeStatements = createStatementsIfNeeded(paymentInstruction, rgs);
if (madeStatements) {
continue;
}

View file

@ -30,6 +30,7 @@ import ru.spcex.platform.enumeration.RegistryDesignation;
import ru.spcex.platform.enumeration.RegistryInstrumentType;
import ru.spcex.platform.enumeration.RegistryStatus;
import ru.spcex.platform.enumeration.RegistryUnit;
import ru.spcex.platform.enumeration.Section;
import ru.spcex.platform.enumeration.SessionType;
import ru.spcex.platform.imdg.api.Imdg;
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.ImdgPredicateBuilder;
import ru.spcex.platform.utils.enumeration.IEnumKey;
import ru.spcex.platform.utils.text.TextUtil;
@Service
@ -126,33 +128,46 @@ public class InclusionObligations implements ISessionStage {
for (Map.Entry<Long, List<Registry>> entrySet : registryByGroupId.entrySet()) {
log.debug("Processing set of registry with groupId: {}", entrySet.getKey());
String rgsSection = null;
for (Registry registry : entrySet.getValue()) {
registry.setRegistryStatus(RegistryStatus.POOL.getKey());
registry.setClearingDate(LocalDate.now());
registry.setSessionId(sessionId);
obtainSessionType(sessionId).ifPresent(st -> registry.setSessionType(st.getKey()));
registryImdg.update(registry);
updateExecutions(sessionId, entrySet.getKey());
if (TextUtil.isEmpty(rgsSection)) {
rgsSection = registry.getSection();
}
}
updateExecutions(sessionId, entrySet.getKey(), rgsSection);
}
return new StageResult(null, true);
}
@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();
SessionType ssnTpe = obtainSessionType(sessionId).orElse(null);
if (ssnTpe == null || sessionId == null) {
log.debug("will not update executions#sessionId - couldn't determine session type");
return;
}
Imdg<T> execImdg;
Imdg<T> execImdg = null;
switch (ssnTpe) {
case MEDM, FINL, XDEP -> execImdg = (Imdg<T>) executionDepositImdg;
case IPO0, IPOB, TRDT, IPOT -> execImdg = (Imdg<T>) executionFondImdg;
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) {
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();
ImdgPredicate prdct = pb.equals("exchangeExecutionId", rgsGroupId);
Collection<T> execs = execImdg.getCollectionObjectsByPredicate(prdct);
Imdg<T> finalExecImdg = execImdg;
execs.forEach(e -> {
e.setUpdated(now);
e.setSessionId(sessionId);
execImdg.update(e);
finalExecImdg.update(e);
});
}

View file

@ -156,7 +156,7 @@ public class InspectionObligations implements ISessionStage {
failGroup.run();
continue;
}
if (Section.MKR.equals(section) && mOrS.equals(RegistryInstrumentType.S)) {
if (Section.MKR.equalsByKey(rgs.getSection()) && mOrS.equals(RegistryInstrumentType.S)) {
continue;
}
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)
.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);
}
}