From 0aa623836f6ee5793bf31191df975a3ea2ab39df Mon Sep 17 00:00:00 2001 From: etreschenkov Date: Wed, 17 Jun 2026 11:01:37 +0300 Subject: [PATCH] http://jira.mfd.msk:8088/browse/CLS-1051 --- .../GatewayEksClientCodeValidationRule.java | 80 +++++++++---------- 1 file changed, 37 insertions(+), 43 deletions(-) diff --git a/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/validation/GatewayEksClientCodeValidationRule.java b/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/validation/GatewayEksClientCodeValidationRule.java index 9d489b857..44bb1e814 100644 --- a/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/validation/GatewayEksClientCodeValidationRule.java +++ b/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/validation/GatewayEksClientCodeValidationRule.java @@ -100,9 +100,13 @@ public enum GatewayEksClientCodeValidationRule implements IValidationRule imdg = context.obtainMap(IMDGDistributedNames.Map_DepoAccount, DepoAccount.class); DepoAccount depoAccount = imdg.getFirstObjectByPredicate( - predicateBuilder.equals("accountId", accountSymbols.getAccountId()) + predicateBuilder.and( + predicateBuilder.equals("accountId", accountSymbols.getAccountId()), + predicateBuilder.equals("companyId", company.getId()) + ) ); if (depoAccount == null) { context.storeObject(ClientCodeStoreObjects.DEPO_ACCOUNT, Optional.empty()); @@ -122,12 +126,14 @@ public enum GatewayEksClientCodeValidationRule implements IValidationRule accountImdg = context.obtainMap(IMDGDistributedNames.Map_Account, Account.class); List validClrnAccs = new ArrayList<>(); + Company company = context.getStoredObject(ClientCodeStoreObjects.COMPANY); for (MoneyAccountMsgRequest moneyAccount : moneyAccounts) { ImdgPredicateBuilder predicateBuilder = accountImdg.predicateBuilder(); Account clrnAcc = accountImdg.getFirstObjectByPredicate( predicateBuilder.and( predicateBuilder.equals("account", moneyAccount.getAccount()), - predicateBuilder.equals("accountType", AccountType.Clrn.getKey()) + predicateBuilder.equals("accountType", AccountType.Clrn.getKey()), + predicateBuilder.equals("companyId", company.getId()) )); if (clrnAcc == null) { return of(AccountError.AccountNotFound, moneyAccount.getAccount()); @@ -164,56 +170,44 @@ public enum GatewayEksClientCodeValidationRule implements IValidationRule validate (ImdgValidationContext < TkrAccount > context) { + public Optional validate(ImdgValidationContext context) { Optional depoAccountOpt = context.getStoredObject(ClientCodeStoreObjects.DEPO_ACCOUNT); List clrnAccs = context.getStoredObject(ClientCodeStoreObjects.CLRN_ACCS); - Optional ruClrnAcc = clrnAccs.stream() - .filter(ruAcc -> CurrencyCode.RUB.equalsByKey(ruAcc.getCurrency())) - .findFirst(); - - if (ruClrnAcc.isEmpty() && depoAccountOpt.isEmpty()) { - return empty(); - } Imdg imdg = context.obtainMap(IMDGDistributedNames.Map_TradingClearingRegistry, TradingClearingRegistry.class); Imdg accountImdg = context.obtainMap(IMDGDistributedNames.Map_Account, Account.class); ImdgPredicateBuilder pb = imdg.predicateBuilder(); - ImdgPredicate query = null; - if (ruClrnAcc.isPresent()) { - query = pb.equals("moneyAccountId", ruClrnAcc.get().getId()); - } - if (depoAccountOpt.isPresent()) { - ImdgPredicate depoCondition = pb.equals("depoAccountId", depoAccountOpt.get().getAccountId()); - query = query == null ? depoCondition : pb.or(query, depoCondition); - } - Collection tcr = imdg.getCollectionObjectsByPredicate(query); - - if (tcr.isEmpty()) { - return empty(); - } else { - Account dubAcc = null; - for (TradingClearingRegistry duplicate : tcr) { - if (ruClrnAcc.isPresent() && - Objects.equals(duplicate.getMoneyAccountId(), ruClrnAcc.get().getId())) { - dubAcc = ruClrnAcc.get(); - } - if (depoAccountOpt.isPresent() && - depoAccountOpt.get().getAccountId().equals(duplicate.getDepoAccountId())) { - dubAcc = accountImdg.getSingleObjectByID(depoAccountOpt.get().getAccountId()); - } - if (dubAcc != null) { - break; - } + for (Account clrnAcc : clrnAccs) { + ImdgPredicate query = pb.equals("moneyAccountId", clrnAcc.getId()); + if (depoAccountOpt.isPresent()) { + ImdgPredicate depoCondition = pb.equals("depoAccountId", depoAccountOpt.get().getAccountId()); + query = pb.or(query, depoCondition); } - return of(AccountError.AccountForTradingClearingRegistryAlreadyUsed, - dubAcc != null ? dubAcc.getAccount() : "null"); - } - } - } + Collection tcr = imdg.getCollectionObjectsByPredicate(query); - ; + if (!tcr.isEmpty()) { + Account dubAcc = null; + for (TradingClearingRegistry duplicate : tcr) { + if (Objects.equals(duplicate.getMoneyAccountId(), clrnAcc.getId())) { + dubAcc = clrnAcc; + } + if (depoAccountOpt.isPresent() && + depoAccountOpt.get().getAccountId().equals(duplicate.getDepoAccountId())) { + dubAcc = accountImdg.getSingleObjectByID(depoAccountOpt.get().getAccountId()); + } + if (dubAcc != null) { + break; + } + } + return of(AccountError.AccountForTradingClearingRegistryAlreadyUsed, + dubAcc != null ? dubAcc.getAccount() : "null"); + } + } + return empty(); + } + }; private static final Logger log = LoggerFactory.getLogger(GatewayEksClientCodeValidationRule.class); - } +}