From 2bd57dc4b65c504b7e3dc7a81d56bd631ed30b81 Mon Sep 17 00:00:00 2001 From: etreschenkov Date: Mon, 25 May 2026 13:47:48 +0300 Subject: [PATCH] http://jira.mfd.msk:8088/browse/CLS-1032 --- .../ClientCodeValidationConfig.java | 49 +---------------- .../account/service/ClientCodeService.java | 31 ----------- .../service/v2/facade/ClientCodeFacade.java | 52 +++++-------------- .../listeners/ClientCodeMessageListener.java | 6 +-- .../BackendClientCodeValidationRule.java | 37 ++----------- 5 files changed, 23 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 b008c5538..cbd9899d5 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 @@ -48,29 +48,7 @@ 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, - BackendClientCodeValidationRule.TcrIsNotPresentByAccount, + BackendClientCodeValidationRule.TcrIsPresentByAccount, DictionaryPresentRule.instance("status", ClientCodeNewRequest::getStatus, IMDGDistributedNames.Map_ServiceStatusDictionary, @@ -101,7 +79,6 @@ public class ClientCodeValidationConfig { AccountError.RequiredFieldEmpty, AccountError.RecordNotFound ), - FieldRequiredRule.instance("companyId", ClientCodeUpdateRequest::getCompanyId, AccountError.RequiredFieldEmpty), IdPresentRule.instance("companyId", ClientCodeUpdateRequest::getCompanyId, @@ -109,29 +86,7 @@ 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, - DictionaryPresentRule.instance("stauts", + DictionaryPresentRule.instance("status", ClientCodeUpdateRequest::getStatus, IMDGDistributedNames.Map_ServiceStatusDictionary, ServiceStatusDictionary.class, 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 fba15d9cb..7cd5e2c1e 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 @@ -344,23 +344,7 @@ public class ClientCodeService extends QueueConsumer implements InitializingBean return makeErrorResponse(userRequest, AccountError.RecordNotFound, req.getId()); } - boolean doCreateTCR = checkNeedCreateTCR(req.getCompanyId(), req.getMoneyAccountId(), req.getDepoAccountId()); - if (doCreateTCR) { - try { - requestInfoUpdate = createAndWaitTCR(userRequest.getId(), clientCode.getId(), - req.getCompanyId(), req.getMoneyAccountId(), req.getDepoAccountId()); - if (requestInfoUpdate != null) return requestInfoUpdate; - } catch (Exception e) { - log.error("Can not wait creation of TCR. request id={};CompanyId={}, MoneyAccountId={}, DepoAccountId={}; {}", - userRequest.getId(), req.getCompanyId(), req.getMoneyAccountId(), req.getDepoAccountId(), - e.toString()); - return makeErrorResponse(userRequest, AccountError.GeneralError, "Can not create TCR: " + e.getMessage()); - } - } - updateClientCode(clientCode, req); - //fixme спросить, у нас при апдейте передаётся clientCode.id которого надо изменять. А тут список currencyAccountList приходит - в нём что будет - только 1 счёт для него и его же менять? - clientCodeMap.update(clientCode); log.debug("successfully processed update, id {}", clientCode.getId()); return null; @@ -525,25 +509,10 @@ public class ClientCodeService extends QueueConsumer implements InitializingBean private void updateClientCode(ClientCode clientCode, ClientCodeUpdateRequest req) { assert clientCode.getId() != null && clientCode.getId().equals(req.getId()); - clientCode.setCompanyId(req.getCompanyId()); clientCode.setCode(req.getCode()); - - if (req.getMoneyAccountId() != null) { - TradingClearingRegistry tradingClearingRegistry = selectTradingClearingRegistry(req.getCompanyId(), req.getMoneyAccountId(), req.getDepoAccountId()); - if (tradingClearingRegistry == null) { - log.warn("TCR not found: CompanyId {}, MoneyAccountId {}, DepoAccountId {}", - req.getCompanyId(), req.getMoneyAccountId(), req.getDepoAccountId()); - } else { - clientCode.setTradingClearingRegistryId(tradingClearingRegistry.getId()); - } - } - clientCode.setTradingClearingRegistryId(req.getTradingClearingRegistryId()); - clientCode.setMoneyAccountId(req.getMoneyAccountId()); - clientCode.setDepoAccountId(req.getDepoAccountId()); clientCode.setStatus(req.getStatus()); - clientCode.setUpdated(Instant.now()); } 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 7d4d9478b..b15572b17 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 @@ -40,7 +40,7 @@ public class ClientCodeFacade implements IClearingFacade { /** * Создает clientCode, TCR и опционально TCRList, если указаны валюты. */ - public void createClientCode(ClientCodeNewRequest request, IValidator validator, boolean isClearingAcc) { + public void createClientCodeWithTkr(ClientCodeNewRequest request, IValidator validator, boolean isClearingAcc) { log.trace("Start process creating new client code"); TradingClearingRegistry tradingClearingRegistry; { @@ -78,8 +78,6 @@ public class ClientCodeFacade implements IClearingFacade { clientCode.setCompanyId(request.getCompanyId()); clientCode.setCode(request.getCode()); clientCode.setTradingClearingRegistryId(tradingClearingRegistry.getId()); -// clientCode.setMoneyAccountId(request.getMoneyAccountId()); -// clientCode.setDepoAccountId(request.getDepoAccountId()); clientCode.setStatus(request.getStatus()); clientCodeImdg.insert(clientCode); log.debug("successfully processed, new clientCode id {}", clientCode.getId()); @@ -87,41 +85,19 @@ public class ClientCodeFacade implements IClearingFacade { } } -// public void createClientCode(ClientCodeBusiness businessRequest) { -// log.trace("Start process creating new client code"); -// TradingClearingRegistry tradingClearingRegistry; -// { -// log.debug("Trading Clearing Registry is not exist, creating..."); -// TradingClearingRegistryBusiness creationTcrRequest = new TradingClearingRegistryBusiness(); -// creationTcrRequest.setCompanyId(request.getCompanyId()); -// creationTcrRequest.setMoneyAccountId(request.getMoneyAccountId()); -// creationTcrRequest.setDepoAccountId(request.getDepoAccountId()); -// creationTcrRequest.setTradingClearingRegistryType(TradingClearingRegistryType.Client_B.getKey()); -// tradingClearingRegistry = tradingClearingRegistryFacade.createTradingClearingRegistry(creationTcrRequest, null); -// } -// { -// if (request.getCurrencyAccountList() != null && !request.getCurrencyAccountList().isEmpty()) { -// TradingClearingRegistryListNewRequest tcrListNew = new TradingClearingRegistryListNewRequest(); -// tcrListNew.setTradingClearingRegistryId(tradingClearingRegistry.getId()); -// tcrListNew.setCurrencyAccountList(request.getCurrencyAccountList()); -// List tkrListIds = tradingClearingRegistryListFacade.createTradingClearingRegistryList(tcrListNew, null); -// } -// } -// -// { -// ClientCode clientCode = new ClientCode(); -// clientCode.setCreated(Instant.now()); -// clientCode.setUpdated(clientCode.getCreated()); -// -// clientCode.setCompanyId(request.getCompanyId()); -// clientCode.setCode(request.getCode()); -// clientCode.setMoneyAccountId(request.getMoneyAccountId()); -// clientCode.setDepoAccountId(request.getDepoAccountId()); -// clientCode.setStatus(request.getStatus()); -// clientCodeImdg.insert(clientCode); -// log.debug("successfully processed, new clientCode id {}", clientCode.getId()); -// } -// } + public void createClientCode(ClientCodeNewRequest request) { + log.trace("Start process creating new client code"); + ClientCode clientCode = new ClientCode(); + clientCode.setCreated(Instant.now()); + clientCode.setUpdated(clientCode.getCreated()); + clientCode.setCompanyId(request.getCompanyId()); + clientCode.setCode(request.getCode()); + clientCode.setTradingClearingRegistryId(request.getTradingClearingRegistryId()); + clientCode.setStatus(request.getStatus()); + clientCodeImdg.insert(clientCode); + log.debug("successfully processed, new clientCode id {}", clientCode.getId()); + } + public void lock() { // tradingClearingRegistryFacade.lock() // tradingClearingRegistryListFacade.lock() 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 8ebe5bdf6..eabf0f4af 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 @@ -163,7 +163,7 @@ public class ClientCodeMessageListener extends QueueConsumer implements Initiali .map(currencyCodeAccountEntry -> currencyCodeAccountEntry.getValue().getId()) .toList(); clientCodeNewRequest.setCurrencyAccountList(foreignCurrencyList); - clientCodeFacade.createClientCode(clientCodeNewRequest, validator, true); + clientCodeFacade.createClientCodeWithTkr(clientCodeNewRequest, validator, true); TradingClearingRegistry tradingClearingRegistry = selectTradingClearingRegistry(company.getId(), moneyAccount.getId(), depoAccountId); @@ -209,7 +209,7 @@ public class ClientCodeMessageListener extends QueueConsumer implements Initiali clientCodeNewRequest.setMoneyAccountId(rubMoneyAcc.get()); clientCodeNewRequest.setDepoAccountId(depoAccountId); clientCodeNewRequest.setCurrencyAccountList(accIds); - clientCodeFacade.createClientCode(clientCodeNewRequest, validator, false); + clientCodeFacade.createClientCodeWithTkr(clientCodeNewRequest, validator, false); } } @@ -222,7 +222,7 @@ public class ClientCodeMessageListener extends QueueConsumer implements Initiali return makeErrorResponse(clientCodeNewRequest, validationResult); } - clientCodeFacade.createClientCode(request, validationResult.validator(), true); + clientCodeFacade.createClientCode(request); return null; } diff --git a/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/validation/BackendClientCodeValidationRule.java b/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/validation/BackendClientCodeValidationRule.java index 7f4b35960..de2469e4d 100644 --- a/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/validation/BackendClientCodeValidationRule.java +++ b/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/validation/BackendClientCodeValidationRule.java @@ -1,15 +1,12 @@ package ru.spcex.clearing.account.validation; import java.util.List; -import java.util.Map; import java.util.Optional; import ru.clearing.classes.statics.data.account.Account; import ru.clearing.classes.statics.data.registry.TradingClearingRegistry; -import ru.clearing.classes.statics.data.registry.TradingClearingRegistryList; import ru.spcex.clearing.account.errors.AccountError; import ru.spcex.clearing.imdg.IMDGDistributedNames; import ru.spcex.clearing.platform.messaging.domain.cud.account.ClientCodeNewRequest; -import ru.spcex.platform.enumeration.Status; import ru.spcex.platform.imdg.api.Imdg; import ru.spcex.platform.imdg.validation.ImdgValidationContext; import ru.spcex.platform.utils.enumeration.EnumMessage; @@ -37,43 +34,17 @@ public enum BackendClientCodeValidationRule implements IValidationRule validate(ImdgValidationContext context) { ClientCodeNewRequest validatedObject = context.getValidatedObject(); - List currencyIds = validatedObject.getCurrencyAccountList(); - Long moneyAccountId = validatedObject.getMoneyAccountId(); - if (moneyAccountId == null) { - return empty(); - } Imdg tradingClearingRegistryImdg = context.obtainMap(IMDGDistributedNames.Map_TradingClearingRegistry, TradingClearingRegistry.class); - Imdg tradingClearingRegistryListImdg = - context.obtainMap(IMDGDistributedNames.Map_TradingClearingRegistryList, TradingClearingRegistryList.class); - TradingClearingRegistry tcrByMoneyAccount = tradingClearingRegistryImdg.getFirstObjectByFieldValues( - Map.of( - "moneyAccountId", moneyAccountId, - "status", Status.Active.getKey() - )); - if (tcrByMoneyAccount != null) { - return of(AccountError.TradingClearingRegistryAlreadyExist); + TradingClearingRegistry tcrByMoneyAccount = tradingClearingRegistryImdg.getSingleObjectByID(validatedObject.getTradingClearingRegistryId()); + if (tcrByMoneyAccount == null) { + return of(AccountError.TradingClearingRegistryNotFound); } - - if (currencyIds == null || currencyIds.isEmpty()) { - return empty(); - } - for (Long id : currencyIds) { - TradingClearingRegistryList tcrList = tradingClearingRegistryListImdg.getFirstObjectByFieldValues( - Map.of( - "accountId", id, - "status", Status.Active.getKey() - )); - if (tcrList != null) { - return of(AccountError.AccountForTradingClearingRegistryAlreadyUsed); - } - } - return empty(); } }