правка 7 шага для МКР и промежуточной сессии
This commit is contained in:
parent
7174024333
commit
c8fa6e052e
4 changed files with 111 additions and 76 deletions
|
|
@ -43,7 +43,7 @@ public class FinalMkrSession extends AbstractSession implements InitializingBean
|
||||||
private final InspectionObligations inspectionObligations;
|
private final InspectionObligations inspectionObligations;
|
||||||
private final FormingRegistersOnOS formingRegistersOnOS;
|
private final FormingRegistersOnOS formingRegistersOnOS;
|
||||||
private final FormingPaymentInstructionReturnMkr formingPaymentInstructionReturn;
|
private final FormingPaymentInstructionReturnMkr formingPaymentInstructionReturn;
|
||||||
private final FormingPaymentInstructionDealsFinalMkr formingPaymentInstructionDeals;
|
private final FormingPaymentInstructionAssets formingPaymentInstructionDeals;
|
||||||
private final UnlockResources unlockResources;
|
private final UnlockResources unlockResources;
|
||||||
private final FinishingSession finishingSession;
|
private final FinishingSession finishingSession;
|
||||||
private final EndStageNotification endStageNotification;
|
private final EndStageNotification endStageNotification;
|
||||||
|
|
@ -61,7 +61,7 @@ public class FinalMkrSession extends AbstractSession implements InitializingBean
|
||||||
ObligationAdmission obligationsAdmission,
|
ObligationAdmission obligationsAdmission,
|
||||||
InclusionObligations inclusionObligations,
|
InclusionObligations inclusionObligations,
|
||||||
InspectionObligations inspectionObligations, FormingRegistersOnOS formingRegistersOnOS,
|
InspectionObligations inspectionObligations, FormingRegistersOnOS formingRegistersOnOS,
|
||||||
FormingPaymentInstructionReturnMkr formingPaymentInstructionReturn, FormingPaymentInstructionDealsFinalMkr formingPaymentInstructionDeals,
|
FormingPaymentInstructionReturnMkr formingPaymentInstructionReturn, FormingPaymentInstructionAssets formingPaymentInstructionDeals,
|
||||||
UnlockResources unlockResources,
|
UnlockResources unlockResources,
|
||||||
FinishingSession finishingSession,
|
FinishingSession finishingSession,
|
||||||
EndStageNotification endStageNotification,
|
EndStageNotification endStageNotification,
|
||||||
|
|
@ -104,6 +104,7 @@ public class FinalMkrSession extends AbstractSession implements InitializingBean
|
||||||
inclusionObligations.setSessionType(sessionType());
|
inclusionObligations.setSessionType(sessionType());
|
||||||
inspectionObligationsReturn.setSessionType(sessionType());
|
inspectionObligationsReturn.setSessionType(sessionType());
|
||||||
inspectionObligations.setSessionType(sessionType());
|
inspectionObligations.setSessionType(sessionType());
|
||||||
|
formingPaymentInstructionDeals.setSection(section());
|
||||||
imdgProvider.waitAvailable();
|
imdgProvider.waitAvailable();
|
||||||
initSessionIfPresent();
|
initSessionIfPresent();
|
||||||
}
|
}
|
||||||
|
|
@ -197,7 +198,7 @@ public class FinalMkrSession extends AbstractSession implements InitializingBean
|
||||||
|
|
||||||
StageResult<Collection<PaymentInstruction>> paymentResult = null;
|
StageResult<Collection<PaymentInstruction>> paymentResult = null;
|
||||||
{
|
{
|
||||||
FormingPaymentInstructionDealsMkrPayload payload = new FormingPaymentInstructionDealsMkrPayload();
|
FormingPaymentInstructionPayload payload = new FormingPaymentInstructionPayload();
|
||||||
payload.setSessionId(currSession.getId());
|
payload.setSessionId(currSession.getId());
|
||||||
payload.setPaymentInstructionReturns(returnsPayment.getStageResult());
|
payload.setPaymentInstructionReturns(returnsPayment.getStageResult());
|
||||||
//stage 7
|
//stage 7
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ public class IntermediateMkrSession extends AbstractSession implements Initializ
|
||||||
private final InspectionObligations inspectionObligations;
|
private final InspectionObligations inspectionObligations;
|
||||||
private final FormingRegistersOnOS formingRegistersOnOS;
|
private final FormingRegistersOnOS formingRegistersOnOS;
|
||||||
private final FormingPaymentInstructionReturnMkr formingPaymentInstructionReturn;
|
private final FormingPaymentInstructionReturnMkr formingPaymentInstructionReturn;
|
||||||
private final FormingPaymentInstructionDealsFinalMkr formingPaymentInstructionDeals;
|
private final FormingPaymentInstructionAssets formingPaymentInstructionDeals;
|
||||||
private final UnlockResources unlockResources;
|
private final UnlockResources unlockResources;
|
||||||
private final FinishingSession finishingSession;
|
private final FinishingSession finishingSession;
|
||||||
private final EndStageNotification endStageNotification;
|
private final EndStageNotification endStageNotification;
|
||||||
|
|
@ -61,7 +61,7 @@ public class IntermediateMkrSession extends AbstractSession implements Initializ
|
||||||
ObligationAdmission obligationsAdmission,
|
ObligationAdmission obligationsAdmission,
|
||||||
InclusionObligations inclusionObligations,
|
InclusionObligations inclusionObligations,
|
||||||
InspectionObligations inspectionObligations, FormingRegistersOnOS formingRegistersOnOS,
|
InspectionObligations inspectionObligations, FormingRegistersOnOS formingRegistersOnOS,
|
||||||
FormingPaymentInstructionReturnMkr formingPaymentInstructionReturn, FormingPaymentInstructionDealsFinalMkr formingPaymentInstructionDeals,
|
FormingPaymentInstructionReturnMkr formingPaymentInstructionReturn, FormingPaymentInstructionAssets formingPaymentInstructionDeals,
|
||||||
UnlockResources unlockResources,
|
UnlockResources unlockResources,
|
||||||
FinishingSession finishingSession,
|
FinishingSession finishingSession,
|
||||||
EndStageNotification endStageNotification,
|
EndStageNotification endStageNotification,
|
||||||
|
|
@ -104,6 +104,7 @@ public class IntermediateMkrSession extends AbstractSession implements Initializ
|
||||||
inclusionObligations.setSessionType(sessionType());
|
inclusionObligations.setSessionType(sessionType());
|
||||||
inspectionObligationsReturn.setSessionType(sessionType());
|
inspectionObligationsReturn.setSessionType(sessionType());
|
||||||
inspectionObligations.setSessionType(sessionType());
|
inspectionObligations.setSessionType(sessionType());
|
||||||
|
formingPaymentInstructionDeals.setSection(section());
|
||||||
imdgProvider.waitAvailable();
|
imdgProvider.waitAvailable();
|
||||||
initSessionIfPresent();
|
initSessionIfPresent();
|
||||||
}
|
}
|
||||||
|
|
@ -184,7 +185,7 @@ public class IntermediateMkrSession extends AbstractSession implements Initializ
|
||||||
|
|
||||||
StageResult<Collection<PaymentInstruction>> paymentResult = null;
|
StageResult<Collection<PaymentInstruction>> paymentResult = null;
|
||||||
{
|
{
|
||||||
FormingPaymentInstructionDealsMkrPayload payload = new FormingPaymentInstructionDealsMkrPayload();
|
FormingPaymentInstructionPayload payload = new FormingPaymentInstructionPayload();
|
||||||
payload.setSessionId(currSession.getId());
|
payload.setSessionId(currSession.getId());
|
||||||
payload.setPaymentInstructionReturns(returnsPayment.getStageResult());
|
payload.setPaymentInstructionReturns(returnsPayment.getStageResult());
|
||||||
//stage 7
|
//stage 7
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,7 @@ import ru.spcex.platform.utils.number.BigDecimalUtil;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import static ru.spcex.platform.enumeration.RegistryTradingParams.*;
|
import static ru.spcex.platform.enumeration.RegistryTradingParams.*;
|
||||||
import static ru.spcex.platform.utils.number.BigDecimalUtil.safeBD;
|
import static ru.spcex.platform.utils.number.BigDecimalUtil.safeBD;
|
||||||
|
|
@ -66,6 +67,7 @@ public class FormingPaymentInstructionAssets implements ISessionStage {
|
||||||
private final IMessageResolver msgResolver = new SimpleMessageResolver();
|
private final IMessageResolver msgResolver = new SimpleMessageResolver();
|
||||||
private final SecuritySelector<Security> securitySelector;
|
private final SecuritySelector<Security> securitySelector;
|
||||||
private final RegistryManager rgsMng;
|
private final RegistryManager rgsMng;
|
||||||
|
private Section section;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public FormingPaymentInstructionAssets(ImdgProvider imdgProvider,
|
public FormingPaymentInstructionAssets(ImdgProvider imdgProvider,
|
||||||
|
|
@ -90,7 +92,7 @@ public class FormingPaymentInstructionAssets implements ISessionStage {
|
||||||
FormingPaymentInstructionPayload payload = (FormingPaymentInstructionPayload) task.getData();
|
FormingPaymentInstructionPayload payload = (FormingPaymentInstructionPayload) task.getData();
|
||||||
switch (task.getTaskType()) {
|
switch (task.getTaskType()) {
|
||||||
case FormingPaymentInstruction -> {
|
case FormingPaymentInstruction -> {
|
||||||
return formingPaymentInstructions(payload.getSessionId());
|
return formingPaymentInstructions(payload);
|
||||||
}
|
}
|
||||||
default -> {
|
default -> {
|
||||||
throw new IllegalStateException("Unknown task type: " + task.getTaskType());
|
throw new IllegalStateException("Unknown task type: " + task.getTaskType());
|
||||||
|
|
@ -98,12 +100,15 @@ public class FormingPaymentInstructionAssets implements ISessionStage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Collection<Registry> selectAMBRegistries() {
|
private Collection<Registry> selectAMBRegistries(Long sessionId) {
|
||||||
ImdgPredicateBuilder rgsPb = registryImdg.predicateBuilder();
|
ImdgPredicateBuilder rgsPb = registryImdg.predicateBuilder();
|
||||||
RegistryCodeSqlBuilder registryCodeSqlBuilder = RegistryCodeSqlBuilder.getInstance(
|
RegistryCodeSqlBuilder registryCodeSqlBuilder = RegistryCodeSqlBuilder.getInstance(
|
||||||
AM_B
|
AM_B
|
||||||
);
|
);
|
||||||
ImdgPredicate rgsCodePrdct = rgsPb.sql(registryCodeSqlBuilder.build());
|
ImdgPredicate rgsCodePrdct = rgsPb.and(
|
||||||
|
rgsPb.sql(registryCodeSqlBuilder.build()),
|
||||||
|
rgsPb.equals("sessionId", sessionId)
|
||||||
|
);
|
||||||
return registryImdg.getCollectionObjectsByPredicate(rgsCodePrdct);
|
return registryImdg.getCollectionObjectsByPredicate(rgsCodePrdct);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -116,8 +121,9 @@ public class FormingPaymentInstructionAssets implements ISessionStage {
|
||||||
return registryImdg.getCollectionObjectsByPredicate(rgsCodePrdct);
|
return registryImdg.getCollectionObjectsByPredicate(rgsCodePrdct);
|
||||||
}
|
}
|
||||||
|
|
||||||
private StageResult<?> formingPaymentInstructions(Long sessionId) {
|
private StageResult<?> formingPaymentInstructions(FormingPaymentInstructionPayload payload) {
|
||||||
Collection<Registry> AMBregistries = selectAMBRegistries();
|
Long sessionId = payload.getSessionId();
|
||||||
|
Collection<Registry> AMBregistries = selectAMBRegistries(sessionId);
|
||||||
log.debug("found AMB registries.size() = {}", AMBregistries.size());
|
log.debug("found AMB registries.size() = {}", AMBregistries.size());
|
||||||
Instant now = Instant.now();
|
Instant now = Instant.now();
|
||||||
Account tranAcc = accountImdg.getFirstObjectBySQL("accountType = '%s' and status = '%s' and processingSign = '%s'"
|
Account tranAcc = accountImdg.getFirstObjectBySQL("accountType = '%s' and status = '%s' and processingSign = '%s'"
|
||||||
|
|
@ -210,75 +216,84 @@ public class FormingPaymentInstructionAssets implements ISessionStage {
|
||||||
registryImdg.update(registry);
|
registryImdg.update(registry);
|
||||||
paymentInstructions.add(paymentInstruction);
|
paymentInstructions.add(paymentInstruction);
|
||||||
}
|
}
|
||||||
|
if (section == null || !section.equals(Section.MKR)) {
|
||||||
|
Collection<Registry> ASBregistries = selectASBRegistries();
|
||||||
|
log.debug("found ASB registries.size() = {}", ASBregistries.size());
|
||||||
|
|
||||||
Collection<Registry> ASBregistries = selectASBRegistries();
|
for (Registry registry : ASBregistries) {
|
||||||
log.debug("found ASB registries.size() = {}", ASBregistries.size());
|
//по каждому AMB регистру создаем PaymentInstruction
|
||||||
|
//проверяем balance посчитанный на шаге 5
|
||||||
|
|
||||||
for (Registry registry : ASBregistries) {
|
if (registry.getBalance().compareTo(BigDecimal.ZERO) == 0) {
|
||||||
//по каждому AMB регистру создаем PaymentInstruction
|
log.debug("Skip creating paymentInstruction by registry with 0 balance");
|
||||||
//проверяем balance посчитанный на шаге 5
|
continue;
|
||||||
|
}
|
||||||
if (registry.getBalance().compareTo(BigDecimal.ZERO) == 0) {
|
Account counterAcc = accountImdg.getSingleObjectByID(registry.getAccountId());
|
||||||
log.debug("Skip creating paymentInstruction by registry with 0 balance");
|
boolean isPositiveBalance = registry.getBalance().compareTo(BigDecimal.ZERO) > 0;
|
||||||
continue;
|
Long senderId;
|
||||||
|
Long addresseeId;
|
||||||
|
Account debitLegAccount;
|
||||||
|
Account creditLegAccount;
|
||||||
|
BigDecimal amount;
|
||||||
|
if (isPositiveBalance) {
|
||||||
|
senderId = registry.getCompanyId();
|
||||||
|
addresseeId = Sender.One.getId();
|
||||||
|
debitLegAccount = dtrnAcc;
|
||||||
|
creditLegAccount = counterAcc;
|
||||||
|
amount = registry.getBalance() == null ? null : registry.getBalance().abs();
|
||||||
|
Optional<Registry> payerAstO = rgsMng.findRelatedAsset(
|
||||||
|
registry.getTradingClearingRegistryId(),
|
||||||
|
registry.getCompanyId(),
|
||||||
|
registry.getSecuritySymbol(),
|
||||||
|
AS_T
|
||||||
|
);
|
||||||
|
payerAstO.ifPresent(amt -> {
|
||||||
|
amt.setSettledDebit(safeBD(amt.getSettledDebit()).add(safeBD(registry.getBalance().abs())));
|
||||||
|
setUpdatedStoreInImdg(amt, now);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
senderId = Sender.One.getId();
|
||||||
|
addresseeId = registry.getCompanyId();
|
||||||
|
debitLegAccount = counterAcc;
|
||||||
|
creditLegAccount = dtrnAcc;
|
||||||
|
amount = registry.getBalance() == null ? null : registry.getBalance().abs();
|
||||||
|
Optional<Registry> payerAstO = rgsMng.findRelatedAsset(
|
||||||
|
registry.getTradingClearingRegistryId(),
|
||||||
|
registry.getCompanyId(),
|
||||||
|
registry.getSecuritySymbol(),
|
||||||
|
AS_T
|
||||||
|
);
|
||||||
|
payerAstO.ifPresent(amt -> {
|
||||||
|
amt.setSettledCredit(safeBD(amt.getSettledCredit()).add(safeBD(registry.getBalance().abs())));
|
||||||
|
setUpdatedStoreInImdg(amt, now);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
PaymentInstructionBuilderV2 paymentInstructionBuilder = PaymentInstructionBuilderV2.builder(imdgProvider)
|
||||||
|
.registry(registry)
|
||||||
|
.sender(senderId)
|
||||||
|
.addressee(addresseeId)
|
||||||
|
.debitLegAccount(debitLegAccount)
|
||||||
|
.creditLegAccount(creditLegAccount)
|
||||||
|
.amount(amount)
|
||||||
|
.sessionId(sessionId)
|
||||||
|
.purpose(String.format("Перевод по итогу клиринга по ТКР %s", registry.getTradingClearingRegistry()));
|
||||||
|
PaymentInstruction paymentInstruction = paymentInstructionBuilder.build();
|
||||||
|
log.debug("Created paymentInstruction by registry.id: {}", registry.getId());
|
||||||
|
paymentInstructionImdg.insert(paymentInstruction);
|
||||||
|
registry.setPaymentId(paymentInstruction.getId());
|
||||||
|
registry.setUpdated(now);
|
||||||
|
registryImdg.update(registry);
|
||||||
|
paymentInstructions.add(paymentInstruction);
|
||||||
}
|
}
|
||||||
Account counterAcc = accountImdg.getSingleObjectByID(registry.getAccountId());
|
|
||||||
boolean isPositiveBalance = registry.getBalance().compareTo(BigDecimal.ZERO) > 0;
|
|
||||||
Long senderId;
|
|
||||||
Long addresseeId;
|
|
||||||
Account debitLegAccount;
|
|
||||||
Account creditLegAccount;
|
|
||||||
BigDecimal amount;
|
|
||||||
if (isPositiveBalance) {
|
|
||||||
senderId = registry.getCompanyId();
|
|
||||||
addresseeId = Sender.One.getId();
|
|
||||||
debitLegAccount = dtrnAcc;
|
|
||||||
creditLegAccount = counterAcc;
|
|
||||||
amount = registry.getBalance() == null ? null : registry.getBalance().abs();
|
|
||||||
Optional<Registry> payerAstO = rgsMng.findRelatedAsset(
|
|
||||||
registry.getTradingClearingRegistryId(),
|
|
||||||
registry.getCompanyId(),
|
|
||||||
registry.getSecuritySymbol(),
|
|
||||||
AS_T
|
|
||||||
);
|
|
||||||
payerAstO.ifPresent(amt -> {
|
|
||||||
amt.setSettledDebit(safeBD(amt.getSettledDebit()).add(safeBD(registry.getBalance().abs())));
|
|
||||||
setUpdatedStoreInImdg(amt, now);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
senderId = Sender.One.getId();
|
|
||||||
addresseeId = registry.getCompanyId();
|
|
||||||
debitLegAccount = counterAcc;
|
|
||||||
creditLegAccount = dtrnAcc;
|
|
||||||
amount = registry.getBalance() == null ? null : registry.getBalance().abs();
|
|
||||||
Optional<Registry> payerAstO = rgsMng.findRelatedAsset(
|
|
||||||
registry.getTradingClearingRegistryId(),
|
|
||||||
registry.getCompanyId(),
|
|
||||||
registry.getSecuritySymbol(),
|
|
||||||
AS_T
|
|
||||||
);
|
|
||||||
payerAstO.ifPresent(amt -> {
|
|
||||||
amt.setSettledCredit(safeBD(amt.getSettledCredit()).add(safeBD(registry.getBalance().abs())));
|
|
||||||
setUpdatedStoreInImdg(amt, now);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
PaymentInstructionBuilderV2 paymentInstructionBuilder = PaymentInstructionBuilderV2.builder(imdgProvider)
|
|
||||||
.registry(registry)
|
|
||||||
.sender(senderId)
|
|
||||||
.addressee(addresseeId)
|
|
||||||
.debitLegAccount(debitLegAccount)
|
|
||||||
.creditLegAccount(creditLegAccount)
|
|
||||||
.amount(amount)
|
|
||||||
.sessionId(sessionId)
|
|
||||||
.purpose(String.format("Перевод по итогу клиринга по ТКР %s", registry.getTradingClearingRegistry()));
|
|
||||||
PaymentInstruction paymentInstruction = paymentInstructionBuilder.build();
|
|
||||||
log.debug("Created paymentInstruction by registry.id: {}", registry.getId());
|
|
||||||
paymentInstructionImdg.insert(paymentInstruction);
|
|
||||||
registry.setPaymentId(paymentInstruction.getId());
|
|
||||||
registry.setUpdated(now);
|
|
||||||
registryImdg.update(registry);
|
|
||||||
paymentInstructions.add(paymentInstruction);
|
|
||||||
}
|
}
|
||||||
|
if (payload.getPaymentInstructionReturns().size() > 0) {
|
||||||
|
log.debug("PaymentInstructions return size {}, PaymentInstructions deals size {}. sending SDF03",
|
||||||
|
payload.getPaymentInstructionReturns().size(),
|
||||||
|
paymentInstructions.size());
|
||||||
|
paymentInstructions = Stream.concat(payload.getPaymentInstructionReturns().stream(),
|
||||||
|
paymentInstructions.stream()).toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
sendSdfs(paymentInstructions);
|
sendSdfs(paymentInstructions);
|
||||||
StageResult<Collection<PaymentInstruction>> stageResult = new StageResult<>(null, true);
|
StageResult<Collection<PaymentInstruction>> stageResult = new StageResult<>(null, true);
|
||||||
|
|
@ -364,4 +379,8 @@ public class FormingPaymentInstructionAssets implements ISessionStage {
|
||||||
sDf12.setGenerationTime(Instant.now());
|
sDf12.setGenerationTime(Instant.now());
|
||||||
return sDf12;
|
return sDf12;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setSection(Section section) {
|
||||||
|
this.section = section;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,13 @@
|
||||||
package ru.spcex.clearing.session.stage.task;
|
package ru.spcex.clearing.session.stage.task;
|
||||||
|
|
||||||
|
import ru.clearing.classes.statics.data.payment.PaymentInstruction;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
public class FormingPaymentInstructionPayload {
|
public class FormingPaymentInstructionPayload {
|
||||||
private Long sessionId;
|
private Long sessionId;
|
||||||
|
private Collection<PaymentInstruction> paymentInstructionReturns;
|
||||||
|
|
||||||
public Long getSessionId() {
|
public Long getSessionId() {
|
||||||
return sessionId;
|
return sessionId;
|
||||||
|
|
@ -10,4 +16,12 @@ public class FormingPaymentInstructionPayload {
|
||||||
public void setSessionId(Long sessionId) {
|
public void setSessionId(Long sessionId) {
|
||||||
this.sessionId = sessionId;
|
this.sessionId = sessionId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Collection<PaymentInstruction> getPaymentInstructionReturns() {
|
||||||
|
return paymentInstructionReturns != null ? paymentInstructionReturns : Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPaymentInstructionReturns(Collection<PaymentInstruction> paymentInstructionReturns) {
|
||||||
|
this.paymentInstructionReturns = paymentInstructionReturns;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue