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 44bb1e814..c945204db 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 @@ -117,6 +117,24 @@ public enum GatewayEksClientCodeValidationRule implements IValidationRule validate(ImdgValidationContext context) { + TkrAccount validatedObject = context.getValidatedObject(); + Optional depoAccount = context.getStoredObject(ClientCodeStoreObjects.DEPO_ACCOUNT); + if (depoAccount.isPresent()) { + Imdg tradingClearingRegistryImdg = context.obtainMap(IMDGDistributedNames.Map_TradingClearingRegistry, TradingClearingRegistry.class); + ImdgPredicateBuilder predicateBuilder = tradingClearingRegistryImdg.predicateBuilder(); + Collection tkrIds = tradingClearingRegistryImdg.getCollectionIdsByPredicate( + predicateBuilder.equals("depoAccountId", depoAccount.get().getId()) + ); + if (tkrIds != null && !tkrIds.isEmpty()) { + return of(AccountError.AccountForTradingClearingRegistryAlreadyUsed, depoAccount.get().getId()); + } + } + return Optional.empty(); + } + }, ClsAccountsPresent() { @Override public Optional validate(ImdgValidationContext context) { 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 ea787c7c3..167cfb77e 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 @@ -1,6 +1,7 @@ package ru.spcex.clearing.account.validation; import java.util.ArrayList; +import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Optional; @@ -97,7 +98,7 @@ public enum GatewayUpdateEksClientCodeValidationRule implements IValidationRule< ); if (depoAccount == null) { context.storeObject(ClientCodeStoreObjects.DEPO_ACCOUNT, Optional.empty()); - return of(AccountError.AccountNotFound, "depo_account"); + return of(AccountError.DepoAccountNotFound, "depo_account"); } if (!depoAccount.getAccountId().equals(tkr.getDepoAccountId())) { return of(AccountError.DepoAccountChangeNotAllowed, depoAccount.getAccountId()); @@ -116,7 +117,7 @@ public enum GatewayUpdateEksClientCodeValidationRule implements IValidationRule< && CurrencyCode.RUB.equalsByKey(moneyAccountMsgRequest.getCurrCode())) .toList(); if (!accounts.isEmpty()) { - return of(AccountError.AccountForTradingClearingRegistryAlreadyUsed, accounts.stream().findFirst().get().getAccount()); + return of(AccountError.CurrencyForTradingClearingRegistryListAlreadyUsed, accounts.stream().findFirst().get().getAccount()); } return empty(); } @@ -150,6 +151,8 @@ public enum GatewayUpdateEksClientCodeValidationRule implements IValidationRule< @Override public Optional validate(ImdgValidationContext context) { TkrAccount validatedObject = context.getValidatedObject(); + TradingClearingRegistry tkr = context.getStoredObject(ClientCodeStoreObjects.TRADING_CLEARING_REGISTRY); + Company company = context.getStoredObject(ClientCodeStoreObjects.COMPANY); Imdg accountImdg = context.obtainMap(IMDGDistributedNames.Map_Account, Account.class); Imdg tkrList = context.obtainMap(IMDGDistributedNames.Map_TradingClearingRegistryList, TradingClearingRegistryList.class); ImdgPredicateBuilder predicateBuilder = accountImdg.predicateBuilder(); @@ -168,17 +171,29 @@ public enum GatewayUpdateEksClientCodeValidationRule implements IValidationRule< Account account = accountImdg.getFirstObjectByPredicate( predicateBuilder.and( predicateBuilder.equals("account", request.getAccount()), - predicateBuilder.equals("accountType", AccountType.Clrn.getKey()) + predicateBuilder.equals("accountType", AccountType.Clrn.getKey()), + predicateBuilder.equals("companyId", company.getId()) ) ); if (account == null) { return of(AccountError.AccountNotFound, request.getAccount()); } - TradingClearingRegistryList tkrListByAccount = tkrList.getSingleObjectByPredicate( - predicateBuilder.equals("accountId", account.getId()) + Collection tkrListByCurrency = tkrList.getCollectionIdsByPredicate( + predicateBuilder.and( + predicateBuilder.equals("currency", account.getCurrency()), + predicateBuilder.equals("tradingClearingRegistryId", tkr.getId()) + ) ); - if (tkrListByAccount != null) { + if (tkrListByCurrency != null && !tkrListByCurrency.isEmpty()) { + return of(AccountError.CurrencyForTradingClearingRegistryListAlreadyUsed, account.getId()); + } + Collection tkrListByAccount = tkrList.getCollectionIdsByPredicate( + predicateBuilder.and( + predicateBuilder.equals("accountId", account.getId()) + ) + ); + if (tkrListByAccount != null && !tkrListByAccount.isEmpty()) { return of(AccountError.AccountForTradingClearingRegistryAlreadyUsed, account.getId()); } clrnAccounts.add(account); @@ -188,20 +203,22 @@ public enum GatewayUpdateEksClientCodeValidationRule implements IValidationRule< Account account = accountImdg.getFirstObjectByPredicate( predicateBuilder.and( predicateBuilder.equals("account", request.getAccount()), - predicateBuilder.equals("accountType", AccountType.Clrn.getKey()) + predicateBuilder.equals("accountType", AccountType.Clrn.getKey()), + predicateBuilder.equals("companyId", company.getId()) + ) ); if (account == null) { return of(AccountError.AccountNotFound, request.getAccount()); } - TradingClearingRegistryList tkrListByAccount = tkrList.getSingleObjectByPredicate( + Collection tkrListByAccount = tkrList.getCollectionIdsByPredicate( predicateBuilder.and( predicateBuilder.equals("accountId", account.getId()), - predicateBuilder.equals("currency", account.getCurrency()) + predicateBuilder.equals("tradingClearingRegistryId", tkr.getId()) ) ); - if (tkrListByAccount == null) { - return of(AccountError.AccountForTradingClearingRegistryAlreadyUsed, account.getId()); + if (tkrListByAccount == null || tkrListByAccount.isEmpty()) { + return of(AccountError.AccountNotFound, account.getId()); } } context.storeObject(ClientCodeStoreObjects.CLRN_ACCS, clrnAccounts); @@ -212,6 +229,7 @@ public enum GatewayUpdateEksClientCodeValidationRule implements IValidationRule< @Override public Optional validate(ImdgValidationContext context) { TkrAccount validatedObject = context.getValidatedObject(); + TradingClearingRegistry tkr = context.getStoredObject(ClientCodeStoreObjects.TRADING_CLEARING_REGISTRY); Imdg accountImdg = context.obtainMap(IMDGDistributedNames.Map_Account, Account.class); Imdg tkrList = context.obtainMap(IMDGDistributedNames.Map_TradingClearingRegistryList, TradingClearingRegistryList.class); ImdgPredicateBuilder predicateBuilder = accountImdg.predicateBuilder(); @@ -232,11 +250,14 @@ public enum GatewayUpdateEksClientCodeValidationRule implements IValidationRule< if (account == null) { return of(AccountError.AccountNotFound, request.getAccount()); } - TradingClearingRegistryList tkrListByAccount = tkrList.getSingleObjectByPredicate( - predicateBuilder.equals("currency", account.getCurrency()) + Collection tkrListByAccount = tkrList.getCollectionIdsByPredicate( + predicateBuilder.and( + predicateBuilder.equals("currency", account.getCurrency()), + predicateBuilder.equals("tradingClearingRegistryId", tkr.getId()) + ) ); - if (tkrListByAccount != null) { - return of(AccountError.AccountForTradingClearingRegistryAlreadyUsed, account.getId()); + if (tkrListByAccount != null && !tkrListByAccount.isEmpty()) { + return of(AccountError.CurrencyForTradingClearingRegistryListAlreadyUsed, account.getId()); } anltAccounts.add(account); }