From f6ba9ee06db7b80e8c2efb09b57b09982c1cdcfd Mon Sep 17 00:00:00 2001 From: etreschenkov Date: Fri, 22 May 2026 17:02:28 +0300 Subject: [PATCH] http://jira.mfd.msk:8088/browse/CLS-1023 --- .../ClientCodeValidationConfig.java | 92 +++++++-------- .../account/service/ClientCodeService.java | 2 +- .../TradingClearingRegistryService.java | 38 ++++--- .../service/v2/facade/AccountFacade.java | 106 +++++++++--------- .../service/v2/facade/ClientCodeFacade.java | 4 +- .../facade/TradingClearingRegistryFacade.java | 21 ++-- .../listeners/ClientCodeMessageListener.java | 57 +++++----- .../GatewayEksClientCodeValidationRule.java | 2 +- 8 files changed, 170 insertions(+), 152 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 3ff22bb3e..b4897e7ea 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 @@ -1,12 +1,10 @@ package ru.spcex.clearing.account.config.validation; import java.util.Map; -import java.util.Objects; import java.util.function.Consumer; import java.util.function.Function; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import ru.clearing.classes.statics.data.account.Account; import ru.clearing.classes.statics.data.account.ClientCode; import ru.clearing.classes.statics.data.company.Company; import ru.clearing.platform.dictionary.ServiceStatusDictionary; @@ -50,28 +48,28 @@ public class ClientCodeValidationConfig { Company.class, AccountError.RequiredFieldEmpty, AccountError.CompanyNotFound), - - IdPresentRule.instance("moneyAccountId", - ClientCodeNewRequest::getMoneyAccountId, - IMDGDistributedNames.Map_Account, - Account.class, - AccountError.RequiredFieldEmpty, - AccountError.AccountNotFound, - false, - acc -> Objects.equals(context.getValidatedObject().getCompanyId(), acc.getCompanyId()) - ? null : AccountError.AccountNotFound - ), - IdPresentRule.instance("depoAccountId", - ClientCodeNewRequest::getDepoAccountId, - IMDGDistributedNames.Map_Account, - Account.class, - AccountError.RequiredFieldEmpty, - AccountError.AccountNotFound, - false, - acc -> Objects.equals(context.getValidatedObject().getCompanyId(), acc.getCompanyId()) - ? null : AccountError.AccountNotFound - ), - BackendClientCodeValidationRule.AllAccountsPresent, +// +// IdPresentRule.instance("moneyAccountId", +// ClientCodeNewRequest::getMoneyAccountId, +// IMDGDistributedNames.Map_Account, +// Account.class, +// AccountError.RequiredFieldEmpty, +// AccountError.AccountNotFound, +// false, +// acc -> Objects.equals(context.getValidatedObject().getCompanyId(), acc.getCompanyId()) +// ? null : AccountError.AccountNotFound +// ), +// IdPresentRule.instance("depoAccountId", +// ClientCodeNewRequest::getDepoAccountId, +// IMDGDistributedNames.Map_Account, +// Account.class, +// AccountError.RequiredFieldEmpty, +// AccountError.AccountNotFound, +// false, +// acc -> Objects.equals(context.getValidatedObject().getCompanyId(), acc.getCompanyId()) +// ? null : AccountError.AccountNotFound +// ), +// BackendClientCodeValidationRule.AllAccountsPresent, BackendClientCodeValidationRule.TcrIsNotPresentByAccount, DictionaryPresentRule.instance("status", ClientCodeNewRequest::getStatus, @@ -111,28 +109,28 @@ public class ClientCodeValidationConfig { Company.class, AccountError.RequiredFieldEmpty, AccountError.CompanyNotFound), - - IdPresentRule.instance("moneyAccountId", - ClientCodeUpdateRequest::getMoneyAccountId, - IMDGDistributedNames.Map_Account, - Account.class, - AccountError.RequiredFieldEmpty, - AccountError.AccountNotFound, - false, - acc -> Objects.equals(context.getValidatedObject().getCompanyId(), acc.getCompanyId()) - ? null : AccountError.AccountNotFound - ), - IdPresentRule.instance("depoAccountId", - ClientCodeUpdateRequest::getDepoAccountId, - IMDGDistributedNames.Map_Account, - Account.class, - AccountError.RequiredFieldEmpty, - AccountError.AccountNotFound, - false, - acc -> Objects.equals(context.getValidatedObject().getCompanyId(), acc.getCompanyId()) - ? null : AccountError.AccountNotFound - ), - BackendClientCodeValidationRule.AllAccountsPresent, +// +// IdPresentRule.instance("moneyAccountId", +// ClientCodeUpdateRequest::getMoneyAccountId, +// IMDGDistributedNames.Map_Account, +// Account.class, +// AccountError.RequiredFieldEmpty, +// AccountError.AccountNotFound, +// false, +// acc -> Objects.equals(context.getValidatedObject().getCompanyId(), acc.getCompanyId()) +// ? null : AccountError.AccountNotFound +// ), +// IdPresentRule.instance("depoAccountId", +// ClientCodeUpdateRequest::getDepoAccountId, +// IMDGDistributedNames.Map_Account, +// Account.class, +// AccountError.RequiredFieldEmpty, +// AccountError.AccountNotFound, +// false, +// acc -> Objects.equals(context.getValidatedObject().getCompanyId(), acc.getCompanyId()) +// ? null : AccountError.AccountNotFound +// ), +// BackendClientCodeValidationRule.AllAccountsPresent, DictionaryPresentRule.instance("stauts", ClientCodeUpdateRequest::getStatus, IMDGDistributedNames.Map_ServiceStatusDictionary, @@ -172,6 +170,8 @@ public class ClientCodeValidationConfig { addImdg.accept(IMDGDistributedNames.Map_CompanySymbols); addImdg.accept(IMDGDistributedNames.Map_Account); addImdg.accept(IMDGDistributedNames.Map_TradingClearingRegistry); + addImdg.accept(IMDGDistributedNames.Map_AccountSymbols); + addImdg.accept(IMDGDistributedNames.Map_DepoAccount); return new ValidatorImpl<>(context, FieldRequiredRule.instance("client_code", TkrAccount::getClientCode, AccountError.RequiredFieldEmpty), GatewayClientCodeValidationRule.CompanyPresent, diff --git a/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/service/ClientCodeService.java b/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/service/ClientCodeService.java index e49dc9e21..fba15d9cb 100644 --- a/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/service/ClientCodeService.java +++ b/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/service/ClientCodeService.java @@ -436,7 +436,7 @@ public class ClientCodeService extends QueueConsumer implements InitializingBean request.setRequestPayload(requestPayload); // Следующий вызываемый метод обязательно должен быть synchronized. - RequestInfoUpdate reply = tradingClearingRegistryService.tradingClearingRegistryNew(request); + RequestInfoUpdate reply = tradingClearingRegistryService.tradingClearingRegistryNew(request, true); if (reply != null && Status.Error.equals(reply.getStatus())) { log.warn("tradingClearingRegistryService return error: " + reply.getMessage()); } diff --git a/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/service/TradingClearingRegistryService.java b/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/service/TradingClearingRegistryService.java index 8c09a744e..cee4bee13 100644 --- a/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/service/TradingClearingRegistryService.java +++ b/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/service/TradingClearingRegistryService.java @@ -143,7 +143,7 @@ public class TradingClearingRegistryService extends QueueConsumer implements Ini .setFunction(this::tradingClearingRegistryAutoNew) .forDestination(Consts.DESTINATION_TRADING_CLEARING_REGISTRY_AUTO_NEW, callbacks::put); callback(TradingClearingRegistryNewRequest.class) - .setFunction(this::tradingClearingRegistryNew) + .setFunction(tkrReq -> tradingClearingRegistryNew(tkrReq, true)) .forDestination(Consts.DESTINATION_TRADING_CLEARING_REGISTRY_NEW, callbacks::put); callback(TradingClearingRegistryUpdateRequest.class) .setFunction(this::tradingClearingRegistryUpdate) @@ -318,7 +318,8 @@ public class TradingClearingRegistryService extends QueueConsumer implements Ini return null; } - public synchronized RequestInfoUpdate tradingClearingRegistryNew(BaseRequest userRequest) { + public synchronized RequestInfoUpdate tradingClearingRegistryNew(BaseRequest userRequest, + boolean sentToGateway) { log.debug("TradingClearingRegistryNewRequest received"); RequestInfoUpdate requestInfoUpdate = userRoleVerification.validateRoleAndGetResult(userRequest); if (requestInfoUpdate != null) { @@ -341,6 +342,25 @@ public class TradingClearingRegistryService extends QueueConsumer implements Ini } } + TradingClearingRegistry tradingClearingRegistry = createTkr(req); + if (sentToGateway) { + Optional tkr = createRequestToGateway(tradingClearingRegistry); + if (tkr.isPresent()) { + SendTkrRequest sendTkrRequest = new SendTkrRequest(); + sendTkrRequest.getTkrs().add(tkr.get()); + kafkaSender.sendRequestToQueue(Consts.ACCOUNTS_TO_GATEWAY, sendTkrRequest); + } + + sendNotificationToReportSvc(tradingClearingRegistry); + sendNotificationToClearingSvc(tradingClearingRegistry); + } + log.debug("successfully processed, id {}", tradingClearingRegistry.getId()); + return null; + } + + public TradingClearingRegistry createTkr(TradingClearingRegistryNewRequest req) { + // Дополнительная проверка + Long id = tradingClearingRegistryImdg.nextIDSequenceFor(); TradingClearingRegistry tradingClearingRegistry = new TradingClearingRegistry(); tradingClearingRegistry.setId(id); @@ -386,20 +406,8 @@ public class TradingClearingRegistryService extends QueueConsumer implements Ini tradingClearingRegistryImdg.insert(tradingClearingRegistry); log.info("New TCR.id={} was created.", tradingClearingRegistry.getId()); - Optional tkr = createRequestToGateway(tradingClearingRegistry); - if (tkr.isPresent()) { - SendTkrRequest sendTkrRequest = new SendTkrRequest(); - sendTkrRequest.getTkrs().add(tkr.get()); - kafkaSender.sendRequestToQueue(Consts.ACCOUNTS_TO_GATEWAY, sendTkrRequest); - } - - sendNotificationToReportSvc(tradingClearingRegistry); - sendNotificationToClearingSvc(tradingClearingRegistry); - - log.debug("successfully processed, id {}", id); - return null; + return tradingClearingRegistry; } - protected Long companySequenceNextId(Long companyId, TradingClearingRegistryPurpose registryPurpose, String tradingRegistryType) { ImdgPredicateBuilder pb = tradingClearingRegistryImdg.predicateBuilder(); Collection existTCR = tradingClearingRegistryImdg.getCollectionObjectsByPredicate( diff --git a/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/service/v2/facade/AccountFacade.java b/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/service/v2/facade/AccountFacade.java index 7db125408..0ecc9badf 100644 --- a/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/service/v2/facade/AccountFacade.java +++ b/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/service/v2/facade/AccountFacade.java @@ -3,6 +3,7 @@ package ru.spcex.clearing.account.service.v2.facade; import java.time.Instant; import java.util.Collection; import java.util.Map; +import java.util.Optional; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; @@ -13,7 +14,6 @@ import ru.clearing.classes.statics.data.misc.Currency; import ru.spcex.clearing.account.service.AccountHelper; import ru.spcex.clearing.account.service.InformationAccountService; import ru.spcex.clearing.imdg.IMDGDistributedNames; -import ru.spcex.clearing.platform.messaging.domain.cud.account.TkrAccount; import ru.spcex.clearing.platform.messaging.domain.cud.gateway.MoneyAccountMsgRequest; import ru.spcex.platform.classes.base.interfaces.IClearingFacade; import ru.spcex.platform.enumeration.AccountType; @@ -55,62 +55,60 @@ public class AccountFacade implements IClearingFacade { this.tradingClearingRegistryListFacade = tradingClearingRegistryListFacade; } - public void createInfoAccount(TkrAccount account, Company company) { - for (MoneyAccountMsgRequest moneyAccountMsgRequest : account.getMoneyAccounts()) { - String currencyCode = moneyAccountMsgRequest.getCurrCode() == null ? CurrencyCode.RUB.getKey() : moneyAccountMsgRequest.getCurrCode(); - ImdgPredicateBuilder predicateBuilder = currencyImdg.predicateBuilder(); - Currency currency = currencyImdg.getFirstObjectByPredicate( - predicateBuilder.equals("currencyCode", currencyCode) - ); + public Optional createInfoAccount(MoneyAccountMsgRequest moneyAccountMsgRequest, Company company) { + String currencyCode = moneyAccountMsgRequest.getCurrCode() == null ? CurrencyCode.RUB.getKey() : moneyAccountMsgRequest.getCurrCode(); + ImdgPredicateBuilder predicateBuilder = currencyImdg.predicateBuilder(); + Currency currency = currencyImdg.getFirstObjectByPredicate( + predicateBuilder.equals("currencyCode", currencyCode) + ); - Long currencyCodeId = CurrencyCode.RUB.getKey().equals(currencyCode) ? 810 : currency.getId(); - Instant now = Instant.now(); - Account infoAccount = new Account(); - infoAccount.setCompanyId(company.getId()); - infoAccount.setAccount(moneyAccountMsgRequest.getEks_account()); - - ImdgPredicateBuilder pb = accountImdg.predicateBuilder(); - ImdgPredicate andPredicate = pb.and( - pb.equals("accountType", AccountType.Anlt.getKey()), - pb.equals("currency", currency.getCurrencyCode()) - ); - Collection accountsAnlt = accountImdg.getCollectionObjectsByPredicate(andPredicate); - if (accountsAnlt.isEmpty()) { - log.warn("Account with {} not exist.", andPredicate); - } else if (accountsAnlt.size() > 1) { - log.warn("Account for companyId 1 and accountType=ANLT contains multiply elements, use first"); - } - Account anltAccount = accountsAnlt.iterator().next(); - String specialAnltAccId = anltAccount.getAccount().substring(anltAccount.getAccount().length() - 4); - Long infoSequenceId = informationAccountService.accountNextId(currencyCode, currencyCodeId); - String accountValue = informationAccountService.generateInfoAccount(currencyCodeId, infoSequenceId, specialAnltAccId); - log.trace("New info-account SequenceId={} account={}", infoSequenceId, accountValue); - infoAccount.setAccount(accountValue); - infoAccount.setAccountType(AccountType.Info.getKey()); - infoAccount.setCurrency(currencyCode); - infoAccount.setStatus(WorkflowStatus.Active.getKey()); - infoAccount.setCreated(now); - infoAccount.setUpdated(now); - accountHelper.fillAccountFromRelation(infoAccount, null, false); - - InformationAccount infoAcc = new InformationAccount(); - infoAcc.setAccountId(infoAccount.getId()); - Account firstAccountAntl = accountImdg.getFirstObjectByFieldValues(Map.of( - "companyId", Sender.One.getId(), - "accountType", AccountType.Anlt.getKey(), - "currency", infoAccount.getCurrency() - )); - if (firstAccountAntl == null) { - log.warn("Can not find 1 ANTL {} account for fill information ClearingAccountId.", infoAccount.getCurrency()); - } else { - infoAcc.setClearingAccountId(firstAccountAntl.getId()); - } - infoAcc.setCompanyId(infoAccount.getCompanyId()); - accountImdg.insert(infoAccount); - Long infoId = informationAccountImdg.insert(infoAcc); - log.debug("For account id={} make InformationAccount id={}", infoAccount.getId(), infoId); + Long currencyCodeId = CurrencyCode.RUB.getKey().equals(currencyCode) ? 810 : currency.getId(); + Instant now = Instant.now(); + Account infoAccount = new Account(); + infoAccount.setCompanyId(company.getId()); + infoAccount.setAccount(moneyAccountMsgRequest.getEks_account()); + ImdgPredicateBuilder pb = accountImdg.predicateBuilder(); + ImdgPredicate andPredicate = pb.and( + pb.equals("accountType", AccountType.Anlt.getKey()), + pb.equals("currency", currency.getCurrencyCode()) + ); + Collection accountsAnlt = accountImdg.getCollectionObjectsByPredicate(andPredicate); + if (accountsAnlt.isEmpty()) { + log.warn("Account with {} not exist.", andPredicate); + } else if (accountsAnlt.size() > 1) { + log.warn("Account for companyId 1 and accountType=ANLT contains multiply elements, use first"); } + Account anltAccount = accountsAnlt.iterator().next(); + String specialAnltAccId = anltAccount.getAccount().substring(anltAccount.getAccount().length() - 4); + Long infoSequenceId = informationAccountService.accountNextId(currencyCode, currencyCodeId); + String accountValue = informationAccountService.generateInfoAccount(currencyCodeId, infoSequenceId, specialAnltAccId); + log.trace("New info-account SequenceId={} account={}", infoSequenceId, accountValue); + infoAccount.setAccount(accountValue); + infoAccount.setAccountType(AccountType.Info.getKey()); + infoAccount.setCurrency(currencyCode); + infoAccount.setStatus(WorkflowStatus.Active.getKey()); + infoAccount.setCreated(now); + infoAccount.setUpdated(now); + accountHelper.fillAccountFromRelation(infoAccount, null, false); + accountImdg.insert(infoAccount); + + InformationAccount infoAcc = new InformationAccount(); + infoAcc.setAccountId(infoAccount.getId()); + Account firstAccountAntl = accountImdg.getFirstObjectByFieldValues(Map.of( + "companyId", Sender.One.getId(), + "accountType", AccountType.Anlt.getKey(), + "currency", infoAccount.getCurrency() + )); + if (firstAccountAntl == null) { + log.warn("Can not find 1 ANTL {} account for fill information ClearingAccountId.", infoAccount.getCurrency()); + } else { + infoAcc.setClearingAccountId(firstAccountAntl.getId()); + } + infoAcc.setCompanyId(infoAccount.getCompanyId()); + Long infoId = informationAccountImdg.insert(infoAcc); + log.debug("For account id={} make InformationAccount id={}", infoAccount.getId(), infoId); + return Optional.of(infoAcc); } public void lock() { diff --git a/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/service/v2/facade/ClientCodeFacade.java b/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/service/v2/facade/ClientCodeFacade.java index 7dd2b2fb0..2cbc02773 100644 --- a/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/service/v2/facade/ClientCodeFacade.java +++ b/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/service/v2/facade/ClientCodeFacade.java @@ -39,7 +39,7 @@ public class ClientCodeFacade implements IClearingFacade { /** * Создает clientCode, TCR и опционально TCRList, если указаны валюты. */ - public void createClientCode(ClientCodeNewRequest request, IValidator validator) { + public void createClientCode(ClientCodeNewRequest request, IValidator validator, boolean isClearingAcc) { log.trace("Start process creating new client code"); TradingClearingRegistry tradingClearingRegistry; { @@ -49,7 +49,7 @@ public class ClientCodeFacade implements IClearingFacade { creationTcrRequest.setMoneyAccountId(request.getMoneyAccountId()); creationTcrRequest.setDepoAccountId(request.getDepoAccountId()); creationTcrRequest.setTradingClearingRegistryType(TradingClearingRegistryType.Client_B.getKey()); - tradingClearingRegistry = tradingClearingRegistryFacade.createTradingClearingRegistry(creationTcrRequest, null); + tradingClearingRegistry = tradingClearingRegistryFacade.createTradingClearingRegistry(creationTcrRequest, null, isClearingAcc); } { if (request.getCurrencyAccountList() != null && !request.getCurrencyAccountList().isEmpty()) { diff --git a/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/service/v2/facade/TradingClearingRegistryFacade.java b/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/service/v2/facade/TradingClearingRegistryFacade.java index 2a7b8c0f6..81e7a449e 100644 --- a/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/service/v2/facade/TradingClearingRegistryFacade.java +++ b/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/service/v2/facade/TradingClearingRegistryFacade.java @@ -8,6 +8,7 @@ import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import ru.clearing.classes.statics.data.account.ClearingAccount; import ru.clearing.classes.statics.data.account.DepoAccount; +import ru.clearing.classes.statics.data.account.InformationAccount; import ru.clearing.classes.statics.data.company.Company; import ru.clearing.classes.statics.data.registry.TradingClearingRegistry; import ru.spcex.clearing.account.model.TradingClearingRegistryBusiness; @@ -34,6 +35,7 @@ public class TradingClearingRegistryFacade { private final Imdg tradingClearingRegistryImdg; private final Imdg depoAccountImdg; private final Imdg clearingAccountImdg; + private final Imdg informationAccountImdg; private final Imdg companyImdg; public TradingClearingRegistryFacade(ImdgProvider imdgProvider, @@ -43,12 +45,14 @@ public class TradingClearingRegistryFacade { TradingClearingRegistry.class); this.depoAccountImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_DepoAccount, DepoAccount.class); this.clearingAccountImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_ClearingAccount, ClearingAccount.class); + this.informationAccountImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_InformationAccount, InformationAccount.class); this.companyImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Company, Company.class); this.kafkaSender = kafkaSender; } public TradingClearingRegistry createTradingClearingRegistry(TradingClearingRegistryNewRequest request, - IValidator validator) { + IValidator validator, + boolean isClearingAcc) { Long id = tradingClearingRegistryImdg.nextIDSequenceFor(); TradingClearingRegistry tradingClearingRegistry = new TradingClearingRegistry(); tradingClearingRegistry.setId(id); @@ -58,8 +62,15 @@ public class TradingClearingRegistryFacade { DepoAccount depoAccount = request.getDepoAccountId() != null ? depoAccountImdg.getFirstObjectByFieldValues(Map.of("accountId", request.getDepoAccountId())) : null; - ClearingAccount clearingAccount = request.getMoneyAccountId() != null ? - clearingAccountImdg.getFirstObjectByFieldValues(Map.of("accountId", request.getMoneyAccountId())) : null; + + String tradingRegistryType = TradingClearingRegistryType.Owner_A.getKey(); + if (isClearingAcc) { + ClearingAccount clearingAccount = request.getMoneyAccountId() != null ? + clearingAccountImdg.getFirstObjectByFieldValues(Map.of("accountId", request.getMoneyAccountId())) : null; + if (clearingAccount != null) { + tradingRegistryType = clearingAccount.getClearingAccountType(); + } + } if (request.getStatus() == null) { tradingClearingRegistry.setStatus(ServiceStatus.Active.getKey()); @@ -69,14 +80,10 @@ public class TradingClearingRegistryFacade { log.trace("TCR status in request set: {}", tradingClearingRegistry.getStatus()); } - String tradingRegistryType; if (request.getTradingClearingRegistryType() != null) { tradingRegistryType = request.getTradingClearingRegistryType(); } else if (depoAccount != null) { tradingRegistryType = depoAccount.getDepoAccountType(); - } else { - if (clearingAccount != null) tradingRegistryType = clearingAccount.getClearingAccountType(); - else tradingRegistryType = TradingClearingRegistryType.Owner_A.getKey(); } tradingClearingRegistry.setTradingClearingRegistryType(tradingRegistryType); 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 044847770..72d1f6c6a 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 @@ -1,5 +1,6 @@ package ru.spcex.clearing.account.service.v2.listeners; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -12,9 +13,12 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.InitializingBean; import org.springframework.stereotype.Service; import ru.clearing.classes.statics.data.account.Account; +import ru.clearing.classes.statics.data.account.DepoAccount; +import ru.clearing.classes.statics.data.account.InformationAccount; import ru.clearing.classes.statics.data.company.Company; import ru.clearing.classes.statics.data.registry.TradingClearingRegistry; import ru.spcex.clearing.account.model.ValidationResult; +import ru.spcex.clearing.account.service.TradingClearingRegistryService; import ru.spcex.clearing.account.service.v2.GatewayRequestCreator; import ru.spcex.clearing.account.service.v2.facade.AccountFacade; import ru.spcex.clearing.account.service.v2.facade.ClientCodeFacade; @@ -26,6 +30,7 @@ import ru.spcex.clearing.platform.messaging.domain.Consts; import ru.spcex.clearing.platform.messaging.domain.cud.account.ClientCodeNewRequest; import ru.spcex.clearing.platform.messaging.domain.cud.account.TkrAccount; import ru.spcex.clearing.platform.messaging.domain.cud.account.TkrAccountsGatewayRequest; +import ru.spcex.clearing.platform.messaging.domain.cud.gateway.MoneyAccountMsgRequest; import ru.spcex.clearing.platform.messaging.domain.cud.gateway.SendTkrRequest; import ru.spcex.clearing.platform.messaging.domain.cud.gateway.Tkr; import ru.spcex.clearing.platform.messaging.service.QueueConsumer; @@ -49,6 +54,7 @@ public class ClientCodeMessageListener extends QueueConsumer implements Initiali private final GatewayRequestCreator gatewayRequestCreator; private final UserRoleVerification userRoleVerification; private final AccountFacade accountFacade; + private final TradingClearingRegistryService tradingClearingRegistryService; public ClientCodeMessageListener(Consumer kafkaQueue, Producer kafkaProducer, @@ -58,7 +64,8 @@ public class ClientCodeMessageListener extends QueueConsumer implements Initiali ClientCodeValidator clientCodeValidator, GatewayRequestCreator gatewayRequestCreator, UserRoleVerification userRoleVerification, - AccountFacade accountFacade) { + AccountFacade accountFacade, + TradingClearingRegistryService tradingClearingRegistryService) { super(kafkaQueue, kafkaProducer); this.kafkaSender = kafkaSender; this.imdgProvider = imdgProvider; @@ -67,6 +74,7 @@ public class ClientCodeMessageListener extends QueueConsumer implements Initiali this.gatewayRequestCreator = gatewayRequestCreator; this.userRoleVerification = userRoleVerification; this.accountFacade = accountFacade; + this.tradingClearingRegistryService = tradingClearingRegistryService; } @Override @@ -186,7 +194,7 @@ public class ClientCodeMessageListener extends QueueConsumer implements Initiali .map(currencyCodeAccountEntry -> currencyCodeAccountEntry.getValue().getId()) .toList(); clientCodeNewRequest.setCurrencyAccountList(foreignCurrencyList); - clientCodeFacade.createClientCode(clientCodeNewRequest, validator); + clientCodeFacade.createClientCode(clientCodeNewRequest, validator, true); TradingClearingRegistry tradingClearingRegistry = selectTradingClearingRegistry(company.getId(), moneyAccount.getId(), depoAccountId); @@ -204,33 +212,30 @@ public class ClientCodeMessageListener extends QueueConsumer implements Initiali ValidationResult validationResult = entry.getValue(); IValidator validator = validationResult.validator(); Company company = validator.getStored(ClientCodeStoreObjects.COMPANY); - accountFacade.createInfoAccount(tkrAccount, company); + Optional depoAccount = validator.getStored(ClientCodeStoreObjects.DEPO_ACCOUNT); + Long depoAccountId = depoAccount.map(DepoAccount::getId).orElse(null); + List accountIds = new ArrayList<>(); + List infoAccsId = new ArrayList<>(); + for (MoneyAccountMsgRequest account : tkrAccount.getMoneyAccounts()) { + Optional infoAccId = accountFacade.createInfoAccount(account, company); + if (infoAccId.isPresent()) { + accountIds.add(infoAccId.get().getAccountId()); + infoAccsId.add(infoAccId.get().getId()); + } else { + log.error("Can't create info account for account: {}", tkrAccount.getClientCode()); + } + } + ClientCodeNewRequest clientCodeNewRequest = new ClientCodeNewRequest(); log.debug("Creating new clientCode by tkr account: {}", tkrAccount.getClientCode()); - Optional depoAccount = validator.getStored(ClientCodeStoreObjects.DEPO_ACCOUNT); - Long depoAccountId = depoAccount.map(Account::getId).orElse(null); -// Map accountByCurrency = validator.getStored(ClientCodeStoreObjects.MAPPED_TO_CURRENCY_ACCOUNTS); -// -// clientCodeNewRequest.setCompanyId(company.getId()); -// clientCodeNewRequest.setCode(tkrAccount.getClientCode()); -// clientCodeNewRequest.setDepoAccountId(depoAccountId); -// Account moneyAccount = accountByCurrency.get(CurrencyCode.RUB.getKey()); -// clientCodeNewRequest.setMoneyAccountId(moneyAccount.getId()); -// -// List foreignCurrencyList = accountByCurrency.entrySet() -// .stream() -// .filter(currencyCodeAccountEntry -> !CurrencyCode.RUB.equalsByKey(currencyCodeAccountEntry.getKey())) -// .map(currencyCodeAccountEntry -> currencyCodeAccountEntry.getValue().getId()) -// .toList(); -// clientCodeNewRequest.setCurrencyAccountList(foreignCurrencyList); -// clientCodeFacade.createClientCode(clientCodeNewRequest, validator); -// -// TradingClearingRegistry tradingClearingRegistry = selectTradingClearingRegistry(company.getId(), -// moneyAccount.getId(), depoAccountId); -// sendTkrRequest.getTkrs().add(gatewayRequestCreator.createTkrGatewayReq(tradingClearingRegistry)); -// log.debug("Success created new clientCode by tkr account: {}", tkrAccount.getClientCode()); + clientCodeNewRequest.setCompanyId(company.getId()); + clientCodeNewRequest.setCode(tkrAccount.getClientCode()); + clientCodeNewRequest.setMoneyAccountId(accountIds.get(0)); + clientCodeNewRequest.setDepoAccountId(depoAccountId); + clientCodeNewRequest.setCurrencyAccountList(accountIds); + clientCodeFacade.createClientCode(clientCodeNewRequest, validator, false); } } @@ -243,7 +248,7 @@ public class ClientCodeMessageListener extends QueueConsumer implements Initiali return makeErrorResponse(clientCodeNewRequest, validationResult); } - clientCodeFacade.createClientCode(request, validationResult.validator()); + clientCodeFacade.createClientCode(request, validationResult.validator(), true); return null; } 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 ee88998fb..e639a2ea9 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 @@ -96,7 +96,7 @@ public enum GatewayEksClientCodeValidationRule implements IValidationRule