diff --git a/clearing-parent/registry-service/src/main/java/ru/spcex/clearing/registry/service/DepoPaymentInstructionRegisterService.java b/clearing-parent/registry-service/src/main/java/ru/spcex/clearing/registry/service/DepoPaymentInstructionRegisterService.java index fb09c0230..3e428210a 100644 --- a/clearing-parent/registry-service/src/main/java/ru/spcex/clearing/registry/service/DepoPaymentInstructionRegisterService.java +++ b/clearing-parent/registry-service/src/main/java/ru/spcex/clearing/registry/service/DepoPaymentInstructionRegisterService.java @@ -7,6 +7,7 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import ru.clearing.classes.statics.data.account.Account; import ru.clearing.classes.statics.data.misc.Session; import ru.clearing.classes.statics.data.payment.PaymentInstruction; import ru.clearing.classes.statics.data.register.DepoPaymentInstructionRegister; @@ -17,11 +18,13 @@ import ru.spcex.clearing.platform.messaging.domain.BaseRequest; import ru.spcex.clearing.platform.messaging.domain.cud.schedule.LauncherCommandRequest; import ru.spcex.clearing.platform.messaging.service.QueueConsumer; import ru.spcex.clearing.registry.util.PreClearMap; +import ru.spcex.platform.enumeration.AccountType; import ru.spcex.platform.imdg.api.Imdg; import ru.spcex.platform.imdg.api.ImdgProvider; import ru.spcex.platform.utils.validation.IValidator; import java.time.Instant; +import java.util.ArrayList; import java.util.Collection; import java.util.Map; import java.util.Optional; @@ -39,6 +42,7 @@ public class DepoPaymentInstructionRegisterService extends QueueConsumer impleme private final Imdg sessionMap; private final Imdg tradingClearingRegistryMap; private final Imdg InOutDirectionDictionaryMap; + private final Imdg accountMap; private final Function, IValidator> fieldValuesValidator; private final PreClearMap preClearMap; @@ -53,6 +57,7 @@ public class DepoPaymentInstructionRegisterService extends QueueConsumer impleme this.sessionMap = imdgProvider.getImdg(IMDGDistributedNames.Map_Session, Session.class); this.tradingClearingRegistryMap = imdgProvider.getImdg(IMDGDistributedNames.Map_TradingClearingRegistry, TradingClearingRegistry.class); this.InOutDirectionDictionaryMap = imdgProvider.getImdg(IMDGDistributedNames.Map_InOutDirectionDictionary, InOutDirectionDictionary.class); + this.accountMap = imdgProvider.getImdg(IMDGDistributedNames.Map_Account, Account.class); this.fieldValuesValidator = fieldValuesValidator; preClearMap = PreClearMap.instanceForInstantField(depoPaymentInstructionRegisterMap, "created"); } @@ -68,25 +73,32 @@ public class DepoPaymentInstructionRegisterService extends QueueConsumer impleme public void depoPaymentInstructionRegisterNew(BaseRequest userRequest) { log.debug("LauncherCommandRequest received from {}", createRegistry_GORR.topic()); - Map sessionQuery = Map.of("section", "FOND"); - Collection actualSessions = sessionMap.getCollectionObjectsByFieldValues(sessionQuery); - if (actualSessions.isEmpty()) { - log.debug("No Session with such conditions section = FOND"); - return; - } - log.debug("Select {} Session by query {}", actualSessions.size(), sessionQuery); - preClearMap.preClearMap(); - for (Session session : actualSessions) { - Map> fieldValues = Map.of("sessionId", session.getId()); - Collection paymentInstructionBySessionId = - paymentInstructionMap.getCollectionObjectsByFieldValues(fieldValues); - log.debug("Select {} PaymentInstruction by query {}", paymentInstructionBySessionId.size(), fieldValues); - for (PaymentInstruction paymentInstruction : paymentInstructionBySessionId) { - if (isDuplicateInMap(paymentInstruction).isEmpty()) { - insertDepoPaymentInstructionRegister(paymentInstruction); + + Collection paymentInstructions = paymentInstructionMap.getAllValues(); + log.debug("Selected {} PaymentInstruction, do filter by account...", paymentInstructions.size()); + Collection depoPaymentInstructions = new ArrayList<>(); + for (PaymentInstruction paymentInstruction : paymentInstructions) { + // filter by accountType + if (paymentInstruction.getCreditLeg_accountId() != null) { + Account account = accountMap.getSingleObjectByID(paymentInstruction.getCreditLeg_accountId()); + if (account == null) + log.warn("Account id={} not found for paymentInstruction.id={}", + paymentInstruction.getCreditLeg_accountId(), paymentInstruction.getId()); + else { + if (AccountType.Depo.equalsByKey(account.getAccountType())) { + depoPaymentInstructions.add(paymentInstruction); + } } } } + paymentInstructions = null; + log.debug("Filtered {} PaymentInstruction, with depo account's", depoPaymentInstructions.size()); + preClearMap.preClearMap(); + for (PaymentInstruction paymentInstruction : depoPaymentInstructions) { + if (isDuplicateInMap(paymentInstruction).isEmpty()) { + insertDepoPaymentInstructionRegister(paymentInstruction); + } + } log.debug("successfully processed"); } diff --git a/clearing-parent/registry-service/src/main/java/ru/spcex/clearing/registry/service/MoneyPaymentInstructionRegisterService.java b/clearing-parent/registry-service/src/main/java/ru/spcex/clearing/registry/service/MoneyPaymentInstructionRegisterService.java index 6691c2d01..684f3437c 100644 --- a/clearing-parent/registry-service/src/main/java/ru/spcex/clearing/registry/service/MoneyPaymentInstructionRegisterService.java +++ b/clearing-parent/registry-service/src/main/java/ru/spcex/clearing/registry/service/MoneyPaymentInstructionRegisterService.java @@ -7,6 +7,7 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import ru.clearing.classes.statics.data.account.Account; import ru.clearing.classes.statics.data.company.Company; import ru.clearing.classes.statics.data.misc.Session; import ru.clearing.classes.statics.data.payment.PaymentInstruction; @@ -16,11 +17,14 @@ import ru.spcex.clearing.platform.messaging.domain.BaseRequest; import ru.spcex.clearing.platform.messaging.domain.cud.schedule.LauncherCommandRequest; import ru.spcex.clearing.platform.messaging.service.QueueConsumer; import ru.spcex.clearing.registry.util.PreClearMap; +import ru.spcex.platform.enumeration.AccountType; import ru.spcex.platform.imdg.api.Imdg; import ru.spcex.platform.imdg.api.ImdgProvider; +import ru.spcex.platform.utils.enumeration.IEnumKey; import ru.spcex.platform.utils.validation.IValidator; import java.time.Instant; +import java.util.ArrayList; import java.util.Collection; import java.util.Map; import java.util.Optional; @@ -37,6 +41,7 @@ public class MoneyPaymentInstructionRegisterService extends QueueConsumer implem private final Imdg sessionMap; private final Function, IValidator> fieldValuesValidator; private final Imdg companyMap; + private final Imdg accountMap; private final PreClearMap preClearMap; @Autowired @@ -49,6 +54,7 @@ public class MoneyPaymentInstructionRegisterService extends QueueConsumer implem this.paymentInstructionMap = imdgProvider.getImdg(IMDGDistributedNames.Map_PaymentInstruction, PaymentInstruction.class); this.sessionMap = imdgProvider.getImdg(IMDGDistributedNames.Map_Session, Session.class); this.companyMap = imdgProvider.getImdg(IMDGDistributedNames.Map_Company, Company.class); + this.accountMap = imdgProvider.getImdg(IMDGDistributedNames.Map_Account, Account.class); this.fieldValuesValidator = fieldValuesValidator; preClearMap = PreClearMap.instanceForLocalDateField(moneyPaymentInstructionRegisterMap, "clearingDate"); } @@ -63,21 +69,33 @@ public class MoneyPaymentInstructionRegisterService extends QueueConsumer implem public void moneyPaymentInstructionRegisterNew(BaseRequest userRequest) { log.debug("LauncherCommandRequest received from {}", TOPIC_NAME); - Map> fieldValuesSectionMkr = Map.of("section", "MKR"); - Collection actualSessions = sessionMap.getCollectionObjectsByFieldValues(fieldValuesSectionMkr); - log.debug("Selected {} Session by query {}", actualSessions.size(), fieldValuesSectionMkr); - preClearMap.preClearMap(); - actualSessions.forEach(session -> { - Map> fieldValuesSessionId = Map.of("sessionId", session.getId()); - Collection paymentInstructionBySessionId = - paymentInstructionMap.getCollectionObjectsByFieldValues(fieldValuesSessionId); - log.debug("Selected {} PaymentInstruction by query {}", paymentInstructionBySessionId.size(), fieldValuesSessionId); - for (PaymentInstruction paymentInstruction : paymentInstructionBySessionId) { - if (isDuplicateInMap(paymentInstruction).isEmpty()) { - insertMoneyPaymentInstructionRegister(paymentInstruction); + + Collection paymentInstructions = paymentInstructionMap.getAllValues(); + log.debug("Selected {} PaymentInstruction, do filter by account...", paymentInstructions.size()); + Collection moneyPaymentInstructions = new ArrayList<>(); + for (PaymentInstruction paymentInstruction : paymentInstructions) { + // filter by accountType + if (paymentInstruction.getCreditLeg_accountId() != null) { + Account account = accountMap.getSingleObjectByID(paymentInstruction.getCreditLeg_accountId()); + if (account == null) + log.warn("Account id={} not found for paymentInstruction.id={}", + paymentInstruction.getCreditLeg_accountId(), paymentInstruction.getId()); + else { + if (IEnumKey.contains(account.getAccountType(), AccountType.Clrn, AccountType.Info, AccountType.Anlt, AccountType.Tran)) { + moneyPaymentInstructions.add(paymentInstruction); + } } } - }); + } + paymentInstructions = null; + log.debug("Filtered {} PaymentInstruction, with money account's", moneyPaymentInstructions.size()); + + preClearMap.preClearMap(); + for (PaymentInstruction paymentInstruction : moneyPaymentInstructions) { + if (isDuplicateInMap(paymentInstruction).isEmpty()) { + insertMoneyPaymentInstructionRegister(paymentInstruction); + } + } log.debug("successfully processed"); } diff --git a/clearing-parent/registry-service/src/test/java/ru/spcex/clearing/registry/service/ExecutionRegisterServiceTest.java b/clearing-parent/registry-service/src/test/java/ru/spcex/clearing/registry/service/ExecutionRegisterServiceTest.java index 422ebbbf0..23eddccff 100644 --- a/clearing-parent/registry-service/src/test/java/ru/spcex/clearing/registry/service/ExecutionRegisterServiceTest.java +++ b/clearing-parent/registry-service/src/test/java/ru/spcex/clearing/registry/service/ExecutionRegisterServiceTest.java @@ -24,10 +24,12 @@ import ru.spcex.clearing.test.TestUtils; import ru.spcex.clearing.test.config.ImdgTestConfig; import ru.spcex.clearing.test.config.KafkaTestConfig; import ru.spcex.platform.enumeration.CompanySymbol; +import ru.spcex.platform.enumeration.MoneyFlowSide; import ru.spcex.platform.enumeration.Side; import ru.spcex.platform.enumeration.Task; import ru.spcex.platform.imdg.api.Imdg; import ru.spcex.platform.imdg.api.ImdgProvider; +import ru.spcex.platform.imdg.iml.hazelcast.adapter.ImdgHazelcast; import javax.annotation.PostConstruct; import java.math.BigDecimal; @@ -162,10 +164,11 @@ class ExecutionRegisterServiceTest { executionFond.setTradingClearingRegistryId(TKR_FOR_TKR_ID); executionFond.setCompanyId(COMPANY_ID); executionFond.setCounterPartyId(COUNTER_PARTY_ID); - executionFond.setSide(Side.BUY.getKey()); + executionFond.setSide(Side.SELL.getKey()); executionFond.setCounterPartyTradingClearingRegistry(COUNTER_PARTY_TKR); executionFond.setPartyTradingClearingRegistry(PARTY_TKR); executionFondImdg.insert(executionFond); + ((ImdgHazelcast)executionDepositImdg).clear(); // чтобы не влиял второй тест LauncherCommandRequest launcherCommandRequest = new LauncherCommandRequest(); @@ -185,16 +188,16 @@ class ExecutionRegisterServiceTest { assertEquals(executionRegister.getExchangeExecutionId(), EXCHANGE_EXECUTION_ID); assertEquals(executionRegister.getExchangeExecutionTime(), EXCHANGE_EXECUTION_TIME); assertEquals(executionRegister.getSecurityId(), SECURITY_ID); - assertEquals(executionRegister.getSellerId(), COUNTER_PARTY_ID); - assertEquals(executionRegister.getSellerClearingCode(), COMPANY_SYMBOL_VALUE_FOR_COUNTER_PARTY_ID); - assertEquals(executionRegister.getSellerTradingClearingRegister(), COUNTER_PARTY_TKR); - assertEquals(executionRegister.getSellerMoneyAccount(), MONEY_ACCOUNT_FOR_COUNTER_PARTY_TKR); - assertEquals(executionRegister.getSellerDepoAccount(), DEPO_ACCOUNT_FOR_COUNTER_PARTY_TKR); - assertEquals(executionRegister.getBuyerId(), COMPANY_ID); - assertEquals(executionRegister.getBuyerClearingCode(), COMPANY_SYMBOL_VALUE_FOR_COMPANY_ID); - assertEquals(executionRegister.getBuyerTradingClearingRegister(), PARTY_TKR); - assertEquals(executionRegister.getBuyerMoneyAccount(), MONEY_ACCOUNT_FOR_TKR); - assertEquals(executionRegister.getBuyerDepoAccount(), DEPO_ACCOUNT_FOR_TKR); + assertEquals(executionRegister.getSellerId(), COMPANY_ID); + assertEquals(executionRegister.getSellerClearingCode(), COMPANY_SYMBOL_VALUE_FOR_COMPANY_ID); + assertEquals(executionRegister.getSellerTradingClearingRegister(), PARTY_TKR); + assertEquals(executionRegister.getSellerMoneyAccount(), MONEY_ACCOUNT_FOR_TKR); + assertEquals(executionRegister.getSellerDepoAccount(), DEPO_ACCOUNT_FOR_TKR); + assertEquals(executionRegister.getBuyerId(), COUNTER_PARTY_ID); + assertEquals(executionRegister.getBuyerClearingCode(), COMPANY_SYMBOL_VALUE_FOR_COUNTER_PARTY_ID); + assertEquals(executionRegister.getBuyerTradingClearingRegister(), COUNTER_PARTY_TKR); + assertEquals(executionRegister.getBuyerMoneyAccount(), MONEY_ACCOUNT_FOR_COUNTER_PARTY_TKR); + assertEquals(executionRegister.getBuyerDepoAccount(), DEPO_ACCOUNT_FOR_COUNTER_PARTY_TKR); assertEquals(executionRegister.getAmount(), SETTLEMENT_AMOUNT); assertEquals(executionRegister.getQuantity(), QUANTITY); assertEquals(executionRegister.getClearingDate(), LocalDate.now()); @@ -217,10 +220,11 @@ class ExecutionRegisterServiceTest { executionDeposit.setTradingClearingRegistryId(TKR_FOR_TKR_ID); executionDeposit.setCompanyId(COMPANY_ID); executionDeposit.setCounterPartyId(COUNTER_PARTY_ID); - executionDeposit.setSide(Side.SELL.getKey()); + executionDeposit.setSide(MoneyFlowSide.SELL.getKey()); executionDeposit.setCounterPartyTradingClearingRegistry(COUNTER_PARTY_TKR); executionDeposit.setPartyTradingClearingRegistry(PARTY_TKR); executionDepositImdg.insert(executionDeposit); + ((ImdgHazelcast)executionFondImdg).clear(); // чтобы не влиял первый тест LauncherCommandRequest launcherCommandRequest = new LauncherCommandRequest();