From 2f94fcfe5099e0a546510e2b9a115ab738be81a7 Mon Sep 17 00:00:00 2001 From: etreschenkov Date: Thu, 18 Jun 2026 18:46:05 +0300 Subject: [PATCH] http://jira.mfd.msk:8088/browse/CLS-1039 --- .../ClientCodeValidationConfig.java | 1 + .../clearing/account/errors/AccountError.java | 4 +- .../listeners/ClientCodeMessageListener.java | 16 +++++-- ...ewayUpdateEksClientCodeValidationRule.java | 45 ++++++------------- 4 files changed, 28 insertions(+), 38 deletions(-) diff --git a/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/config/validation/ClientCodeValidationConfig.java b/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/config/validation/ClientCodeValidationConfig.java index 6f4d3f309..8495db2cf 100644 --- a/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/config/validation/ClientCodeValidationConfig.java +++ b/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/config/validation/ClientCodeValidationConfig.java @@ -174,6 +174,7 @@ public class ClientCodeValidationConfig { addImdg.accept(IMDGDistributedNames.Map_CompanySymbols); addImdg.accept(IMDGDistributedNames.Map_Account); addImdg.accept(IMDGDistributedNames.Map_TradingClearingRegistry); + addImdg.accept(IMDGDistributedNames.Map_TradingClearingRegistryList); addImdg.accept(IMDGDistributedNames.Map_AccountSymbols); addImdg.accept(IMDGDistributedNames.Map_DepoAccount); addImdg.accept(IMDGDistributedNames.Map_ClientCode); diff --git a/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/errors/AccountError.java b/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/errors/AccountError.java index c479f99bd..212d44841 100644 --- a/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/errors/AccountError.java +++ b/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/errors/AccountError.java @@ -32,8 +32,8 @@ public enum AccountError implements IErrorEnumId { CurrencyForTradingClearingRegistryListAlreadyUsed(5031L), BadSymbol(5032L), TradingClearingRegistryNotFound(3022L), - ClientCodeNotLinedToTkr(3033L), - AccountRubForbiddenForAdd(3033L), + DepoAccountChangeNotAllowed(5033L), + ClientCodeNotFound(5034L), CurrencyNotFound(1016L), ; diff --git a/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/service/v2/listeners/ClientCodeMessageListener.java b/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/service/v2/listeners/ClientCodeMessageListener.java index 3b5a8c69a..0f0fa7a9d 100644 --- a/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/service/v2/listeners/ClientCodeMessageListener.java +++ b/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/service/v2/listeners/ClientCodeMessageListener.java @@ -8,7 +8,6 @@ import java.util.List; import java.util.Map; import java.util.Optional; import java.util.concurrent.atomic.AtomicBoolean; -import java.util.stream.Stream; import org.apache.kafka.clients.consumer.Consumer; import org.apache.kafka.clients.producer.Producer; import org.slf4j.Logger; @@ -221,12 +220,21 @@ public class ClientCodeMessageListener extends QueueConsumer implements Initiali TkrAccount tkrAccount = entry.getKey(); ValidationResult validationResult = entry.getValue(); IValidator validator = validationResult.validator(); + Company company = validator.getStored(ClientCodeStoreObjects.COMPANY); List clrnAccs = validator.getStored(ClientCodeStoreObjects.CLRN_ACCS); List anltAccs = validator.getStored(ClientCodeStoreObjects.ANLT_ACCS); TradingClearingRegistry tradingClearingRegistry = validator.getStored(ClientCodeStoreObjects.TRADING_CLEARING_REGISTRY); - List accIds = Stream.concat(clrnAccs.stream(), anltAccs.stream()) - .map(Account::getId) - .toList(); + + List accIds = new ArrayList<>(); + for (MoneyAccountMsgRequest account : tkrAccount.getMoneyAccounts()) { + if (StringUtils.hasText(account.getEks_account())) { + log.debug("eks_account is filled, creating info account: {}", account.getEks_account()); + Pair accId = accountFacade.createAccountInfo(account, company); + accIds.add(accId.getFirst()); + } + } + + clrnAccs.forEach(account -> accIds.add(account.getId())); TradingClearingRegistryListNewRequest tcrListNew = new TradingClearingRegistryListNewRequest(); tcrListNew.setTradingClearingRegistryId(tradingClearingRegistry.getId()); diff --git a/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/validation/GatewayUpdateEksClientCodeValidationRule.java b/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/validation/GatewayUpdateEksClientCodeValidationRule.java index 8f6775a17..ea787c7c3 100644 --- a/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/validation/GatewayUpdateEksClientCodeValidationRule.java +++ b/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/validation/GatewayUpdateEksClientCodeValidationRule.java @@ -97,10 +97,10 @@ public enum GatewayUpdateEksClientCodeValidationRule implements IValidationRule< ); if (depoAccount == null) { context.storeObject(ClientCodeStoreObjects.DEPO_ACCOUNT, Optional.empty()); - return of(AccountError.DepoAccountNotFound, "depo_account"); + return of(AccountError.AccountNotFound, "depo_account"); } - if (!tkr.getDepoAccountId().equals(depoAccount.getAccountId())) { - return of(AccountError.AccountForTradingClearingRegistryAlreadyUsed, depoAccount.getAccountId()); + if (!depoAccount.getAccountId().equals(tkr.getDepoAccountId())) { + return of(AccountError.DepoAccountChangeNotAllowed, depoAccount.getAccountId()); } } return empty(); @@ -116,7 +116,7 @@ public enum GatewayUpdateEksClientCodeValidationRule implements IValidationRule< && CurrencyCode.RUB.equalsByKey(moneyAccountMsgRequest.getCurrCode())) .toList(); if (!accounts.isEmpty()) { - return of(AccountError.AccountRubForbiddenForAdd, accounts.stream().findFirst().get().getAccount()); + return of(AccountError.AccountForTradingClearingRegistryAlreadyUsed, accounts.stream().findFirst().get().getAccount()); } return empty(); } @@ -140,7 +140,7 @@ public enum GatewayUpdateEksClientCodeValidationRule implements IValidationRule< ) ); if (existClientCode == null) { - return of(AccountError.ClientCodeNotLinedToTkr, trkCode); + return of(AccountError.ClientCodeNotFound, trkCode); } context.storeObject(ClientCodeStoreObjects.CLIENT_CODE, existClientCode); return empty(); @@ -155,12 +155,12 @@ public enum GatewayUpdateEksClientCodeValidationRule implements IValidationRule< ImdgPredicateBuilder predicateBuilder = accountImdg.predicateBuilder(); List accounts = validatedObject.getMoneyAccounts().stream() .filter(moneyAccountMsgRequest -> - moneyAccountMsgRequest.getStatus().equals("NEW") + StringUtils.hasText(moneyAccountMsgRequest.getAccount()) && moneyAccountMsgRequest.getStatus().equals("NEW") && !CurrencyCode.RUB.equalsByKey(moneyAccountMsgRequest.getCurrCode())) .toList(); List existAccounts = validatedObject.getMoneyAccounts().stream() .filter(moneyAccountMsgRequest -> - moneyAccountMsgRequest.getStatus().equals("NEW") + StringUtils.hasText(moneyAccountMsgRequest.getAccount()) && moneyAccountMsgRequest.getStatus().equals("NOW") && !CurrencyCode.RUB.equalsByKey(moneyAccountMsgRequest.getCurrCode())) .toList(); List clrnAccounts = new ArrayList<>(); @@ -171,6 +171,7 @@ public enum GatewayUpdateEksClientCodeValidationRule implements IValidationRule< predicateBuilder.equals("accountType", AccountType.Clrn.getKey()) ) ); + if (account == null) { return of(AccountError.AccountNotFound, request.getAccount()); } @@ -194,7 +195,10 @@ public enum GatewayUpdateEksClientCodeValidationRule implements IValidationRule< return of(AccountError.AccountNotFound, request.getAccount()); } TradingClearingRegistryList tkrListByAccount = tkrList.getSingleObjectByPredicate( - predicateBuilder.equals("accountId", account.getId()) + predicateBuilder.and( + predicateBuilder.equals("accountId", account.getId()), + predicateBuilder.equals("currency", account.getCurrency()) + ) ); if (tkrListByAccount == null) { return of(AccountError.AccountForTradingClearingRegistryAlreadyUsed, account.getId()); @@ -229,7 +233,7 @@ public enum GatewayUpdateEksClientCodeValidationRule implements IValidationRule< return of(AccountError.AccountNotFound, request.getAccount()); } TradingClearingRegistryList tkrListByAccount = tkrList.getSingleObjectByPredicate( - predicateBuilder.equals("accountId", account.getId()) + predicateBuilder.equals("currency", account.getCurrency()) ); if (tkrListByAccount != null) { return of(AccountError.AccountForTradingClearingRegistryAlreadyUsed, account.getId()); @@ -237,29 +241,6 @@ public enum GatewayUpdateEksClientCodeValidationRule implements IValidationRule< anltAccounts.add(account); } - List existAccounts = validatedObject.getMoneyAccounts().stream() - .filter(moneyAccountMsgRequest -> - StringUtils.hasText(moneyAccountMsgRequest.getEks_account()) && moneyAccountMsgRequest.getStatus().equals("NOW") - && !CurrencyCode.RUB.equalsByKey(moneyAccountMsgRequest.getCurrCode())) - .toList(); - for (MoneyAccountMsgRequest request : existAccounts) { - Account account = accountImdg.getFirstObjectByPredicate( - predicateBuilder.and( - predicateBuilder.equals("accountType", AccountType.Anlt.getKey()), - predicateBuilder.equals("currency", request.getCurrCode()), - predicateBuilder.equals("account", request.getEks_account()) - ) - ); - if (account == null) { - return of(AccountError.AccountNotFound, request.getAccount()); - } - TradingClearingRegistryList tkrListByAccount = tkrList.getSingleObjectByPredicate( - predicateBuilder.equals("accountId", account.getId()) - ); - if (tkrListByAccount == null) { - return of(AccountError.AccountForTradingClearingRegistryAlreadyUsed, account.getId()); - } - } context.storeObject(ClientCodeStoreObjects.ANLT_ACCS, anltAccounts); return empty(); }